Remember our general Hypothesis Testing framework:
We estimate the mean of quantitative (Q) variables, such as weight, height, blood pressure, and IQ.
Sample mean
$$ { \bar{x} = \sum_{i=1}^n \frac{x_{i}}{n} = \frac{x_{1}+x_{2}+...+x_{n}}{n} } $$
where xi = ith value of x
n = sample size (total number of observations)
It is basically the sum of all values divided by the total number of values.
The sample mean is a point estimate of the population mean (μ), i.e., we estimate the population mean ("true mean") by the sample mean, which was discussed in a previous lecture.
We use this to compare the sample mean to the population mean where:
H0: null hypothesis
Ha: alternative hypothesis
μ: population mean
μ0: null hypothesized value
The null hypothesis here is:
The population mean μ is equal to the null hypothesized value (μ0).The alternative hypotheses are:
H0: μ = μ0
The population mean μ is not equal to null hypothesized value (μ0).Select only one alternative hypothesis.
Ha: μ ≠ μ0
or
The population mean μ is greater than the null hypothesized value (μ0).
Ha: μ > μ0
or
The population mean μ is less than the null hypothesized value (μ0).
Ha: μ < μ0
We will use the following variables for this section:
H0: null hypothesis
Ha: alternative hypothesis
μ: population mean
μ0: null hypothesized value
σ: population standard deviation
n: size of random sample
X: sample mean
x: computed sample mean
Null hypothesis:
H0: μ = μ0
Alternative hypotheses:
Ha: μ ≠ μ0 or Ha: μ > μ0 or Ha: μ < μ0
Under the assumption that H0 is true, test statistic Z obtained by standardizing X is
$$ {Z = \frac{\bar{X} - \mu_0}{\frac{\sigma}{\sqrt{n}}}} $$
Test statistic value z would be
$$ {z = \frac{\bar{x} - \mu_0}{\frac{\sigma}{\sqrt{n}}}} $$
The test statistic value z would give you an idea of the difference between x and μ0 in terms of "standard deviation units."
| Alternative Hypothesis | Rejection Region for Level α Test |
| Ha: μ ≠ μ0 | either z ≥ zα/2 or z ≤ -zα/2 (two-tailed test) |
| Ha: μ > μ0 | z ≥ zα (upper-tailed test) |
| Ha: μ < μ0 | z ≤ -zα (lower-tailed test) |
Let us use the metabolic data set from a mouse experiment in Dr. Kim’s lab.
library(tidyverse)
met <- read_csv("https://denvirlab.marshall.edu/BMR617-2024/data/TH-B6-metabolic.csv") %>%
separate(MouseID, sep="-", into=c("Strain","Diet","ID"))
We can find the mean cholesterol levels (mg/dl) and their corresponding standard deviations for the C57BL/6 (B6) and TallyHO (TH) mice regardless of diet by using the code below. Depending on your version of RStudio, you may need to use "%>% as.data.frame()" as a workaround.
met %>% group_by(Strain) %>% summarize(Mean_Chol=mean(Cholesterol), SD_Chol=sd(Cholesterol))
OR
met %>% group_by(Strain) %>% summarize(Mean_Chol=mean(Cholesterol), SD_Chol=sd(Cholesterol)) %>% as.data.frame()
Output:
Strain Mean_Chol SD_Chol
1 B6 82.50533 45.58874
2 TH 135.03857 34.93428
You can create vectors containing the cholesterol levels (mg/dl) per strain by:
b6_chol <- pull((filter(met, Strain=="B6")), Cholesterol)
th_chol <- pull((filter(met, Strain=="TH")), Cholesterol)
Assume that our example data set is a subset of a normal population and that we know the population mean and standard deviation.
install.packages("TeachingDemos")
library(TeachingDemos)
Perform z-test:
z.test(b6_chol, mu=90, stdev=35, alternative=“two.sided”)
z.test(th_chol, mu=90, stdev=35, alternative=“two.sided”)
Z-test Output for B6:
One Sample z-test
data: b6_chol
z = -0.82933, n = 15.000, Std. Dev. = 35.000, Std. Dev. of the sample mean = 9.037, p-value =
0.4069
alternative hypothesis: true mean is not equal to 90
95 percent confidence interval:
64.79321 100.21745
sample estimates:
mean of b6_chol
82.50533
Let us understand the output.
One Sample z-test
data: th_chol
z = 4.8148, n = 14.0000, Std. Dev. = 35.0000, Std. Dev. of the sample mean = 9.3541, p-value =
1.473e-06
alternative hypothesis: true mean is not equal to 90
95 percent confidence interval:
116.7048 153.3724
sample estimates:
mean of th_chol
135.0386
Let us understand the output.Here, we will assume a large sample size n so the sample standard deviation S approaches population standard deviation σ.
We will use the following variables for this section:
H0: null hypothesis
Ha: alternative hypothesis
μ: population mean
μ0: null hypothesized value
S: sample standard deviation
s: computed standard deviation
n: size of random sample
X: sample mean
x: computed sample mean
Null hypothesis:
H0: μ = μ0
Alternative hypotheses:
Ha: μ ≠ μ0 or Ha: μ > μ0 or Ha: μ < μ0
Standardized variable (which has approximately a standard normal distribution) would be
$$ {Z = \frac{\bar{X} - \mu}{\frac{S}{\sqrt{n}}}} $$
Test statistic Z would be
$$ {Z = \frac{\bar{X} - \mu_0}{\frac{S}{\sqrt{n}}}} $$
Test statistic value z would be
$$ {z = \frac{\bar{x} - \mu_0}{\frac{s}{\sqrt{n}}}} $$
| Alternative Hypothesis | Rejection Region for Level α Test |
| Ha: μ ≠ μ0 | either z ≥ zα/2 or z ≤ -zα/2 (two-tailed test) |
| Ha: μ > μ0 | z ≥ zα (upper-tailed test) |
| Ha: μ < μ0 | z ≤ -zα (lower-tailed test) |
Let us use a modified version of the metabolic data set from a mouse experiment in Dr. Kim’s lab that you have been using.
This time there will be dummy values included. Note that the dummy values are for illustration purposes only and not from any experiment.
metmod <- read_csv("https://denvirlab.marshall.edu/BMR617-2024/data/TH-B6-metabolic-modified.csv") %>%
separate(MouseID, sep="-", into=c("Strain","Diet","ID"))
Find the mean cholesterol levels (mg/dl) and standard deviation regardless of strain and diet.
mice_chol <- pull(metmod, Cholesterol)
mean(mice_chol)
sd(mice_chol)
Sample mean is 108.6543 while sample standard deviation is 48.94094.
Perform z-test (use the sample standard deviation for stdev in this R code).
z.test(mice_chol, mu=90, alternative ="two.sided") # will spit out error
z.test(mice_chol, mu=90, stdev=48.94094, alternative ="two.sided")
Z-test Output for modified metabolic data:
One Sample z-test
data: mice_chol
z = 2.4406, n = 41.0000, Std. Dev. = 48.9409, Std. Dev. of the sample mean = 7.6433, p-value =
0.01466
alternative hypothesis: true mean is not equal to 90
95 percent confidence interval:
93.67374 123.63489
sample estimates:
mean of mice_chol
108.6543
Let us understand the output.Here, we will have a small sample size n, so assume that it has at least approximately a normal population distribution and the population standard deviation is unknown. It follows a t-distribution.
We will use the following variables for this section:
H0: null hypothesis
Ha: alternative hypothesis
μ: population mean
μ0: null hypothesized value
S: sample standard deviation
s: computed standard deviation
n: size of random sample
X: sample mean
x: computed sample mean
Null hypothesis:
H0: μ = μ0
Alternative hypotheses:
Ha: μ ≠ μ0 or Ha: μ > μ0 or Ha: μ < μ0
Standardized variable (assuming approximately normal distribution) would be
$$ {T = \frac{\bar{X} - \mu}{\frac{S}{\sqrt{n}}}} $$
Test statistic T would be
$$ {T = \frac{\bar{X} - \mu_0}{\frac{S}{\sqrt{n}}}} $$
Test statistic value t would be
$$ {t = \frac{\bar{x} - \mu_0}{\frac{s}{\sqrt{n}}}} $$
| Alternative Hypothesis | Rejection Region for Level α Test |
| Ha: μ ≠ μ0 | either t ≥ tα/2,n-1 or t ≤ -tα/2,n-1 (two-tailed test) |
| Ha: μ > μ0 | t ≥ tα,n-1 (upper-tailed test) |
| Ha: μ < μ0 | t ≤ -tα,n-1 (lower-tailed test) |
Let us use the metabolic data set of TH mice from a mouse experiment in Dr. Kim’s lab that you have been using.
Let us assume a normal population distribution with unknown population standard deviation σ.
Assume for TH mice that the population mean cholesterol μ is 90 mg/dl.
Perform t-test.
Format: t.test(data, mu = μ, alternative=“greater”, “less”, “two.sided”)
t.test(th_chol, mu=90, alternative=“two.sided”)
t-test Output for TH:
One Sample t-test
data: th_chol
t = 4.8239, df = 13, p-value = 0.0003323
alternative hypothesis: true mean is not equal to 90
95 percent confidence interval:
114.8681 155.2090
sample estimates:
mean of x
135.0386
Let us understand the output.Devore, J.L. (2010). Probability and Statistics for Engineering and the Sciences (Eighth ed). Cengage Learning, Boston, MA, USA. https://faculty.ksu.edu.sa/sites/default/files/probability_and_statistics_for_engineering_and_the_sciences.pdf
Motulsky, H. (2018). Intuitive biostatistics : a nonmathematical guide to statistical thinking (Fourth edition. ed.). New York: Oxford University Press. pp. 318-328.
Elston, R.C. and Johnson, W.D. (2008). Basic Biostatistics for Geneticists and Epidemiologists: A Practical Approach. John Wiley & Sons Ltd, West Sussex, UK.