Lab5
Lab5
Point Estimation
Let’s assume we have a random sample X1 , X2 , ..., Xn from a population with mean µ and variance σ 2 . The
sample mean X̄ is an estimator of the population mean µ. The sample variance S 2 is an estimator of the
population variance σ 2 .
Pn
We can find the sample mean and sample variance using the following formulas: X̄ = n1 i=1 Xi and
1 n
S 2 = n−1 2
P
i=1 (Xi − X̄) .
Let’s calculate the sample mean and sample variance for a random sample of 5 numbers: 1, 2, 3, 4, 5.
# sample data
x <- c(1, 2, 3, 4, 5)
n <- length(x)
# sample mean
mean_x <- mean(x)
Confidence Intervals
A confidence interval is a range of values that is likely to contain the true value of an unknown population
parameter. The confidence level is the probability that the interval will contain the true parameter value.
For example, a 95% confidence interval for the population mean µ is given by X̄ ± zα/2 √Sn , where X̄ is the
sample mean, S is the sample standard deviation, n is the sample size, and zα/2 is the critical value of the
standard normal distribution corresponding to the desired confidence level.
Let’s calculate a 95% confidence interval for the population mean using the sample data from the previous
example.
x <- c(1, 2, 3, 4, 5)
n <- length(x)
# confidence level
1
## [1] 1.959964
# margin of error
margin_of_error <- z * (var_x / sqrt(n))
cat("95% Confidence Interval for the population mean:", int_lower, int_upper, "\n")
Exercises
1. Create a vector x with the values 234,2356,341,1235 and calculate the sample mean and sample variance.
2. create a vector y with the values 1,2,3,4,5,6,7,8,9,10 and calculate a 90% confidence interval for the
population mean.
3. generate 500 random numbers from a range of 1-100 and calculate the sample mean and sample variance.
4. Assume you have a random normal sample of size 100 with a mean of 50 and a standard deviation of
10. Calculate a 95% confidence interval for the population mean.
5. Assume you have a random sample of size 50 with a mean of 74 and a standard deviation of 16.
Calculate a 99% confidence interval for the population mean.
6. Assume you have a random sample of size 25 with a mean of 30 and a standard deviation of 5. Calculate
a 90% confidence interval for the population mean.
7. Assume you have a random sample of size 10 with a mean of 20 and a standard deviation of 3. Calculate
a 99% confidence interval for the population mean.