Posted on Apr 3, 2010

Economic Impact of Wal-Mart

I remember discussing monopolies and antitrusts in my high school economics class. In fact, my major high school paper was describing the (evil) monopoly Microsoft, back when the Internet Explorer fight was occurring. I learned a lot about these big businesses at the time, and I was able to see the Wal-Mart corporation as a potentially good thing, but as well as a potentially bad thing.

Some have hypothesized that Wal-Mart starves the Mom-n-Pop shops, preventing any chance for the little guys to compete against a department/electronics/car repair/gas station/whatever else Wal-Mart can do nowadays.  However, near them are many other stores that profit on the customers going to and leaving Wal-Mart.  As a statistician, this problem excites me because I would like data to settle this matter.

I am new to spatial statistics, so I am not looking for the most complex model that will really answer this question.  The model I am considering is simplistic by design and has much room for improvement.  This is actually the project on which I am working for my spatial statistics class.

One local economic indicator is the state (or county) unemployment rate, and because this information is readily available, I am using it as the response in my model.  For now, I am not considering a spatio-temporal model, where I might consider the unemployment rate over time: like I said, simplistic!  For predictor variables, I am going to first look at the number of local Wal-Marts in each state and in each county.  Eventually, I will look at more information about these such as the number of “supercenters” apart from the number of “neighborhood markets.”  Also, looking at the opening date for each Wal-Mart would be of interest in the spatio-temporal model, but this is ignored for now, again for simplicity.

Over the next few days, I will be posting the code for scraping the Wal-Mart covariate data as well as the R code for the spatial analysis.

Posted on Mar 14, 2009

A Little Bit About Data Frames in R

Data frames in R are much like DataSets in SAS, SPSS, .NET, etc. Really, they are just spreadsheets that feel like a matrices. We can use these to look at numerical data along with any meta data or characteristics associated with the numbers though numbers are not required. From the R Documentation, “a data frame is a list of variables of the same length with unique row names”, and also it is “a matrix-like structure whose columns may be of differing types (numeric, logical, factor and character and so on)”.

Let’s take a look at an example. First, we start with generating a 3 x 3 identity matrix and assigning the matrix to the variable, mat.

[code]
mat = diag( 3 )
[/code]

By typing mat, we can see the output.

     [,1] [,2] [,3]
[1,]    1    0    0
[2,]    0    1    0
[3,]    0    0    1

Next, we are going to convert this matrix to a data frame called mat_dataframe and output it.

[code] mat_dataframe = data.frame( mat )[/code]

  X1 X2 X3
1  1  0  0
2  0  1  0
3  0  0  1

Notice that the column names are X1, X2, and X3 and that the row names are 1, 2, and 3. Say we want to add more columns and rows to our data frame. Let’s first start by appending a row to the “mat_dataframe.”  We do this with rbind.

[code]
mat_dataframe = rbind(mat_dataframe, c(2,2,2))
[/code]

We have added a vector of twos to the next row of the data frame.  Here’s what mat_dataframe looks like so far.

  X1 X2 X3
1  1  0  0
2  0  1  0
3  0  0  1
4  2  2  2

Now, we should try appending 2 columns to the mat_dataframe using 2 different methods. The first line will create a new data frame from the original data frame and append a column called “City” with “Dallas” as the entry for each row. The second takes this data frame and adds another column called Color with entries blue and green.

[code]
mat_dataframe = data.frame( mat_dataframe, City="Dallas" )
mat_dataframe = cbind( mat_dataframe, Color=c( "blue", "green" ) )
[/code]

Now, the mat_dataframe looks like this.

  X1 X2 X3   City Color
1  1  0  0 Dallas  blue
2  0  1  0 Dallas green
3  0  0  1 Dallas  blue
4  2  2  2 Dallas green

Notice that once blue and green were both used, they were both repeated. Before we move on, let me mention a gotcha when adding columns. On the City column, I simply inserted Dallas for each row, but under the Color column, I added 2 different colors. What happens if we specify three values? Let’s try this with a new column called Country.

[code]
mat_dataframe = data.frame( mat_dataframe, Country=c( "USA", "Canada", "Mexico" ) )
[/code]

We get the following error…

Error in data.frame(mat_dataframe, Country = c(“USA”, “Canada”, “Mexico”)) : arguments imply differing number of rows: 4, 3

A rule of thumb: make sure the number of values being assigned divides into the number of rows (or columns) of the data frame. If our data frame had 6 rows (or 9 or 12 or … ), we could have used the above code.

Our data frame is essentially a matrix with a couple of attached column vectors containing strings. This may not seem very useful at first, but it is a wonderful data structure, making some statistical methods among other things easier to use. Soon, I will post a basic ANOVA example using data frames.

Posted on Feb 11, 2009

Zero Factorial

I must have had this epiphany several times in the last few years, but I had it again this evening while being introduced to the dark side.  Many students are taught that

[latex]n! = n \times (n-1) \times \ldots 2 \times 1[/latex]

and that 0! is defined as 1.  But is there some higher level mathematics in which this factorial idea is just a corollary as with most pre-graduate school mathematics.  Well, there is!  This is the epic Gamma function.  It is defined as

[latex]\Gamma( \alpha ) = \int_0^{\infty} y^{\alpha – 1} e^{-y} dy[/latex].

If [latex]\alpha[/latex] is a positive integer, then [latex]\Gamma( \alpha ) = (\alpha – 1)![/latex].

Here is the main event.  Suppose [latex]\alpha = 1[/latex]; because [latex]\alpha[/latex] is a positive integer, [latex]\Gamma( \alpha ) = 0![/latex]  But then, notice that

[latex]\Gamma( 1 ) = \int_0^{\infty} y^{ 1 – 1 } e^{-y} dy = \int_0^{\infty} e^{-y} dy = 1[/latex].

Hence, our conclusion is that 0! = 1.