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.01656441
median(x)
[1] 0.01632657
sd(x)
[1] 0.9942932

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.01656441
mean(xplus100)
[1] 100.0166

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.01632657
median(xplus100)
[1] 100.0163

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.9942932
sd(xplus100)
[1] 0.9942932

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.318598
IQR(xplus100)
[1] 1.318598

Yes, the IQR remains the same.

Measures of variation - The range.

Does the range also show no change?

Solution

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

Yes.

An Exercise for you

I’ll leave it as an exercise for you to 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.

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.03879 -0.65215  0.01633  0.01656  0.66644  3.96297 

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.005   6.333   7.568   7.530   8.724   9.979 
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.888   6.935   9.206   9.985  12.412  25.944 

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