Ou have learned that given a sample of size n from a normal distribution, the CL=95% confidence interval for the mean can be calculated by Sample mean +/- z((1-CL)/2)*Sample std/sqrt(n). Where z((1-cl)/2)=z(.025) is the z score.a. help(qnorm) function. Use qnorm(1-.025) to find z(.025).
b. Create a vector x by generating n=50 numbers from N(mean=30,sd=2) distribution. Calculate the confidence interval from this data using the CI formula. Check whether the interval covers the true mean=30 or not.
c. Repeat the above experiments for 200 times to obtain 200 such intervals. Calculate the percentage of intervals that cover the true mean=30. This is the empirical coverage probability. In theory, it should be very close to your CL.
d. Write a function using CL as an input argument, and the percentage calculated from question c as an output. Use this function to create a 5 by 2 matrix with one column showing the theoretical CL and the other showing the empirical coverage probability, for CL=.8, .85, .9, .95,.99.

Answers

Answer 1
Answer:

a. To find the z score for a given confidence level, you can use the `qnorm()` function in R. The `qnorm()` function takes a probability as an argument and returns the corresponding z score. To find the z score for a 95% confidence level, you can use `qnorm(1-.025)`:

```R
z <- qnorm(1-.025)
```

This will give you the z score for a 95% confidence level, which is approximately 1.96.

b. To create a vector `x` with 50 numbers from a normal distribution with mean 30 and standard deviation 2, you can use the `rnorm()` function:

```R
x <- rnorm(50, mean = 30, sd = 2)
```

To calculate the confidence interval for this data, you can use the formula:

```R
CI <- mean(x) + c(-1, 1) * z * sd(x) / sqrt(length(x))
```

This will give you the lower and upper bounds of the 95% confidence interval. You can check whether the interval covers the true mean of 30 by seeing if 30 is between the lower and upper bounds:

```R
lower <- CI[1]
upper <- CI[2]
if (lower <= 30 && upper >= 30) {
 print("The interval covers the true mean.")
} else {
 print("The interval does not cover the true mean.")
}
```

c. To repeat the above experiment 200 times and calculate the percentage of intervals that cover the true mean, you can use a for loop:

```R
count <- 0
for (i in 1:200) {
 x <- rnorm(50, mean = 30, sd = 2)
 CI <- mean(x) + c(-1, 1) * z * sd(x) / sqrt(length(x))
 lower <- CI[1]
 upper <- CI[2]
 if (lower <= 30 && upper >= 30) {
   count <- count + 1
 }
}
percentage <- count / 200
```

This will give you the percentage of intervals that cover the true mean.

d. To write a function that takes a confidence level as an input and returns the percentage of intervals that cover the true mean, you can use the following code:

```R
calculate_percentage <- function(CL) {
 z <- qnorm(1-(1-CL)/2)
 count <- 0
 for (i in 1:200) {
   x <- rnorm(50, mean = 30, sd = 2)
   CI <- mean(x) + c(-1, 1) * z * sd(x) / sqrt(length(x))
   lower <- CI[1]
   upper <- CI[2]
   if (lower <= 30 && upper >= 30) {
     count <- count + 1
   }
 }
 percentage <- count / 200
 return(percentage)
}
```

You can then use this function to create a 5 by 2 matrix with one column showing the theoretical CL and the other showing the empirical coverage probability:

```R
CL <- c(.8, .85, .9, .95, .99)
percentage <- sapply(CL, calculate_percentage)
matrix <- cbind(CL, percentage)
```

This will give you a matrix with the theoretical CL in the first column and the empirical coverage probability in the second column.

Know more about z score here:

brainly.com/question/15016913

#SPJ11


Related Questions

What are the common factors of 60 36 and 24?
Company A offers a starting salary of $28,000 with a raise of $3,000 each year. Company B offers a starting salary of $36,000 with a raise of $2,000 per year. Company C offers a starting salary of $18,000. After how many years would the salaries for Companies A and B be the same? How much of a raise per year would Company C have to offer to equal the salaries of Companies A and B in the year in which the salaries of Companies A and B in the year in which the salaries of those two companies are the same?
Identify the explanatory and response variables in the following situation:There is a strong negative correlation between latitude above the equator and average temperature on December 21. A: Explanatory: Latitude Response: Daylight hours B. Explanatory: Latitude Response: Average temperature C. Explanatory: Daylight hours Response: Latitude D. Explanatory: Time of year Response: Daylight hours
Find the GCF of 4x^2 y and 6xy^3
Savvas Realize Tonya’s dog-walking service charges a flat rate of $20 per month, plus $3 per mile that each dog is walked. Beth does not charge a monthly fee for her dog-walking service, but she charges $5 per mile that each dog is walked.Part AChoose the equation that can be used to find the number of miles m for which Tonya and Beth would charge the same amount. A. 20 + 3m = 5m B. 20 = 3m + 5m C. 20 + 5m = 3m D. 20 + m = 8mPart Bm = _____ miles

120 books increased by 55%

Answers

Simplest way to do this:
 number of books= 120
 percentage represented by 120= 100%
 increase current percent by 55%= 155%

: . 55% increase = original number of books * (155%)
                           = 120 * (155/100)
                           = 186

What are the solutions to the quadratic equation 4x^2 = 64? A. x = −16 and x = 16
B. x = −8 and x = 8
C. x = −4 and x = 4
D. x = −2 and x = 2

Answers

Answer:

C

Step-by-step explanation:

Given

4x² = 64 ( divide both sides by 4 )

x² = 16 ( take the square root of both sides )

x = ± √(16) = ± 4

Solutions are x = - 4 and x = 4 → C

If a material contains three elements joined in a fixed proportion, it is a(an)a. mixture.
b. solution.
c. atom.
d. compound

Answers

The answer is d. if they are chemically joined as a mixture is multiple element but they aren't chemically joined. And an atom is what the element is made of and a solution is not anything to do with joined elements

A rental car costs $48 for one day plus an additional $0.52 per mile. If you have $110, how many miles can you drive the car?

Answers

Answer:

2.27 miles is the answer.

Step-by-step explanation:

Money needed = $48+$0.52 = $48.52

So,

$48.52 = 1 mile

$1 = 1/$48.52

$110 = (1/$48.52)×$110

= 2.27 miles

mr schiffer planted 9 fruit trees in his orchard. of the , 1/3 are grapefruit trees. how many trees are garapefruit trees

Answers

if 1/3th of the trees are grapefruit trees and he planted 9 trees there is 3 grapefruit trees hoped this help
the answer is 1/3×9=3
so 3 are grapefruit trees

There are 8 students in a small class. To make a team, the names of the 2 of them will be drawn from a hat. How many different teams of 2 students are

Answers

use slot method
2 slots

8 choices for first slot
7 choices for second (since 1 is in 1st slot)
8 times 7=56

56 ways to make 2 person teams
The first name can be any one of the 8.
               For each of those . . .
The second name can be any one of the remaining 7.

Total number of ways that 2 names can be drawn = (8 x 7) = 56 .

But . . .

Each team can be drawn in two different ways . . .
       -- Smith first, then Cohen
       -- Cohen first, then Smith.

So, among the 56 ways to draw 2 names, you will find
each possible pair of names drawn twice, in the opposite
order.

The number of different 2-member teams is  (56 / 2)  =  28 .