Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. Perform a simulation study in R (provide the R code) to compare then coverage

ID: 3071193 • Letter: 3

Question

3. Perform a simulation study in R (provide the R code) to compare then coverage of the two confidence intervals: F(x)(1- F(x)) and F(a)td where: 0.05, z is the standard normal critical value and d is the critical value in the Kolmogorov-Smirnov table. Set a "seed" value and simulate B 200 samples of size n 50 from a Uniform distribution with parameters (0, 2) and check the coverage of F(x) for x 0.2, 1, 1.8 (i.e. check how many times the true value of F(x) is included in the two intervals out of the 200 simulations). Comment on the results (compare the coverage of the confidence intervals) and discuss how these can change by modifying B and n.

Explanation / Answer

Set the seed efore simulating data in R, which is useful for creating simulations that can be reproduced. Otherwise the random numbers keeps on changing every time we run the same code.

eg:

set.seed(50)

B=200

n=50

counter=0

for (i in 1:B) { # loop is used since we need it 200 times so called a new variable B and set its value to 200
u<-runif(n,min=0,max=2)#generate 50 numbers between 0 and 2)
y<-mean(u)#calculates the mean of the sample generated
F<-y/2#Finds the value of empirical distribution function using the mean
x<-0.2# value given in the question .you can rerun this code by changing this number to 1 and 1.8
f<-x/2#finding the value of distribution function
ll<-F-1.96*sqrt(F*(1-F)/n) #Lower limit calculation .You can also change the formula to F+d where d is the value from the klolmogorov smirnov table.
ul<-F+1.96*sqrt(F*(1-F)/n) # calculates the upper limit
if(f> ll & f< ul) {
counter = counter + 1}# To check whether the distribution function at a particular value lies within the limit .A counter is added every time when the value lies within the range.
}
counter #and this program returns the value of the counter which means the number of times the empirical distribution function lie within the range after running 200 samples


Code with out explanation

set.seed(50)

B=200

n=50

counter=0

for (i in 1:samples) {
u<-runif(n,min=0,max=2)
y<-mean(u)
F<-y/2
x<-0.5
f<-x/2
ll<-F-1.96*sqrt(F*(1-F)/n)
ul<-F+1.96*sqrt(F*(1-F)/n)
if(f> ll & f< ul) {
counter = counter + 1}

}
counter

In the begining of the code B is set to 200 and n is set to 50 .Changes can be made there to increase or decrease the number of iterations

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote