0
0
R Programmingprogramming~10 mins

Confidence intervals in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the mean of the sample data.

R Programming
mean_value <- [1](sample_data)
Drag options to blanks, or click blank then click option'
Amean
Bmedian
Csum
Dsd
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'median' instead of 'mean' will give the middle value, not the average.
Using 'sum' will add all values but not calculate the average.
2fill in blank
medium

Complete the code to calculate the standard error of the mean.

R Programming
std_error <- sd(sample_data) / sqrt([1](sample_data))
Drag options to blanks, or click blank then click option'
Alength
Bmean
Csum
Dvar
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sum' will add all values, which is not the sample size.
Using 'mean' or 'var' will not give the count of data points.
3fill in blank
hard

Fix the error in the code to calculate the confidence interval using the t-distribution.

R Programming
error_margin <- qt(1 - [1] / 2, df = length(sample_data) - 1) * std_error
Drag options to blanks, or click blank then click option'
A0.1
B0.05
C0.5
D0.01
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0.5 or 0.1 will give wrong quantiles and incorrect intervals.
Using 0.01 corresponds to 99% confidence, not 95%.
4fill in blank
hard

Fill both blanks to create the lower and upper bounds of the confidence interval.

R Programming
conf_interval <- c(mean_value [1] error_margin, mean_value [2] error_margin)
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' for both bounds will give incorrect intervals.
Using '*' or '/' will cause wrong calculations.
5fill in blank
hard

Fill all three blanks to calculate and print a 95% confidence interval for the sample mean.

R Programming
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
Drag options to blanks, or click blank then click option'
Amean
Blength
Dmedian
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'median' instead of 'mean' for the first blank.
Using 'sum' or other functions instead of 'length' for sample size.