Question
*related to R programming*


Using simulation, estimate the coverage for the t-based interval ☺ ta/2,n-1.sx/vn for a population mean y using a confidence
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The R-code is

N=10000# number of replicates

X1=0 #for number of samples contains CI for gausian

X2=0#for number of samples contains CI for exponential

for( i in 1:N)

{set.seed(i+i)

X=rnorm(10) #genrate random numbers from gausian distribution with mean 0 and variance 1

LL=mean(X)-qt(1-0.05,9)*(sd(X)/sqrt(length(X)))

UL=mean(X)+qt(1-0.05,9)*(sd(X)/sqrt(length(X)))

if(LL<0 && 0<UL) X1=X1+1

}

for( i in 1:N)

{set.seed(i+i)

X=rexp(10,1)#generate random numbers with exponential distribution with mean 1

LL=mean(X)-qt(1-0.05,9)*(sd(X)/sqrt(length(X)))

UL=mean(X)+qt(1-0.05,9)*(sd(X)/sqrt(length(X)))

if(LL<1 && 1<UL) X2=X1+1

}

prop.test(X1,N,0.90,conf.level=0.90)#for Gaussian

prop.test(X2,N,0.90,conf.level=0.90)#for exponential

The output of code is

>N=10000# number of replicates

>X1=0 #for number of samples contains CI for gausian

>X2=0#for number of samples contains CI for exponential

>for( i in 1:N)

>{set.seed(i+i)

>X=rnorm(10) #genrate random numbers from gausian distribution with mean 0 and variance 1

>LL=mean(X)-qt(1-0.05,9)*(sd(X)/sqrt(length(X)))

>UL=mean(X)+qt(1-0.05,9)*(sd(X)/sqrt(length(X)))

>if(LL<0 && 0<UL) X1=X1+1

>}

>for( i in 1:N)

>{set.seed(i+i)

>X=rexp(10,1)#generate random numbers with exponential distribution with mean 1

>LL=mean(X)-qt(1-0.05,9)*(sd(X)/sqrt(length(X)))

>UL=mean(X)+qt(1-0.05,9)*(sd(X)/sqrt(length(X)))

>if(LL<1 && 1<UL) X2=X1+1

>}

>prop.test(X1,N,0.90,conf.level=0.90)#for Gaussian

-sample proportions test with continuity correction

data: X1 out of N, null probability 0.9

X-squared = 1.0336, df = 1, p-value = 0.3093

alternative hypothesis: true p is not equal to 0.9

90 percent confidence interval:

0.8980735 0.9079062

sample estimates:

p

0.9031

>prop.test(X2,N,0.90,conf.level=0.90)#for exponential

1-sample proportions test with continuity correction

data: X2 out of N, null probability 0.9

X-squared = 1.1025, df = 1, p-value = 0.2937

alternative hypothesis: true p is not equal to 0.9

90 percent confidence interval:

0.8981757 0.9080040

sample estimates:

p

0.9032

# The CI for desired coverage in case of standard gausian distribution is(0.8980735 ,0.9079062) which contains true coverage

# The CI for desired coverage in case of standard exponential distribution( 0.8981757, 0.9080040) which contains true coverage

Add a comment
Know the answer?
Add Answer to:
*related to R programming* Using simulation, estimate the coverage for the t-based interval ☺ ta/2,n-1.sx/vn for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT