Question

To use R/Rstudio do it (a) Simulate a sample of size n = 30 from N(1,32),...

To use R/Rstudio do it


(a) Simulate a sample of size n = 30 from N(1,32), and calculate the sample variance.
(b) Plot the histogram of your simulated sample in part (a) with option breaks=10.
(c) Repeat (a) 100 times using a for loop, so you will have 100 sample variances. Plot the histogram of the 100 sample variances.
(d) Calculate the mean and the variance of the 100 sample variances in part (c). Is the mean close to 9?

Homework Answers

Answer #1

a)

set.seed(100)
x=rnorm(30,1,3) #Simulation from a N(1,3^2) distribution
var(x) #This calculates sample variance and not the population variance

b) hist(x,breaks=10,main="Histogram of generated sample") #Plots the histogram of the simulated values

c)

set.seed(100)

sample_var=c() #This creates an empty vector
for (i in 1:1000)
{
x=rnorm(30,1,3)
sample_var[i]=(var(x))
}

#sample_var is a vector of sample variances for 100 simulations.

hist(sample_var) #Plotting the histogram of the list of sample variances

d) mean(sample_var)

#9.024444 is what I got as the mean of the 100 sample variances.

var(sample_var)

#This gave me 5.466779 as the variance of the 100 sample variances.

The mean is very close to 9.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
To use R/Rstudio do it "some require": set.seed(123) ,to use 123 (a) Simulate a sample of...
To use R/Rstudio do it "some require": set.seed(123) ,to use 123 (a) Simulate a sample of size n = 30 from N(1,32), and calculate the sample variance. (b) Plot the histogram of your simulated sample in part (a) with option breaks=10. (c) Repeat (a) 100 times using a for loop, so you will have 100 sample variances. Plot the histogram of the 100 sample variances. (d) Calculate the mean and the variance of the 100 sample variances in part (c)....
R Simulation: For n = 10, simulate a random sample of size n from N(µ,σ2), where...
R Simulation: For n = 10, simulate a random sample of size n from N(µ,σ2), where µ = 1 and σ2 = 2; compute the sample mean. Repeat the above simulation 500 times, plot the histogram of the 500 sample means (does it mean that I can just use hist() method instead of plot() method). Now repeat the 500 simulations for n = 1,000. Compare these two sets of results with different sample sizes, and discuss it in the context...
Use R to code a function to generate a random sample of size n from the...
Use R to code a function to generate a random sample of size n from the Beta(a, b) distribution by the acceptance-rejection method. (1) Generate a random sample of size 3000 from the Beta(4,3) distribution. (2) Graph the histogram of the sample with the theoretical Beta(4,3) density superimposed. Answer the above questions by showing the R codes and results.
Using R programming language, complete the following. 1. Generate the bivariate normal sample of size 100...
Using R programming language, complete the following. 1. Generate the bivariate normal sample of size 100 with parameters a. marginal mean of X equal to 1, b. marginal mean of Y equal to 2, c. marginal variance of X equal to 3, d. marginal variance of Y equal to 4, e. correlation between X and Y equal to -1/2. You can use the function mvrnorm(), first installing its package by the code if (! require ("MASS")) install.packages("MASS"); library ("MASS") 2....
Develop an algorithm for generation a random sample of size N from a binomial random variable...
Develop an algorithm for generation a random sample of size N from a binomial random variable X with the parameter n, p. [Hint: X can be represented as the number of successes in n independent Bernoulli trials. Each success having probability p, and X = Si=1nXi , where Pr(Xi = 1) = p, and Pr(Xi = 0) = 1 – p.] (a) Generate a sample of size 32 from X ~ Binomial (n = 7, p = 0.2) (b) Compute...
a. If ? ̅1 is the mean of a random sample of size n from a...
a. If ? ̅1 is the mean of a random sample of size n from a normal population with mean ? and variance ?1 2 and ? ̅2 is the mean of a random sample of size n from a normal population with mean ? and variance ?2 2, and the two samples are independent, show that ?? ̅1 + (1 − ?)? ̅2 where 0 ≤ ? ≤ 1 is an unbiased estimator of ?. b. Find the value...
i.Bias of Sample Mean Draw 20 samples from the normal distribution N(5, 4). Compute the mean...
i.Bias of Sample Mean Draw 20 samples from the normal distribution N(5, 4). Compute the mean of your 20 samples. Report the bias of the sample mean ii. Variance of Sample Mean (Continue of problem i) To estimate the variance of the sample mean, we need to draw many different samples of size 20. Now, we draw 1000 times a sample of size 20. Store all the 1000 sample means. Report the variance of the estimated sample mean. Hint: To...
Conducting a Simulation For example, say we want to simulate the probability of getting “heads” exactly...
Conducting a Simulation For example, say we want to simulate the probability of getting “heads” exactly 4 times in 10 flips of a fair coin. One way to generate a flip of the coin is to create a vector in R with all of the possible outcomes and then randomly select one of those outcomes. The sample function takes a vector of elements (in this case heads or tails) and chooses a random sample of size elements. coin <- c("heads","tails")...
Use R. Generate a random sample with n=15 random observations from an exponential distribution with mean=1....
Use R. Generate a random sample with n=15 random observations from an exponential distribution with mean=1. Calculate the sample median, which is an estimator of the population median. Use bootstrap (nonparametric, with B=1000) methods to estimate the variance of the estimator for the population median. use the Monte Carlo method, e.g. generate 1000 samples of size 15 to estimate the true variance of the median estimator. Compare and comment on your results.
A random sample of size n = 241 is taken from a population of size N...
A random sample of size n = 241 is taken from a population of size N = 5,588 with mean μ = −68 and variance σ2 = 183. [You may find it useful to reference the z table.] a-1. Is it necessary to apply the finite population correction factor? Yes No a-2. Calculate the expected value and the standard error of the sample mean. (Negative values should be indicated by a minus sign. Round "standard error" to 2 decimal places.)...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT