Quiz 4 Statistical
InferenceA pharmaceutical company is interested in testing a potential blood pressure lowering medication. Their first examination considers only subjects that received the medication at baseline then two weeks later. The data are as follows (SBP in mmHg)
| Subject | Baseline | Week 2 |
|---|---|---|
| 1 | 140 | 132 |
| 2 | 138 | 135 |
| 3 | 150 | 151 |
| 4 | 148 | 146 |
| 5 | 135 | 130 |
Consider testing the hypothesis that there was a mean reduction in blood pressure? Give the P-value for the associated two sided T test.
(Hint, consider that the observations are paired.)
Answer
# Calculating the Hypothesis using a T-distribution with a paired.
q1 <- stats::t.test(x = c(140,138,150,148,135),
c(132,135,151,146,130),
paired = TRUE,
alternative = "two.sided")
# P value.
q1$p.value
## [1] 0.08652278
A sample of 9 men yielded a sample average brain volume of 1,100cc and a standard deviation of 30cc. What is the complete set of values of \(\mu_0\) that a test of \(H_0: \mu = \mu_0\) would fail to reject the null hypothesis in a two sided 5% Students t-test?
Answer
\(\mu \pm t_{(n-1,1-\frac{\alpha}{2}) \cdot \frac{sd}{\sqrt(n)}}\)
n <- 9
mu <- 1100
sd <- 30
alpha <- 5/100
# Calculating the quantile to df = 8 and p = 0.975
t_8_975 <- qt(p = (1 - alpha/2), df = 9 - 1)
# Calculating the CI.
mu + c(-1,1) * t_8_975 * sd / sqrt(n)
## [1] 1076.94 1123.06
Researchers conducted a blind taste test of Coke versus Pepsi. Each of four people was asked which of two blinded drinks given in random order that they preferred. The data was such that 3 of the 4 people chose Coke. Assuming that this sample is representative, report a P-value for a test of the hypothesis that Coke is preferred to Pepsi using a one sided exact test.
Answer
My Hypothesis:
\[H_{0}: p = 0.5\] \[H_{a}: p > 0.5\]
General formula:
\[P(n) = {4 \choose n} \cdot (1-p)^{(4-n)} \cdot (p)^{n}\] \[ P(Prefer \ Coke) = P(p \ge 3)$ = $P(3) + P(4)\] \[P(p \ge 3) = {4 \choose 3} \cdot (1-p)^{(4-3)} \cdot (p)^{3} + {4 \choose 4} \cdot (1-p)^{(4-4)} \cdot (p)^{4}\] \[P(p \ge 3) = 0.3125\]
# Calculating the probability.
P_3_4 <- choose(4,3) * (1-1/2)^1 * (1/2)^3 + choose(4,4) * (1-1/2)^0 * (1/2)^4
P_3_4
## [1] 0.3125
Infection rates at a hospital above 1 infection per 100 person days at risk are believed to be too high and are used as a benchmark. A hospital that had previously been above the benchmark recently had 10 infections over the last 1,787 person days at risk. About what is the one sided P-value for the relevant test of whether the hospital is below the standard?
Answer
ppois(q = 10, lambda = 1/100 * 1787)
## [1] 0.03237153
Suppose that 18 obese subjects were randomized, 9 each, to a new diet pill and a placebo. Subjectsβ body mass indices (BMIs) were measured at a baseline and again after having received the treatment or placebo for four weeks. The average difference from follow-up to the baseline (followup - baseline) was β3 kg/m2 for the treated group and 1 kg/m2 for the placebo group. The corresponding standard deviations of the differences was 1.5 kg/m2 for the treatment group and 1.8 kg/m2 for the placebo group. Does the change in BMI appear to differ between the treated and placebo groups? Assuming normality of the underlying data and a common population variance, give a p-value for a two sided t test.
Answer
\[H_{0}: \mu_{diff,treated} - \mu_{diff,placebo} = 0\] \[H_{a}: \mu_{diff,treated} - \mu_{diff,placebo} \ne 0\]
\[\underbrace{\mu_{diff,treated} - \mu_{diff,placebo}}_{0} = \bar{treated} - \bar{placebo} \pm t_{(n + n -2, 1-\frac{\alpha}{2})} \cdot S_{p} \cdot (\frac{1}{n} + \frac{1}{n})^{1/2} \] \[t_{(n + n -2, 1-\frac{\alpha}{2})} \cdot S_{p} \cdot (\frac{1}{n} + \frac{1}{n})^{1/2} = \bar{treated} - \bar{placebo}\] \[t_{(n + n -2, 1-\frac{\alpha}{2})} = \frac{\bar{treated} - \bar{placebo}}{S_{p} \cdot (\frac{1}{n} + \frac{1}{n})^{1/2}}\]
# Sample
n <- 9
# Treated
x_treat <- -3
s_treat <- 1.5
# Placebo
x_placebo <- 1
s_placebo <- 1.8
# The pooled variance estimator is:
sp <- sqrt(((n - 1) * s_treat^2 + (n - 1) * s_placebo^2)/(n + n - 2))
# Calculating the quantile given: mu_treat - mu_placebo = 0
t <- (x_treat - x_placebo)/(sp * sqrt(1/n + 1/n))
# Given t, its possible to calculate the probability.
q5_pvalue <- pt(t, n + n - 2)
# Formatting
format(q5_pvalue, digits = 2,scientific = FALSE)
## [1] "0.000051"
Brain volumes for 9 men yielded a 90% confidence interval of 1,077 cc to 1,123 cc. Would you reject in a two sided 5% hypothesis test of \(H_0 : \mu = 1,078\)?
Answer
The 90% CI already includes the \(\mu=1078\), so if I increase the CI to 95%, it will still contain the \(\mu=1078\). For this reason, I will not reject the \(H_0\) statement.
Researchers would like to conduct a study of \(100\) healthy adults to detect a four year mean brain volume loss of \(.01~mm^3\). Assume that the standard deviation of four year volume loss in this population is \(.04~mm^3\). About what would be the power of the study for a \(5\%\) one sided test versus a null hypothesis of no volume loss?
Answer
lower.tail = FALSE# Inputs
n <- 100
alpha <- 5/100
sd <- 0.04
mu <- 0.01
# Calculating the z value from alpha equal to 5%
z <- qnorm(p = (1 - alpha))
# Calculating the probability.
pnorm(z * sd/sqrt(n), mean = mu, sd = sd/sqrt(n), lower.tail = FALSE)
## [1] 0.8037649
Researchers would like to conduct a study of \(n\) healthy adults to detect a four year mean brain volume loss of \(.01~mm^3\). Assume that the standard deviation of four year volume loss in this population is \(.04~mm^3\). About what would be the value of \(n\) needed for \(90\%\) power of type one error rate of \(5\%\) one sided test versus a null hypothesis of no volume loss?
Answer
sig.level# Calculating the n value.
q8 <- power.t.test(power = 0.9,
delta = 0.01,
sd = 0.04,
sig.level = 0.05,
type = "one.sample",
alternative = "one.sided")
# Printing the n
round(q8$n)
## [1] 138
As you increase the type one error rate, \(\alpha\), what happens to power?