hr <- c(80, 118, 92, 84, 78, 84,
76, 82, 76, 88, 108, 90,
90, 90, 86, 70, 68, 46,
98, 56, 84, 80, 78, 66, 60)STAT 516 hw 1
Students in a statistics class were asked to feel their pulses and count the number of heartbeats they felt during a thirty-second time period. These were doubled in order to obtain beats per minute (bpm) measurements. These are stored in the vector hr in the R code below:
1)
Check whether it appears the measurements come from a normal distribution by making a normal quantile-quantile plot.
qqnorm(scale(hr))
abline(0,1)2)
Report the sample mean
xbar <- mean(hr)
svar <- var(hr)
sn <- sqrt(svar) Sample mean: 81.12
Sample variance: 238.6933
Sample standard deviation: 15.4497
3)
Assume that the resting heart rate measurements are drawn from a normal distribution with unknown mean, but with a known standard deviation of
n <- length(hr)
sigma <- 16
alpha <- 0.01
za2 <- qnorm(1-alpha/2)
lo <- xbar - za2 * sigma / sqrt(n)
up <- xbar + za2 * sigma / sqrt(n)The 99% confidence interval is (72.87735, 89.36265).
4)
Now give a
ta2 <- qt(1-alpha/2,n-1)
lo <- xbar - ta2 * sn / sqrt(n)
up <- xbar + ta2 * sn / sqrt(n)The 99% confidence interval is (72.47762, 89.76238).
5)
Suppose a researcher wished to estimate the mean resting heart rate of this population of students with a margin of error no greater than
M <- 2
alpha <- 0.05
za2 <- qnorm(1-alpha/2)
nr <- ceiling(za2^2 * sn^2 / M^2)The required sample size is 230.
6)
A researcher wishes to know whether the mean resting heart rate for this population of students exceeds 80 bpm. Give
- The null and alternate hypotheses of interest,
- The value of the test statistic,
- The critical value for testing the hypothesis at significance level
, - The decision whether or not to reject
, and - The p-value for testing these hypotheses based on the data.
# Testing H_0: \mu \leq 85 vs H_1: \mu > 85.
alpha <- 0.05
mu0 <- 80
Ttest <- (xbar - mu0)/(sn/sqrt(n))
ta <- qt(1-alpha,n-1)
pval <- 1 - pt(Ttest,n-1)Testing H0: mu <= 80 vs H1: mu > 80
Test statistic: 0.3624665
Critical value: 1.710882
Decision: Fail to reject H0
p-value: 0.3600879
7)
A researcher wishes to know whether the mean resting heart rate for this population of students equal to 82 bpm.
- The null and alternate hypotheses of interest,
- The value of the test statistic,
- The critical value for testing the hypothesis at significance level
, - The decision whether or not to reject
, and - The p-value for testing these hypotheses based on the data.
alpha <- 0.10
mu0 <- 82
Ttest <- (xbar - mu0)/(sn/sqrt(n))
ta2 <- qt(1-alpha/2,n-1)
pval <- 2*(1 - pt(abs(Ttest),n-1))Testing H0: mu = 82 vs H1: mu != 82
Test statistic: -0.2847951
Critical value: 1.710882
Decision: Fail to reject H0
p-value: 0.7782442
8)
Suppose a researcher wants to test whether the mean resting heart rate in this population of students is greater than
alpha <- 0.05
mu_star <- 77
mu0 <- 75
gamma_star <- 0.9
beta_star <- 1 - gamma_star
za <- qnorm(1-alpha)
zb <- qnorm(1 - beta_star)
nr <- ceiling(sn^2 *(za + zb)^2/(mu_star - mu0)^2)
mu <- seq(72,80,length=500)
gm <- 1 - pnorm(za - (mu - mu0)/(sn/sqrt(nr)))
plot(gm ~mu,type ="l")
abline(h = gamma_star,lty = 3)
abline(v = mu_star,lty = 3)
abline(v = mu0,col="gray")
abline(h = alpha,col="gray")The required sample size is 512.
9)
Suppose a researcher wants to test whether the mean resting heart rate in this population of students is equal to
alpha <- 0.01
mu_star <- 80 # pick a value 2 blm away from mu0
mu0 <- 78
gamma_star <- 0.80
beta_star <- 1 - gamma_star
za2 <- qnorm(1-alpha/2)
zb <- qnorm(1 - beta_star)
nr <- ceiling(sn^2 *(za2 + zb)^2/(mu_star - mu0)^2)
mu <- seq(74,82,length=500)
gmr <- 1 - pnorm(za2 - (mu - mu0)/(sn/sqrt(nr)))
gml <- pnorm(-za2 - (mu - mu0)/(sn/sqrt(nr)))
gm <- gmr + gml
plot(gm ~mu,type ="l")
abline(h = gamma_star,lty = 3)
abline(v = mu0 + 2,lty = 3)
abline(v = mu0 - 2,lty = 3)
abline(v = mu0,col="gray")
abline(h = alpha,col="gray")The required sample size is 697.