In: Statistics and Probability
1- Write a function f(n,a,b) that generates n random
numbers
# from Uniform(a,b) distribution and returns their minimum.
# Execute the function with n=100, a=1, b=9.
2- Replicate the function call f(100,1,9) 100 thousand
times
# and plot the empirical density of the minimum of 100 indep.
Unif(1,9)'s
3-Use the sampling distribution from (b) to find 95%
confidence
# interval for the minimum of 100 independent Unif(1,9)'s.
Please solve in R
## R function
Uniform_S=function(nsim)
{
Sam=list()
X=list()
Y=list()
for(i in 1:nsim)
{
Sam[[i]]=runif(n=100, min = 1, max = 9)
X[[i]]=unlist(Sam[[i]])
Y[[i]]=min(X[[i]])
}
return(Y)
}
U=unlist(Uniform_S(nsim=100))
# 2. Replicate the function call f(100,1,9) 100 thousand
times
# and plot the empirical density of the minimum of 100 indep
den=density(U)
plot(den)
# 3-Use the sampling distribution from (b) to find 95%
confidence
# interval for the minimum of 100 independent Unif(1,9)'s.
n <- length(U)
a <- mean(U)
s <- sd(U)
error <- qnorm(0.975)*s/sqrt(n)
left <- a-error
right <- a+error
left
right
## End the Function
## Run
> Uniform_S=function(nsim)
+ {
+ Sam=list()
+ X=list()
+ Y=list()
+
+ for(i in 1:nsim)
+ {
+ Sam[[i]]=runif(n=100, min = 1, max = 9)
+ X[[i]]=unlist(Sam[[i]])
+ Y[[i]]=min(X[[i]])
+ }
+ return(Y)
+ }
>
>
> U=unlist(Uniform_S(nsim=100))
>
> # 2. Replicate the function call f(100,1,9) 100 thousand
times
> # and plot the empirical density of the minimum of 100
indep
>
> den=density(U)
> plot(den)
>
> # 3-Use the sampling distribution from (b) to find 95%
confidence
> # interval for the minimum of 100 independent
Unif(1,9)'s.
>
>
>
> n <- length(U)
> a <- mean(U)
> s <- sd(U)
> error <- qnorm(0.975)*s/sqrt(n)
> left <- a-error
> right <- a+error
> left
[1] 1.056143
> right
[1] 1.078315
>
## Density plot