228k views
2 votes
Suppose we use the following code to generate a sample of height measurements in cm: x=rnorm(50,175,10) We are interested in creating a 90% confidence interval for the average population height. Which of the following is a valid code for computing a 90% confidence interval?

1. c(mean(x)−qt(0.95,49)∗sd(x)/sqrt(50),mean(x)+qt(0.95,49)∗sd(x)/sqrt(50))
2. c(mean(x) - qnorm(0.9) * sd(x)/sqrt(50), mean (x)+qnorm(0.9) ∗sd(x)/sqrt(50))
3. c(mean(x)−qt(0.9,49)∗sd(x)/sqrt(50),mean(x)+qt(0.9,49)∗sd(x)/sqrt(50))
4. c(mean(x) - qnorm (0.95)∗sd(x)/sqrt(50), mean (x)+qnorm(0.95)∗sd(x)/sqrt(50))

User BaltoStar
by
8.7k points

1 Answer

4 votes

Final answer:

The correct R code to compute a 90% confidence interval for the average population height using a given sample is the one that utilizes a t-distribution critical value obtained with qt(0.95, 49), which accounts for the central 90% of the probability of the distribution, leaving 5% in each tail, leading to option 1 being the valid choice.

Step-by-step explanation:

To calculate a 90% confidence interval for the average population height using a sample of heights, the correct R code snippets would include the correct critical value based on the t-distribution, since we assume that the population standard deviation is unknown and the sample size is relatively small (n=50). The t-distribution critical value can be obtained using the qt() function in R, which requires the desired confidence level and the degrees of freedom (n-1).

The correct code snippet for creating a 90% confidence interval would be:

  • This is because for a 90% confidence level, we want the central 90% of the distribution, which leaves 5% in each tail. Therefore, the 1 - 0.05 (or 0.95) percentile of the t-distribution is used.

Therefore, option 1 in the question is the valid code for computing a 90% confidence interval of the sample mean.

User Mikedanylov
by
8.0k points