In: Statistics and Probability
For each of the following subproblems:i. Plot the distribution you’re sampling from (e.g., ifXi∼Exp(λ), plot the exponentialdistribution with rateλ). See Lab 3 for a reminder on how to do this.ii. Generate a sample of sizen= 10 from the distribution, and find the sample mean.iii. Repeat step ii. 999 times (i.e.,k= 1000), and then plot a histogram of the samples.iv. Add a plot of the approximate normal density on top of the histogram.v. Repeat steps ii. – iv. with sample sizen= 100.
(a)Xiiid∼Uniform(−2,2)
(b)Xiiid∼Gamma(k= 2,λ= 0.5)
(c)Xiiid∼Poisson(λ= 1)
(d)Xiiid∼Geometric(p= 0.2)
from the given data of information
R code:
n=10
x=matrix(0,nrow=1000,ncol=n)
m=1:1000*0
for(i in 1:1000)
{
x[i,]=runif(n, min = -2, max = 2)
m[i]=mean(x[i,])
}
hist(m, density=20, breaks=20, prob=TRUE,
xlab="x-variable", ylim=c(0, 1.4),
main="normal curve over histogram when n=10")
curve(dnorm(x,mean(m),sd(m)),col="blue", lwd=2, add=TRUE,
yaxt="n")
.
R code:
n=100
x=matrix(0,nrow=1000,ncol=n)
m=1:1000*0
for(i in 1:1000)
{
x[i,]=runif(n, min = -2, max = 2)
m[i]=mean(x[i,])
}
hist(m, density=20, breaks=20, prob=TRUE,
xlab="x-variable", ylim=c(0, 4),
main="normal curve over histogram when n=100")
curve(dnorm(x,mean(m),sd(m)),col="blue", lwd=2,
add=TRUE,
R code:
n=10
x=matrix(0,nrow=1000,ncol=n)
m=1:1000*0
for(i in 1:1000)
{
x[i,]=rgamma(n, 2,0.5)
m[i]=mean(x[i,])
}
hist(m, density=20, breaks=20, prob=TRUE,
xlab="x-variable", ylim=c(0, 0.6),
main="normal curve over histogram when n=10")
curve(dnorm(x,mean(m),sd(m)),col="blue", lwd=2,
add=TRUE
R code:
n=10
x=matrix(0,nrow=1000,ncol=n)
m=1:1000*0
for(i in 1:1000)
{
x[i,]=rgamma(n, 2,0.5)
m[i]=mean(x[i,])
}
hist(m, density=20, breaks=20, prob=TRUE,
xlab="x-variable", ylim=c(0, 0.6),
main="normal curve over histogram when n=10")
curve(dnorm(x,mean(m),sd(m)),col="blue", lwd=2,
add=TRUE
R code:
n=10
x=matrix(0,nrow=1000,ncol=n)
m=1:1000*0
for(i in 1:1000)
{
x[i,]=rpois(n, 1)
m[i]=mean(x[i,])
}
hist(m, density=20, breaks=20, prob=TRUE,
xlab="x-variable", ylim=c(0, 2),
main="normal curve over histogram when n=10")
curve(dnorm(x,mean(m),sd(m)),col="blue", lwd=2, add=TRUE,
yaxt="n")
R code:
n=100
x=matrix(0,nrow=1000,ncol=n)
m=1:1000*0
for(i in 1:1000)
{
x[i,]=rpois(n, 1)
m[i]=mean(x[i,])
}
hist(m, density=20, breaks=20, prob=TRUE,
xlab="x-variable", ylim=c(0, 4),
main="normal curve over histogram when n=100")
curve(dnorm(x,mean(m),sd(m)),col="blue", lwd=2, add=TRUE,
yaxt="n")
R code:
n=10
x=matrix(0,nrow=1000,ncol=n)
m=1:1000*0
for(i in 1:1000)
{
x[i,]=rgeom(n, 0.2)
m[i]=mean(x[i,])
}
hist(m, density=20, breaks=20, prob=TRUE,
xlab="x-variable", ylim=c(0, 0.5),
main="normal curve over histogram when n=10")
curve(dnorm(x,mean(m),sd(m)),col="blue", lwd=2, add=TRUE,
yaxt="n")
R code:
n=100
x=matrix(0,nrow=1000,ncol=n)
m=1:1000*0
for(i in 1:1000)
{
x[i,]=rgeom(n, 0.2)
m[i]=mean(x[i,])
}
hist(m, density=20, breaks=20, prob=TRUE,
xlab="x-variable", ylim=c(0, 2),
main="normal curve over histogram when n=100")
curve(dnorm(x,mean(m),sd(m)),col="blue", lwd=2, add=TRUE,
yaxt="n")