Question

In: Statistics and Probability

This is the code for the LLN question iid random variable from exponential distribution with mean...

This is the code for the LLN question iid random variable from exponential distribution with mean beta. Beta is fixed 1 for illustration.
# Testing LLN
plot.ybar <- function(n, m = 1e5, beta = 1) {
Ybars <- rep(0,m)
for(i in 1:m) {
Y.sample <- rexp(n,1/beta)
Ybars[i] <- mean(Y.sample)
}
  
p <- hist(Ybars, xlim=c(0,4), freq=F,main = paste("Distribution of Ybar when n=",n, sep=""))

}

par(mfrow = c(2,2))
for (n in c(2, 10, 50, 200)) {
plot.ybar(n)
}

Using similar code in R, how can I do the experiment for Bernoulli(0.1) and Uniform(0,4)

Solutions

Expert Solution

Note that the only difference we need to make is in the input argument of the function plot.ybar i.e. instead of "beta", if we have bernoulli distribution, then we must replace "beta" with Bernoulli parameter "p" and similarly for unifrm distribution, we must replace with parameters of uniform distribution i.e. "a" and "b".

Code for Bernoulli(0.1) :

plot.ybar <- function(n, m = 1e5, prob = 0.1) {
Ybars <- rep(0,m)
for(i in 1:m) {
Y.sample <- rbern(n,prob)
Ybars[i] <- mean(Y.sample)
}
  
p <- hist(Ybars, xlim=c(0,4), freq=F,main = paste("Distribution of Ybar when n=",n, sep=""))

}

par(mfrow = c(2,2))
for (n in c(2, 10, 50, 200)) {
plot.ybar(n)
}

Code for Uniform(0,4) :

plot.ybar <- function(n, m = 1e5, a = 0, b=4) {
Ybars <- rep(0,m)
for(i in 1:m) {
Y.sample <- runif(n,a,b)
Ybars[i] <- mean(Y.sample)
}
  
p <- hist(Ybars, xlim=c(0,4), freq=F,main = paste("Distribution of Ybar when n=",n, sep=""))

}

par(mfrow = c(2,2))
for (n in c(2, 10, 50, 200)) {
plot.ybar(n)
}


Related Solutions

Program a code for the random variable (Exponential distribution), where the user informs the data and...
Program a code for the random variable (Exponential distribution), where the user informs the data and parameters necessary to generate the Probability Density function (PDF) and the Cumulative Distribution Function (CDF).
Suppose X is an exponential random variable with mean 5 and Y is an exponential random...
Suppose X is an exponential random variable with mean 5 and Y is an exponential random variable with mean 10. X and Y are independent. Determine the coefficient of variation of X + Y
If Y is a random variable with exponential distribution with mean 1/λ, show that E (Y...
If Y is a random variable with exponential distribution with mean 1/λ, show that E (Y ^ k) = k! / (λ^k), k = 1,2, ...
A random sample of size 30 from an exponential distribution with mean 5 is simulated. Show...
A random sample of size 30 from an exponential distribution with mean 5 is simulated. Show the R-code to plot the empirical cdf for this sample along with the true cdf in the sample graph.
A random sample of size 30 from an exponential distribution with mean 5 is simulated. Describe...
A random sample of size 30 from an exponential distribution with mean 5 is simulated. Describe the process of plotting the empirical cdf for this sample along with the true cdf in the sample graph.
Let Y1, Y2, ..., Yn be a random sample from an exponential distribution with mean theta....
Let Y1, Y2, ..., Yn be a random sample from an exponential distribution with mean theta. We would like to test H0: theta = 3 against Ha: theta = 5 based on this random sample. (a) Find the form of the most powerful rejection region. (b) Suppose n = 12. Find the MP rejection region of level 0.1. (c) Is the rejection region in (b) the uniformly most powerful rejection region of level 0.1 for testing H0: theta = 3...
This is the code in R for the Central Limit theorem question. This is Exponential distribution...
This is the code in R for the Central Limit theorem question. This is Exponential distribution with mean beta. How can I modify this code to Bernoulli(0.1), Uniform (0,4), and Normal distribution (2,1)    plot.z <- function(n, m=1e5, beta = 1) { mu <- beta sigma <- beta zs <- rep(0,m) for(i in 1:m) { Y.sample <- rexp(n, 1/beta) Ybar <- mean(Y.sample) zs[i] <- (Ybar - mu) / (sigma / sqrt(n)) } p <- hist(zs, xlim=c(-4,4), freq = F, main =...
Probability And Statistics Question: Explain the exponential random variable and normal random variable with at-least ten...
Probability And Statistics Question: Explain the exponential random variable and normal random variable with at-least ten examples in real life? In which situation we prefer normal random variable instead of exponential variable?
If X represents a random variable coming from a normal distribution with mean 3 and if...
If X represents a random variable coming from a normal distribution with mean 3 and if P(X>4.2)=0.36P(X>4.2)=0.36, then P(3<X<4.2)=0.14P(3<X<4.2)=0.14. ___True ___False
The time required to service a particular machine is an exponential random variable with mean 10...
The time required to service a particular machine is an exponential random variable with mean 10 minutes. If a repair person has 35 machines to service, compute the approximate probability that all the work can be completed in under 5 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT