BMR 617: Statistical Techniques for the Biomedical Sciences

Hypothesis Testing for Population Mean

Remember our general Hypothesis Testing framework:

Population Mean

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.

Hypothesis Testing for Population Mean μ

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).
H0: μ = μ0
The alternative hypotheses are:
The population mean μ is not equal to null hypothesized value (μ0).
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
Select only one alternative hypothesis.

Normal Population with Known Population Standard Deviation σ

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 zzα/2 or z-zα/2 (two-tailed test)
 Ha: μ > μ0  zzα (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.

Assume for B6 and TH mice that: Install TeachingDemos and load it.

	install.packages("TeachingDemos")
	library(TeachingDemos)
	
Perform z-test:
Format: z.test(data, mu = μ, stdev = σ, alternative="greater", "less", "two.sided")

	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.

The sample estimate (i.e., estimate of the mean cholesterol for B6 from the sample) is 82.505 mg/dl.
You may check this by just calculating the sum of the B6 cholesterol values divided by the number of values OR by finding the mean of b6_chol (i.e., mean(b6_chol)). We also saw it a while ago when we ran tidyverse's summarize.

The 95% confidence intervaI for the mean cholesterol is [64.793, 100.217].
We are 95% confident that the interval [64.793, 100.217] contains the true value of the mean of cholesterol values for B6 mice in this sample.

The test statistic value z is -0.82933.
The sample mean (x) of 82.505 mg/dl is 0.82 standard deviation (of X) below what we expect it to be (less than 1 sd away) when the null hypothesis is true.

The p-value is 0.4069. This means that if the null hypothesis were true, there would be a 40.7% chance of seeing this data.
If the population mean cholesterol for mice were 90 mg/dl, there would be a 40.7% chance of seeing this data in a study of 15 B6 mice.

Let us interpret the result.

Since the p-value of 0.4069 is higher than our predetermined threshold of 0.05, we cannot reject the null hypothesis (i.e., for this particular sample, we failed to demonstrate a difference between the sample mean cholesterol and the population mean cholesterol).

Z-test Output for TH:

		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.

The sample estimate (i.e., estimate of the mean cholesterol for TH from the sample) is 135.039 mg/dl.
You may check this by just calculating the sum of the TH cholesterol values divided by the number of values OR by finding the mean of th_chol (i.e., mean(th_chol)). Again, we also saw it a while ago when we ran tidyverse's summarize.

The 95% confidence intervaI for the mean cholesterol is [116.705, 153.372].
We are 95% confident that the interval [116.705, 153.372] contains the true value of the mean of cholesterol values for TH mice in this sample.

The test statistic value 𝑧 is 4.8148.
The sample mean (x) of 135.039 mg/dl is 4.81 standard deviations (of X) above what we expect it to be when the null hypothesis is true.

The p-value is 1.473e-06 or 0.000001473. This means that if the null hypothesis were true, there would be a 0.0001473% chance of seeing data “this extreme.”
If the population mean cholesterol for mice were 90 mg/dl, there would be a 0.0001473% chance of seeing data this different in a study of 14 TH mice.

Let us interpret the result.

Since the p-value of 1.473e-06 is less than our predetermined threshold of 0.05, we would reject the null hypothesis and conclude that the mean cholesterol in this sample of TH mice is different from the mean cholesterol of 90 mg/dl in the mice population.

Since the entire 95% confidence interval [116.705, 153.372] is above 90 mg/dl, we would conclude that the TH sample mean cholesterol is more than 90 mg/dl.

Large Sample Tests

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 zzα/2 or z-zα/2 (two-tailed test)
 Ha: μ > μ0  zzα (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.

The sample estimate (i.e., estimate of the mean cholesterol for this modified sample) is 108.654 mg/dl.
You may check this by just calculating the sum of the cholesterol values divided by the number of values OR by finding the mean of mice_chol (i.e., mean(mice_chol)) as we have previously ran.

The 95% confidence intervaI for the mean cholesterol is [93.674, 123.635].
We are 95% confident that the interval [93.674, 123.635] contains the true value of the mean of cholesterol values for this modified sample.

The test statistic value z is 2.4406.
The sample mean (x) of 108.654 mg/dl is 2.44 standard deviations (of X) above what we expect it to be when the null hypothesis is true.

The p-value is 0.01466. This means that if the null hypothesis were true, there would be a 1.466% chance of seeing data “this extreme.”
If the population mean cholesterol for mice were 90 mg/dl, there would be a 1.466% chance of seeing data this different in a study of 41 mice.

Let us interpret the result.

Since the p-value of 0.01466 is less than our predetermined threshold of 0.05, we would reject the null hypothesis and conclude that the mean cholesterol in this modified sample is different from the mean cholesterol of 90 mg/dl in the mice population.

Since the entire 95% confidence interval [93.674, 123.635] is above 90 mg/dl, we would conclude that the sample mean cholesterol is more than 90 mg/dl.

Normal Population Distribution

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 ttα/2,n-1 or t-tα/2,n-1 (two-tailed test)
 Ha: μ > μ0  tα,n-1 (upper-tailed test)
 Ha: μ < μ0  -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.

The sample estimate (i.e., estimate of the mean cholesterol for TH from the sample) is 135.039 mg/dl.
You may check this by just calculating the sum of the TH cholesterol values divided by the number of values OR by finding the mean of th_chol (i.e., mean(th_chol)). Again, we have ran this a while ago.

The 95% confidence intervaI for the mean cholesterol is [114.868, 155.209].
We are 95% confident that the interval [114.868, 155.209] contains the true value of the mean of cholesterol values for TH mice in this sample.

The p-value is 0.0003323. This means that if the null hypothesis were true, there would be a 0.033233% chance of seeing data “this extreme.”
If the population mean cholesterol for mice were 90 mg/dl, there would be a 0.033233% chance of seeing data this different in a study of 14 TH mice.
If the sample mean was the same as the population mean, the probability of observing data at least as extreme as that actually observed is 0.0003323 [reject 𝐻_0]

Let us interpret the result.

Since the p-value of 0.0003323 is less than our predetermined threshold of 0.05, we would reject the null hypothesis and conclude that the mean cholesterol in this sample of TH mice is different from the mean cholesterol of 90 mg/dl.

Since the entire 95% confidence interval [114.868, 155.209] is above 90 mg/dl, we would conclude that the TH sample mean cholesterol is more than 90 mg/dl.

References

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.