In: Statistics and Probability
Assume that I asked heights of 40 female students. It turns out that average height and standard deviation of ladies in our class is 164 cm and 9 cm, respectively. For all computations, assume that the heights follow a normal distribution. (STATISTICS)
a) Write a function in R that calculates the confidence interval for given ?, X̄, s and n.
b) Write a function in R that calculates the prediction interval for given ?, X̄, s and n.
c) Write a function in R that conducts a hypothesis test. The function’s output will be “reject” or “don’t reject” using the input values of ?, X̄, s and n.
Here, n = 40
= 164
s = 9
a) To calculate confidence interval, we can use the below function
Below solution if for 5% significance. Can be charged as per a value
> a <- 0.05 > x <- 164 > s <- 9 > n <- 40 > error <- qnorm(1-a/2)*s/sqrt(n) > left <- a-error > right <- a+error > left [1] 161.2109 > right [1] 166.7891
b) Prediction interval is given by The function in R will be written as:-
> a <- 0.05
> x <- 164
> s <- 9
> error <- qnorm(1-a/2)*s
> left <- a-error
> right <- a+error
> left [1]
146.36
> right [1]
181.64
c) Function for two-tailed hypothesis test
The null hypothesis is that μ = 170. We begin with computing the test statistic.
> x = 164 # sample mean
> mu = 170 # hypothesized value
> s = 9 # sample standard deviation
> n = 40 # sample size
> z = (xbar−mu)/(s/sqrt(n))
>
z #
test statistic
[1] -4.21637
We then compute the critical values at .05 significance level.
> a = .05
> z.half.alpha = qnorm(1−a/2)
> c(−z.half.alpha, z.half.alpha)
[1] −1.9600 1.9600
> If −z.half.alpha <= z <= z.half.alpha, "Do No Reject", "Reject"
[1] Reject