STAT 516 hw 1

Author

Karl Gregory

Students in a statistics class were asked to feel their pulses and count the number of heartbeats they felt during two thirty-second time periods separated by several minutes. For each student the two counts were added together in order to obtain a beats per minute (bpm) measurement. These bpm measurements are stored in the vector hr in the R code below:

hr <- c(75,77,86,108,61,46,82,78,81,
        79,55,67,63,94,76,56,69,79,
        66,78,77,91,82,80,73,62,76,80,83)

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 X¯n, sample variance Sn2, and sample standard deviation Sn of the measurements. Give also the sample size n.

xbar <- mean(hr)
svar <- var(hr)
sn <- sqrt(svar)
n <- length(hr)
 Sample mean: 75.17241  
 Sample variance: 158.2192 
 Sample standard deviation: 12.57852 
 Sample size: 29

3)

Assume that the resting heart rate measurements are drawn from a normal distribution with unknown mean, but with a known standard deviation of 16 beats per minute (bpm). Give a 99% confidence interval for the mean resting heart rate based on the measurements from the students.

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 (67.5193, 82.82553).

4)

Now give a 99% confidence interval for the mean resting heart rate based on the measurements of the students, using the estimated standard deviation Sn in place of σ. That is, assume now that σ is unknown and must be estimated with Sn.

ta2 <- qt(1-alpha/2,n-1)
lo <- xbar - ta2 * sn / sqrt(n)
up <- xbar + ta2 * sn / sqrt(n)
The 99% confidence interval is (68.71806, 81.62677).

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 2 beats per minute with 95% confidence. Using Sn as a guess for σ, suggest a sample size which should be just large enough for the researcher.

M <- 2
alpha <- 0.05
za2 <- qnorm(1-alpha/2)
nr <- ceiling(za2^2 * sn^2 / M^2)
The required sample size is 152.

6)

A researcher wishes to know whether the mean resting heart rate for this population of students exceeds 73 bpm. Give

  1. The null and alternate hypotheses of interest.
  2. The value of the test statistic.
  3. The critical value for testing the hypothesis at significance level α=0.05.
  4. The p-value for testing these hypotheses based on the data.
  5. The decision whether or not to reject H0.
alpha <- 0.05
mu0 <- 73
Ttest <- (xbar - mu0)/(sn/sqrt(n))
ta <- qt(1-alpha,n-1)
pval <- 1 - pt(Ttest,n-1)
dec <- ifelse(pval < alpha, "Reject H0", "Fail to reject H0")
i.   Testing H0: mu <= 73 vs H1: mu > 73 
ii.  Test statistic: 0.9300621
iii. Critical value: 1.701131
iv.  p-value: 0.1801444
v.   Decision: Fail to reject H0

7)

A researcher wishes to know whether the mean resting heart rate for this population of students equal to 70 bpm. Give:

  1. The null and alternate hypotheses of interest.
  2. The value of the test statistic.
  3. The critical value for testing the hypothesis at significance level α=0.10.
  4. The p-value for testing these hypotheses based on the data.
  5. The decision whether or not to reject H0.
alpha <- 0.10
mu0 <- 70
Ttest <- (xbar - mu0)/(sn/sqrt(n))
ta2 <- qt(1-alpha/2,n-1)
pval <- 2*(1 - pt(abs(Ttest),n-1))
dec <- ifelse(pval < alpha, "Reject H0", "Fail to reject H0")
i.   Testing H0: mu = 70 vs H1: mu != 70
ii.  Test statistic: 2.214434
iii. Critical value: 1.701131
iv.  p-value: 0.03511043
v.   Decision: Reject H0

8)

Suppose a researcher wants to test whether the mean resting heart rate in this population of students is greater than 75 bpm. If the true mean is 77 bpm or greater, the researcher would like to detect this with probability at least 90% while using a significance level of α=0.05. Using the sample standard deviation as an estimate of the unknown population standard deviation σ, give a recommended sample size for the researcher.

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 339.

9)

Suppose a researcher wants to test whether the mean resting heart rate in this population of students is equal to 78 bpm. If the true mean lies 2 bpm or more away from this value, the researcher would like to detect this with probability at least 80% while using a significance level of α=0.01. Using the sample standard deviation as an estimate of the unknown population standard deviation σ, give a recommended sample size for the researcher.

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 462.