Complete the code to calculate the mean of the sample data.
mean_value <- [1](sample_data)The mean() function calculates the average value of the sample data, which is needed to compute the confidence interval.
Complete the code to calculate the standard error of the mean.
std_error <- sd(sample_data) / sqrt([1](sample_data))The standard error is the standard deviation divided by the square root of the sample size. The length() function returns the number of observations.
Fix the error in the code to calculate the confidence interval using the t-distribution.
error_margin <- qt(1 - [1] / 2, df = length(sample_data) - 1) * std_error
The confidence level is usually 95%, so the significance level alpha is 0.05. The code uses 1 - alpha/2 to get the correct quantile.
Fill both blanks to create the lower and upper bounds of the confidence interval.
conf_interval <- c(mean_value [1] error_margin, mean_value [2] error_margin)
The confidence interval lower bound is the mean minus the error margin, and the upper bound is the mean plus the error margin.
Fill all three blanks to calculate and print a 95% confidence interval for the sample mean.
mean_value <- [1](sample_data) std_error <- sd(sample_data) / sqrt([2](sample_data)) error_margin <- qt(1 - 0.05 / 2, df = [3](sample_data) - 1) * std_error
The mean is calculated with mean(). The sample size is found with length(), used for standard error and degrees of freedom in qt().