One Quantitative Variable

Harold Nelson

Descriptive Statistics for One Quantitative Variable

There are three basic questions you need to answer to explore a single quantitative variable.

  1. Location - basically, where is the data located?
  2. Variation (scatter, spread, etc.) - how spread out is the data?
  3. Shape - Beyond location and variation, what should be said about the data?

Let’s create some artificial data to explore these ideas

x = rnorm(1000)

That created a vector x with 1,000 numbers drawn from a normal distribution with mean = 0 and standard deviation = 1. Note that nothing seems to have happened. It is worth remembering that in R creating something doesn’t automatically display it. But we can do many things to explore x.

Look at some measures of location and variation to see if they are close to what we would expect from the way we created x.

Solution

mean(x)
[1] -0.04040632
median(x)
[1] -0.03841803
sd(x)
[1] 0.9745511

Following Changes

Why do we call something a measure of location or variation of a collection of numbers? In a practical sense, we want the measure to reflect changes that we make to the set of numbers. If we move the set of numbers to the right, we want the measure to move to the right. If we spread the numbers out more, we want the measure of variation to increase

Now let’s change x and see what happens. First add 100 to each number in the vector

Solution

xplus100 = x + 100

Exercise

What would you want to see in the mean of this new variable? After you think about it, use the R command mean() applied to both variables. Then advance to the next slide and see.

Solution

mean(x)
[1] -0.04040632
mean(xplus100)
[1] 99.95959

The Median

Now look at the median of both variables. Does it do what a good measure of location should do?

Solution

median(x)
[1] -0.03841803
median(xplus100)
[1] 99.96158

Measures of variation - The Standard Deviation.

Look at the standard deviations of both variables. What do you see? Is this what you should see?

Solution

sd(x)
[1] 0.9745511
sd(xplus100)
[1] 0.9745511

There is no change. This does make sense because the entire set of numbers has been uniformly displaced. There is no change in variation, just a change in location.

Measures of variation - The IQR.

Does the IQR do the same thing?

Solution

IQR(x)
[1] 1.323187
IQR(xplus100)
[1] 1.323187

Yes, the IQR remains the same.

Measures of variation - The range.

Does the range also show no change?

Solution

max(x) - min(x)
[1] 6.852404
max(xplus100) - min(xplus100)
[1] 6.852404

Yes.

A Super Command

The summary() function is probably the single best function to start with when you want to examine a quantitative variable.

I’ll use it to compare x and xplus100.

summary(x)
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-3.06234 -0.70009 -0.03842 -0.04041  0.62310  3.79006 
summary(xplus100)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  96.94   99.30   99.96   99.96  100.62  103.79 

An Exercise for you

Describe the relationships between the measures of location and variation for x and those for xtimes100. The values of xtimes100 should be the values of x multiplied by 100.

Solution

xtimes100 = x * 100
summary(x)
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-3.06234 -0.70009 -0.03842 -0.04041  0.62310  3.79006 
summary(xtimes100)
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-306.234  -70.009   -3.842   -4.041   62.310  379.006 

Measures of Variation

sd(x)
[1] 0.9745511
sd(xtimes100)
[1] 97.45511
IQR(x)
[1] 1.323187
IQR(xtimes100)
[1] 132.3187
max(x) - min(x)
[1] 6.852404
max(xtimes100) - min(xtimes100)
[1] 685.2404
sd(x)
[1] 0.9745511
sd(xtimes100)
[1] 97.45511

Shape - Graphical Displays

The standard graphical displays for quantitative variables are the histogram and the boxplot. To be comparable with the histogram, you may want to ask that the boxplot be laid out horizontally instead of vertically, which is the default. There is a command summary(), which produces the key numerical results displayed in the boxplot.

hist(x)

boxplot(x,horizontal=TRUE)

summary(x)
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
-3.06234 -0.70009 -0.03842 -0.04041  0.62310  3.79006 

These graphical displays of x show a very conventional symmetric distribution with a single central peak.

Exercise - Another Example

It is useful to look at some other examples to see a few possibilities. Let’s generate some uniformly distributed numbers between 5 and 10 and create the graphical displays.

flatones = runif(1000,min=5,max=10)
summary(flatones)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  5.003   6.347   7.547   7.561   8.808   9.995 
boxplot(flatones,horizontal=TRUE)

hist(flatones)

Do you see what you expected to see. Is this distribution symmetric? is there a noticeable peak? Are there outliers?

Another Example

Let’s try some values drawn from a Chi-squared distribution with 10 degrees of freedom. Don’t worry about what this means. Just concentrate on the shape questions.

cq = rchisq(1000,df=10)
hist(cq)

boxplot(cq,horizontal=TRUE)

summary(cq)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  1.284   6.594   9.566  10.181  12.818  29.037 

Is this distribution symmetric? Is there a noticeable peak? Are there outliers?