Section 2.2

January 28, 2021

Section 2.2: Inference for a single quantitative variable

Quantitative Variables

  • In Chapter 1, we did inference on a single categorical variable.
    • e.g., Tap or bottled? Red or blue?
    • Our parameter was \(\pi\), and our statistic was \(\hat{p}\).
  • In this section, we will do inference on a single quantitative variable.
    • e.g., word length, height, hours of sleep
    • Our parameter will be \(\mu\), and our statistic will be \(\bar{x}\).

Experiment

Listen to the following music clip.

Estimate the duration

Now write down how many seconds long you think that clip was.

Answer the poll

Based on what you wrote down, answer the poll in the #ma-005 chat.

-poll "How long did the music play?" "Less than 10 seconds" "More than 10 seconds" "I wrote down 10 seconds exactly."

Estimating elapsed time

  • Subjects were told that they’d listen to music and asked questions when it was over.
  • Researchers Played 10 seconds of the Jackson 5’s “ABC” and asked how long they thought it lasted.
  • Can the subjects accurately estimate the length?

Hypotheses

  • Null Hypothesis: People will accurately estimate the length of a 10 second-song snippet, on average.
    • \(H_0: \mu = 10\)
  • Alternative Hypothesis: People will not accurately estimate the length of a 10 second-song snippet, on average.
    • \(H_a: \mu \neq 10\)

Data

timedata <- 
  read.table("http://www.isi-stats.com/isi/data/chap3/TimeEstimate.txt", 
  header = TRUE)
timedata
   Time
1     6
2     7
3     7
4     9
5     9
6     9
7    10
8    10
9    10
10   10
11   12
12   12
13   12
14   14
15   15
16   15
17   15
18   15
19   20
20   20
21   20
22   20
23   20
24   22
25   26

Dotplot of time estimate data

stripchart(timedata, method = "stack", at=0, pch=16, offset = 0.4)

Mean, Median, and Quartiles

summary(timedata)
      Time     
 Min.   : 6.0  
 1st Qu.:10.0  
 Median :12.0  
 Mean   :13.8  
 3rd Qu.:20.0  
 Max.   :26.0  

Median

The median is the middle data value when the data are sorted in order from smallest to largest.

  • The location of the median can be found by determining \((n + 1)/2\), where \(n\) represents the sample size.
  • When there are an odd number of data values, the median is the \([(n + 1)/2]\)th observation.
  • When there are an even number of data values, the median is reported as the average of the middle two numbers.

Median exercise

Here are the sleep times of a small class of six statistics students: 6, 7.5, 5.5, 8, 6.5, 7.5. What is the median for this small class? (Compute this by hand.)

-poll "What is the median of the numbers 6, 7.5, 5.5, 8, 6.5, 7.5?" 5 5.5 6 6.5 6.75 7 7.5 8 "none of these"

Skew, mean, median

  • The distribution obtained is not symmetric, but is right skewed.
  • When data are skewed right, the mean gets pulled out to the right while the median is more resistant to this. (mean > median)

Null Distribution?

  • \(H_0: \mu = 10\) seconds
  • \(H_a: \mu \neq 10\) seconds
  • Our problem now is, how do we develop a null distribution? (The second S in our 3S strategy.)
  • Flipping coins and spinning spinners will not work to model what would happen under a true null hypothesis, because we need to simulate average times. (quantitative variable)

Null distribution of simulated statistics

  • We need to simulate what happened in the study, under the null assumption that \(\mu = 10\).
  • There were 48 students.
  • Our observed statistic was the average estimated time.
  • So we need to draw 48 simulated times and average them. That will give us a dot.

Population?

  • We need to create a population based on what we know about our sample and what we want the mean to be.
  • We need to come up with a large data set that we think our population of time estimates might look like under a true null.
  • We might assume the population is skewed (like our sample) and has a standard deviation similar to what we found in our sample, but has a mean of 10 seconds.

Simulated population

We simulate a large (>6000) population of made-up time estimates that conform to our null hypothesis. Population properties:

    Estimate 
 Min.   : 1  
 1st Qu.: 5  
 Median : 9  
 Mean   :10  
 3rd Qu.:15  
 Max.   :25  
Number of simulated time estimates = 6215

Histogram of simulated population

Null distribution (simulated sample means)

  • Develop a null distribution by taking 1000 samples of size 48.
  • Take the mean of each sample. That’s a dot.

p-value

Find out where our observed mean of 13.71 sec is located.

Learning objectives

  • Use the descriptive statistics applet to describe a data set.
  • Use the one-mean applet to do a simulation-based test on a hypothesis about a single quantitative variable.

Exploration 2.2: How much sleep do we get?

How much sleep do Westmont students get?

Preview

Question: How many hours do Westmont students sleep on a typical night? Let’s make the question more specific and ask about last night. Is the average less than the recommended eight hours? How can we estimate this average?

  • Variable? Type?
    • How many hours of sleep – quantitative
  • Observational Units?
    • People in our class (convenience sample)
  • Population of interest?
    • All Westmont students

\[ H_0: \mu = 8 \\ H_a: \mu < 8 \]

Bias?

  • There are reasons why your class is likely a good representation of all Westmont students in terms of hours slept last night.
  • There are also reasons why your class is likely not a good representation of all Westmont students in terms of hours slept last night.

Since we didn’t collect the data using random sampling, it is uncertain whether our results will generalize to the population of all Westmont students.

Two applets we will use

Join your table group

Use the Descriptive Statistics applet to examine a dotplot of the sample data. To do this, press Clear to delete the existing data in the applet and then copy and paste your class data (including the one-word variable name at the top) into the Sample data box and press Use Data.

Skew

A distribution is called skewed if it is not symmetric, and, instead, the bulk of observation values tend to fall on one side of the distribution, with a longer “tail” on the other. Right-skewed distributions have their tail on the right, and left-skewed distributions have their tail on the left.

Distribution of data

  1. Describe the shape of the distribution of sleep times in the sample as symmetric, right skewed, left skewed, or something else.

  2. One way to summarize the center of a distribution is with the mean. Check the box next to Actual in the Mean row and record the value of the average sleep time for your class. Record the mean, using the appropriate symbol. Also, record the sample size.

Find the median

  1. Use the applet to find the median sleep time for your class by checking the Actual box in the Median row. Record the median of the class data.

  2. Do the mean and median for your class differ by much? What does this suggest about the skewness of the data?

Variability

  1. What is the standard deviation of sleep times for students in your class? Use the applet to find this by checking the Actual box next to Std dev. Record this value.

  2. Are there any sleep hours in your class that you would characterize as unusual? In particular, are there sleep times that are far away from the bulk of the data (outliers)?

Simulation: Hypothetical well-rested population

Assume that the population of sleep hours follows a normal distribution with mean \(\mu = 8\) hours (as indicated under the null hypothesis) and standard deviation \(\sigma = 1.5\). Open the One Mean applet. Notice that the population distribution on the left looks to be normally distributed with mean very close to 8 hours and SD about 1.5 hours. Check the Show Sampling Options box. Keep Number of Samples set to one for now. Set the Sample Size to match the class data. Press Draw Samples and notice that a dotplot of the simulated sample appeared in the middle, and one dot appeared on the rightmost dotplot, corresponding to the mean of this simulated sample.

Make a null distribution

  1. Change the Number of Samples to 1,000 and press Draw Samples a few times to make a null distribution of simulated sample means. Record the mean and standard deviation of the null distribution.

  2. Record a p-value using the Count Samples settings. For this study, the observed statistic is the sample mean \(\bar{x}\) that you recorded in #2.

  3. Record the value of a standardized statistic by using the same formula we used in Section 1.3.

\[ \mbox{standardized statistic} = \frac{\mbox{statistic} - \mbox{null value}}{\mbox{SD of null distribution}} \]

Summarize your conclusion

  1. Use this form to write one well-crafted sentence summarizing your conclusion in the context of this problem. Use the appropriate measures of significance in your sentence.

Remember that the context of this problem concerns how much sleep Westmont students get.

Extension: Inference on the median

  1. In the applet, above the null distribution, there is a radio button for median. What does this change about the null distribution? (What do the dots mean now?) Use the median that you recorded in #6 to obtain a p-value for the following hypotheses, where \(M\) now stands for the population median. \[ H_0: M = 8 \\ H_a: M < 8 \] Record this p-value. How does the strength of evidence compare to the test of means that you did in #9?

Part II: Theory-based test for a single mean

Theory-Based Test

  • We just saw how to do inference on a single quantitative variable using a simulation.
  • The simulation was tricky, because we had to generate a “fake” population to draw from to make the null distribution.
  • Next we’ll explore the theory-based test for a single mean.

Recall: Estimating elapsed time

  • Subjects were told that they’d listen to music and asked questions when it was over.
  • Researchers Played 10 seconds of the Jackson 5’s “ABC” and asked how long they thought it lasted.
  • Can the subjects accurately estimate the length?

Hypotheses

  • Null Hypothesis: People will accurately estimate the length of a 10 second-song snippet, on average.
    • \(H_0: \mu = 10\)
  • Alternative Hypothesis: People will not accurately estimate the length of a 10 second-song snippet, on average.
    • \(H_a: \mu \neq 10\)

Data

timedata <- 
  read.table("http://www.isi-stats.com/isi/data/chap3/TimeEstimate.txt", 
  header = TRUE)
timedata
   Time
1     6
2     7
3     7
4     9
5     9
6     9
7    10
8    10
9    10
10   10
11   12
12   12
13   12
14   14
15   15
16   15
17   15
18   15
19   20
20   20
21   20
22   20
23   20
24   22
25   26

Dotplot of time estimate data

stripchart(timedata, method = "stack", at=0, pch=16, offset = 0.4)

Mean and Standard Deviation

mean(timedata$Time)
[1] 13.8
sd(timedata$Time)
[1] 5.416026

Note: you will use these commands in Investigation #2.

Theory-based test

  • The null distribution that we developed can be predicted with theory-based methods.
  • We know it will be centered on the mean given in the null hypothesis.
  • We can also predict its shape and its standard deviation.

The t-distribution

  • The shape is very much like a normal distribution, but slightly different and is called a t-distribution.
  • The t-distribution has slightly “heavier” tails than a normal distribution.
  • The t-statistic is the standardized statistic we use with a single quantitative variable and can be found using the formula: \[ t = \frac{\bar{x} - \mu}{s/\sqrt{n}} \]

Here, \(s\) is the sample standard deviation.

\[ t \approx \frac{13.8 - 10}{5.416/\sqrt{25}} \approx 3.5 \]

Validity conditions

The theory-based test for a single mean requires either:

  • The quantitative variable should have a symmetric distribution, or,
  • The sample size is at least 20 and the sample distribution is not strongly skewed.

Simulated sample means

Last time, we did a simulation to get a null distribution for this data.

Simulated t-statistics

Using the formula, we get simulated t-statistics:

Convert t-stat to p-value

To get a p-value from a t-statistic, you need some sort of calculator or software (or, gasp, a table in a book).

tstat <- (mean(timedata$Time) - 10)/(sd(timedata$Time)/sqrt(25))
pt(tstat, 24, lower.tail = FALSE)*2
[1] 0.001805775

Easy way: Theory-based inference applet

Even easier way: Use R

t.test(timedata$Time, mu = 10)

    One Sample t-test

data:  timedata$Time
t = 3.5081, df = 24, p-value = 0.001806
alternative hypothesis: true mean is not equal to 10
95 percent confidence interval:
 11.56437 16.03563
sample estimates:
mean of x 
     13.8 

Exploration 2.2, Continued

Preview

Research question: Do Westmont students get less than the recommended 8 hours of sleep per night?

  • Hypotheses

\[ H_0: \mu = 8 \\ H_a: \mu < 8 \]

Join your table group

Data

  1. Enter our class data into the Descriptive Statistics applet (including the one-word variable name at the top) in the Sample data box and press Use Data.

Sample Statistics

  1. Using appropriate notation, record the sample mean, the sample standard deviation, and the sample size, which the applet will calculate for you if you click Actual. You will need the quantities, correctly labeled, to use in the formulas that follow.

Theory-based t-test

Validity Conditions: The quantitative variable should have a symmetric distribution or you should have at least 20 observations and the sample distribution should not be strongly skewed.

  1. Would you consider the validity conditions met for population 1? Record a complete sentence explaining why or why not.

Central Limit Theorem

The central limit theorem implies that the distribution of sample means is normal when the population distribution is normal, or is approximately normal when the sample size is large. Moreover,

\[ \begin{align*} \mbox{MEAN}(\bar{x}) & = \mu \\ \mbox{SD}(\bar{x}) &= \sigma/\sqrt{n} \approx s/\sqrt{n} \end{align*} \]

  1. The standard error \(s/\sqrt{n}\) is a theoretical approximation of the standard deviation of the null distribution. Record \(s/\sqrt{n}\), and compare it to the simulated \(\text{SD}_\text{null}\), which you reported in #8 of Part I. Are these values similar?

The t-statistic

  1. We can find a general formula for a standardized statistic for a test on a population mean. In particular, the t-statistic for a test on a population mean can be found by using this formula: \[ t = \frac{\bar{x} - \mu_0}{s/\sqrt{n}} \] Record the calculation and value of the t-statistic for your class data.

Have someone from your group put this calculation on the Jamboard.

Strength of Evidence

  1. The good news is that t-statistics can be interpreted very similarly to z-statistics. Namely, values greater than 2 (or less than -2) provide strong evidence against the null hypothesis. Interpret what the t-statistic is telling you about strength of evidence against the null hypothesis.

One Mean Applet

  1. Return to the One Mean applet, and set the Sample Size to match the class data. Generate a null distribution with at least 1000 dots. Above the null distribution, change the choice of statistic from mean to t-statistic. Check the box to Overlay t-Distribution. Does this theoretical model do a reasonable job of predicting the behavior of the simulated distribution of t-statistics?

Have someone post a screenshot of the overlaid t-distribution on the Jamboard.

Simulation and Theory

  1. Use the applet to count the number of simulated samples with a t-statistic less than (our alternative hypothesis) the observed value of your t-statistic (from #5) to find the approximate p-value (based on t-statistics). Record this p-value.

  2. The theory-based p-value (one-sample t-test) is also provided in the output. Record the theory-based p-value. How well do the simulation-based and theory-based p-values match?

Try another applet

  1. The theory-based test can also be done using the Theory-Based Inference applet. Select the One mean scenario, check the Test of significance box, and enter the appropriate values for \(n\), \(\bar{x}\), \(s\), and the hypotheses. Record your p-value and t-statistic. Compare these values to your answers to #9 and #5. Are they the same?

  2. Keep the hypotheses and \(n\) and \(s\) the same, and experiment with different values of \(\bar{x}\). Record the largest value of \(\bar{x}\) that gives a p-value less than 0.05. (This is the largest class average we would have to observe to find so-called “strong” evidence against \(H_0\).)

Bonus Material: How to do this in R

Read the data and print a summary:

sleepdata <- 
  read.table("http://math.westmont.edu/ma5/classSleep.txt", 
  header = TRUE)
summary(sleepdata)
   SleepHours    
 Min.   : 5.000  
 1st Qu.: 6.562  
 Median : 7.125  
 Mean   : 7.504  
 3rd Qu.: 8.188  
 Max.   :11.000  

Histogram using ggplot

One-Sample t-test in R

We set \(H_0: \mu = 8\), and the default alternative is two-sided:

library(ggplot2)
t.test(sleepdata$SleepHours, mu = 8)

    One Sample t-test

data:  sleepdata$SleepHours
t = -3.0095, df = 57, p-value = 0.003892
alternative hypothesis: true mean is not equal to 8
95 percent confidence interval:
 7.17449 7.83413
sample estimates:
mean of x 
  7.50431