In the last module, we discussed describing data.
In this module, we are discussing statistical inference on one sample.
Means / medians
Proportions
Variances / standard deviations
In this lecture, we are focusing on one-sample means and medians.
R Setup| resident_name | department | district | academy_status | academy_exam_score | sleep_hours | hustle_earnings | district_temp_f |
|---|---|---|---|---|---|---|---|
| Sable Jones | Desk | Rainforest District | Fail | 65 | 5.5 | 14.72 | 72.2 |
| Kevin Frostwhisker | Patrol | Downtown | Fail | 69 | 7.4 | 45.66 | 66.2 |
| Jasper Duskrunner | Patrol | Sahara Square | Pass | 79 | 8.7 | 30.91 | 89.8 |
\bar{y} \pm t_{\alpha/2, n-1} \frac{s}{\sqrt{n}}
where
\bar{y} is the sample mean (the point estimate)
t has n-1 degrees of freedom (the critical value)
s is the sample standard deviation and n is the sample size (s/\sqrt{n} is the standard error of the mean)
Two-Tailed
H_0: \mu = \mu_0
H_1: \mu \ne \mu_0
Left-Tailed
H_0: \mu \ge \mu_0
H_1: \mu < \mu_0
Right-Tailed
H_0: \mu \le \mu_0
H_1: \mu > \mu_0
\mu is the population mean,
\mu_0 is the hypothesized value of \mu.
t_0 = \frac{\bar{y} - \mu_0}{s/\sqrt{n}}
where
\bar{y} is the sample mean
\mu_0 is the hypothesized value of \mu
s is the sample standard deviation
n is the sample size
R)one_mean() function from library(ssstats) to perform statistical inference.dataset_name |> one_mean(outcome = variable_name,
mu = hypothesized_value,
alternative = "two" | "less" | "greater",
alpha = alpha_level)dataset_name into one_mean(), and sets outcome to the variable being tested.
mu, the hypothesized population value the sample mean is being compared against.
alternative, the direction of the test: "two" for two-sided, "less" and "greater" for one-sided tests.
alpha, the significance level.
where
outcome is the variable name of the outcome variable
mu is the hypothesized value of the population mean
alternative is the alternative hypothesis (default = “two”)
alpha is the significance level (default = 0.05)
The ZPD Academy claims that the passing exam average is 72 points. As Zootopia’s data analyst, you’ve been asked to check whether that claim actually holds up. We will use the zootopia dataset to answer the following question:
First, we need to describe the data.
Then, we will perform a hypothesis test to answer the question.
One-sample mean
x̅ = 77.3333 (SD = 8.023)
95% CI for μ: (74.3375, 80.3292)
Hypotheses:
H₀: μ = 0
H₁: μ ≠ 0
Test statistic: t(29) = 52.795
p-value: < 0.001
Conclusion: Reject the null hypothesis (p = < 0.001 < α = 0.050)
Then, we will perform a hypothesis test to answer the question.
How do we translate this into hypotheses?
For the one_mean() function, we will set
mu = 72alternative = "two".Hypotheses
Test Statistic and p-Value
Rejection Region
Conclusion and Interpretation
Not everyone in Zootopia earns a paycheck the same way. Some residents have steady side hustles that bring in predictable income. The Zootopia City Council has claimed that the typical resident hustle income is Z 35. As the data analyst, you’ve been asked to check. We will use the zootopia dataset to answer the following question:
First, we need to describe the data.
Then, we will perform a hypothesis test to answer the question.
One-sample mean
x̅ = 36.7123 (SD = 22.7781)
95% CI for μ: (28.2068, 45.2178)
Hypotheses:
H₀: μ = 0
H₁: μ ≠ 0
Test statistic: t(29) = 8.828
p-value: < 0.001
Conclusion: Reject the null hypothesis (p = < 0.001 < α = 0.050)
Then, we will perform a hypothesis test to answer the question.
How do we translate this into hypotheses?
For the one_mean() function, we will set
mu = 35alternative = "greater".One-sample mean
x̅ = 36.7123 (SD = 22.7781)
95% CI for μ: (28.2068, 45.2178)
Hypotheses:
H₀: μ ≤ 35
H₁: μ > 35
Test statistic: t(29) = 0.412
p-value: 0.342
Conclusion: Fail to reject the null hypothesis (p = 0.342 ≥ α = 0.050)
Hypotheses
Test Statistic and p-Value
Rejection Region
Conclusion and Interpretation
We assume that the data has an approximate mound-shaped and symmetric distribution.
We will use a quantile-quantile plot (Q-Q plot) to check the assumption of normality.
A QQ plot (“quantile-quantile plot”) is a quick visual check for one question: does my data look roughly normal?
Each dot compares one thing: where the observed data falls, versus where it would fall if your data were “perfectly normal.”
Look at the left side of the plot: the dots dip below the line instead of following it.
The histogram confirms that the data does not have a mound-shaped and symmetric distribution.
Notice how closely the dots hug the diagonal line, especially through the middle.
The histogram confirms that the data has a mound-shaped and symmetric distribution.
Look at the right side of the plot: the dots rise above the line instead of following it.
The historgram confirms that the data does not have a mound-shaped and symmetric distribution.
Notice the dots aren’t a smooth curve, but instead are clustered like a staircase.
Again, the histogram confirms that the data does not have a mound-shaped and symmetric distribution.
R)one_qq() function from library(ssstats) to eyeball normality.dataset_name into one_qq(), generating a QQ plot for the outcome variable.
where
outcome is the variable name of the outcome variableacademy_exam_score variable.hustle_earnings variable.The t-test we have learned is considered a parametric method.
Nonparametric methods do not have distributional assumptions.
Why don’t we always use nonparametric methods?
They are often less efficient: a larger sample size is required to achieve the same probability of a Type I error.
They discard useful information :(
(M_L, M_U) = (y_{(L_{\alpha/2})}, y_{(U_{\alpha/2})})
where
L_{\alpha/2} is the lower critical value of a binomial distribution with parameters n and p = 0.5
U_{\alpha/2} is the upper critical value of a binomial distribution with parameters n and p = 0.5
In R, linear interpolation is used to find the lower and upper bounds of the CI, making it a precise (1-\alpha)100\% CI
Two-Tailed
H_0: M = M_0
H_1: M \ne M_0
Left-Tailed
H_0: M \ge M_0
H_1: M < M_0
Right-Tailed
H_0: M \le M_0
H_1: M > M_0
where
M is the population median,
M_0 is the hypothesized value of M.
S = \sum_{i=1}^n I_{(y_i > M_0)}
where
I is an indicator function that results in a 1 or a 0
n is the sample size
R)one_median() function from library(ssstats) to perform statistical inference.dataset_name |> one_median(outcome = variable_name,
m = hypothesized_value,
alternative = "two" | "less" | "greater",
alpha = alpha_level)dataset_name into one_median(), and sets outcome to the column being examined.
m, the hypothesized population median the sample median is being compared against.
alternative, the direction of the test: "two" for two-sided and "less" or "greater" for a one-sided test.
alpha, the significance level.
where
outcome is the variable name of the outcome variable
m is the hypothesized value of the population median
alternative is the alternative hypothesis (default = “two”)
alpha is the significance level (default = 0.05)
Recall in the Zootopia data, we were investigating the typical income from side hustles. The research question was
We saw that the normality was questionable, thus, we now want to apply a nonparametric approach.
Our hypotheses now become
Is the typical side hustle income actually Z 35, or are residents earning more?
Applying the one_median() function,
Hypotheses
Test Statistic and p-Value
Rejection Region
Conclusion and Interpretation
One-sample median
Median = 31.07
95% CI for M: (23.1486, 37.9992)
Hypotheses:
H₀: M ≤ 35
H₁: M > 35
Test statistic: S = 13
p-value: 0.819
Conclusion: Fail to reject the null hypothesis (p = 0.819 ≥ α = 0.050)
The Zootopia Weather Bureau has publicly claimed that the average daily temperature across the city is 75°F. As the data analyst, you have a sample of daily temperature readings (district_temp_f).
Our analysis steps:
district_temp_f variable.One-sample median
Median = 71.25
95% CI for M: (65.1129, 76.7288)
Hypotheses:
H₀: M = 0
H₁: M ≠ 0
Test statistic: S = 30
p-value: < 0.001
Conclusion: Reject the null hypothesis (p = < 0.001 < α = 0.050)
Then, we will perform a hypothesis test to answer the question.
How do we translate this into hypotheses?
For the one_median() function, we will set
m = 75alternative = "two".Hypotheses
Test Statistic and p-Value
Rejection Region
Conclusion and Interpretation
Using a t-test to examine the mean (\mu) requires normality.
one_qq()).The analysis you choose should match the needed method:
If we meet normality (one_mean()):
If we do not meet normality (one_median()):