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

The diameter of ball bearings produced by a machine is uniformly distributed bet

ID: 3258280 • Letter: T

Question

The diameter of ball bearings produced by a machine is uniformly distributed between 2 and 6 millimeters. You would like to estimate the true mean diameter of these ball bearings. You decide to use a confidence interval, i.e. a range of values that is likely to include the true population parameter of interest, for your estimation. Simulate a sample of size 18 from the above distribution. a) Compute your 95% confidence interval for the mean, assuming variance is known. b) Compute your 95% confidence interval for the mean, assuming variance is unknown. [Estimate variance with sample variance, s^2 = 1/n - 1 sigma ^n_i = 1 (x_i - x)^2]. c) For each of the two previous problems, repeat the process 10000 times, and count how many times your confidence interval contains the true mean. Does it match up with what you expect? Simulate a sample of size 100 from the above distribution. a) Compute your 95% confidence interval for the mean, assuming variance is known. b) Compute your 95% confidence interval for the mean, assuming variance is unknown. [Estimate variance with sample variance, s^2 = sigma ^n_i = 1(x_i - x)^2. c) For each of the two previous problems, repeat the process 10000 times, and count how many times your confidence interval contains the true mean. Does it match up with what you expect?

Explanation / Answer

Performed the simulation study in R. Results are given below the code.

code with ouput (combined):

##question 1:----------------------------------------------------------------------
> n=18
> x=runif(n,2,6)# generating size of sample 18 fromuniform distribution.
> m=mean(x)
> #a)
> # known variance=v^2=(6-2)^2/12 using formula for variance of normal distribution.
> v=sqrt((6-2)^2/12)
> error = qnorm(0.975)*v/sqrt(n)
> left1=m-error
> right1=m+error
> left1
[1] 3.438478
> right1
[1] 4.505347
> #b)
> ##unknown variance
> s=sqrt(sum((x-m)^2)/(n-1))
> error = qnorm(0.975)*s/sqrt(n)
> left2=m-error
> right2=m+error
> left2
[1] 3.436669
> right2
[1] 4.507157
> #c)
> #for (a)
> N=10000
> count=0
> for(i in 1:N)
+ {x=runif(n,2,6)# generating size of sample 18 fromuniform distribution.
+ m=mean(x)
+ if(left1<=m&&m<=right1)
+ {
+ count=count+1
+ }
+ }
> (count/N)*100
[1] 95.02
> #for(b)
> N=10000
> count=0
> for(i in 1:N)
+ {x=runif(n,2,6)# generating size of sample 18 fromuniform distribution.
+ m=mean(x)
+ if(left2<=m&&m<=right2)
+ {
+ count=count+1
+ }
+ }
> (count/N)*100
[1] 95.39
>
> ##question 2:----------------------------------------------------------------------
> n=100 #changed sample size
> x=runif(n,2,6)# generating size of sample 18 fromuniform distribution.
> m=mean(x)
> #a)
> # known variance=v^2=(6-2)^2/12 using formula for variance of normal distribution.
> v=sqrt((6-2)^2/12)
> error = qnorm(0.975)*v/sqrt(n)
> left1=m-error
> right1=m+error
> left1
[1] 3.978891
> right1
[1] 4.431525
> #b)
> ##unknown variance
> s=sqrt(sum((x-m)^2)/(n-1))
> error = qnorm(0.975)*s/sqrt(n)
> left2=m-error
> right2=m+error
> left2
[1] 3.992983
> right2
[1] 4.417433
> #c)
> #for (a)
> N=10000
> count=0
> for(i in 1:N)
+ {x=runif(n,2,6)# generating size of sample 18 fromuniform distribution.
+ m=mean(x)
+ if(left1<=m&&m<=right1)
+ {
+ count=count+1
+ }
+ }
> (count/N)*100
[1] 56.71
> #for(b)
> N=10000
> count=0
> for(i in 1:N)
+ {x=runif(n,2,6)# generating size of sample 18 fromuniform distribution.
+ m=mean(x)
+ if(left2<=m&&m<=right2)
+ {
+ count=count+1
+ }
+ }
> (count/N)*100
[1] 52.29

only code:

##question 1:----------------------------------------------------------------------
n=18
x=runif(n,2,6)# generating size of sample 18 fromuniform distribution.
m=mean(x)
#a)
# known variance=v^2=(6-2)^2/12 using formula for variance of normal distribution.
v=sqrt((6-2)^2/12)
error = qnorm(0.975)*v/sqrt(n)
left1=m-error
right1=m+error
left1
right1
#b)
##unknown variance
s=sqrt(sum((x-m)^2)/(n-1))
error = qnorm(0.975)*s/sqrt(n)
left2=m-error
right2=m+error
left2
right2
#c)
#for (a)
N=10000
count=0
for(i in 1:N)
{x=runif(n,2,6)# generating size of sample 18 fromuniform distribution.
m=mean(x)
if(left1<=m&&m<=right1)
{
count=count+1
}
}
(count/N)*100
#for(b)
N=10000
count=0
for(i in 1:N)
{x=runif(n,2,6)# generating size of sample 18 fromuniform distribution.
m=mean(x)
if(left2<=m&&m<=right2)
{
count=count+1
}
}
(count/N)*100

##question 2:----------------------------------------------------------------------
n=100 #changed sample size
x=runif(n,2,6)# generating size of sample 18 fromuniform distribution.
m=mean(x)
#a)
# known variance=v^2=(6-2)^2/12 using formula for variance of normal distribution.
v=sqrt((6-2)^2/12)
error = qnorm(0.975)*v/sqrt(n)
left1=m-error
right1=m+error
left1
right1
#b)
##unknown variance
s=sqrt(sum((x-m)^2)/(n-1))
error = qnorm(0.975)*s/sqrt(n)
left2=m-error
right2=m+error
left2
right2
#c)
#for (a)
N=10000
count=0
for(i in 1:N)
{x=runif(n,2,6)# generating size of sample 100 fromuniform distribution.
m=mean(x)
if(left1<=m&&m<=right1)
{
count=count+1
}
}
(count/N)*100
#for(b)
N=10000
count=0
for(i in 1:N)
{x=runif(n,2,6)# generating size of sample 100 fromuniform distribution.
m=mean(x)
if(left2<=m&&m<=right2)
{
count=count+1
}
}
(count/N)*100

Result:

1.

a) [3.438478, 4.505347]

b) [3.436669, 4.50715]

c) for a) 95.02% and for b) 95.39%. Thus matches the expected result.

2.

a) [3.978891,4.431525]

b)[3.992983,4.41743]

c) for a) 56.71% and for b) 52.29%. Thus do not match the expected result.