Generate 10,000 samples of a random variable with exponential distribution using
ID: 3544975 • Letter: G
Question
Generate 10,000 samples of a random variable with exponential distribution using simulation method.
The exponential random variable is a standard one with a mean of 10.
Plot the distribution function of the samples by summing the number of samples less than certain value.
Plot also the distribution function of the exponential distribution random variable using its mathematical equation.
As the third figure, plot both functions together in one figure.
Submit a Matlab function or a script that generates the three figures.
Your function or script must contain comments that explain your steps.
Explanation / Answer
H <- B.V[filter]
nH <- B.V[!filter & !is.na(B.V)]
tlist2 <- NULL
all <- c(H,nH)
for(i in 1:5000) {
s <- sample(2586,92) # choose a sample
tlist2 <- c(tlist2, t.test(all[s],all[-s],
var.eq=T)$stat) # add t-stat to list
}
plot(qnorm((2*(1:5000)-1)/10000), sort(tlist2))
abline(0,1,col=2)
ks.test(tlist2, "pnorm")
plot(qnorm((2*(1:5000)-1)/10000), sort(tlist2)-mean(tlist2))
abline(0,1,col=2)
ks.test(tlist2-mean(tlist2), "pnorm")
random.ksstat <- NULL
for(i in 1:1000) {
x <- rnorm(5000)
random.ksstat <- c(random.ksstat,
ks.test(x,pnorm,mean=mean(x))$stat)
}
H <- B.V[filter]
nH <- B.V[!filter & !is.na(B.V)]
tlist2 <- NULL
all <- c(H,nH)
for(i in 1:5000) {
s <- sample(2586,92) # choose a sample
tlist2 <- c(tlist2, t.test(all[s],all[-s],
var.eq=T)$stat) # add t-stat to list
}
plot(qnorm((2*(1:5000)-1)/10000), sort(tlist2))
abline(0,1,col=2)
ks.test(tlist2, "pnorm")
plot(qnorm((2*(1:5000)-1)/10000), sort(tlist2)-mean(tlist2))
abline(0,1,col=2)
ks.test(tlist2-mean(tlist2), "pnorm")
random.ksstat <- NULL
for(i in 1:1000) {
x <- rnorm(5000)
random.ksstat <- c(random.ksstat,
ks.test(x,pnorm,mean=mean(x))$stat)
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.