0% found this document useful (0 votes)
2 views

Lab5

Uploaded by

taytay2560
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lab5

Uploaded by

taytay2560
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab 5:Point Estimation

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)

# sample variance - var uses n-1 in the denominator


var_x <- var(x)

cat("Sample mean:", mean_x, " Sample variance:", var_x, "\n")

## Sample mean: 3 Sample variance: 2.5

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

alpha <- 0.05

# critical value for a 95% confidence level


z <- qnorm(1 - alpha/2)
print(z)

1
## [1] 1.959964
# margin of error
margin_of_error <- z * (var_x / sqrt(n))

int_upper <- mean_x + margin_of_error


int_lower <- mean_x - margin_of_error

cat("95% Confidence Interval for the population mean:", int_lower, int_upper, "\n")

## 95% Confidence Interval for the population mean: 0.8086936 5.191306

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.

You might also like