Leo N.

asked • 04/25/21

Using R script functions generate random samples and calculate sample means. Be sure to solve all 3 parts of this problem.

Please show the R script coding/steps to solve this. Please do all 3 parts of this question!!! Thanks in advance!!! :)


Assume that we have a normal population with a mean of 10 and a variance of 22, i.e., X∼N(10,22). In R, consider using the rnorm()function that is used to draw random values from a normal distribution (so it starts with ‘r’). It can be implemented as rnorm(n, mean, sd) where n is the number of random values to draw, and mean and sd are the mean and the standard deviation of the normal distribution from which random values are drawn.


Part 1: By using the rnorm()function, generate a random sample of size 1500 from the population and draw a histogram of the randomly drawn values.


Part 2: From the population, draw 50 random samples of size 30. Calculate the sample mean of each random sample generating 50 sample means from 50 random samples. Draw a histogram of the sample means.


Part 3: Compare the distributions of the population and the sample mean in terms of location and variability (by comparing the histograms). For this, calculate the mean and standard deviation of 1500 X’s in part 1 and the mean and standard deviation of 50 X’s in part 2. Determine if there is any significant difference in location or variability between the two distributions. If there is a difference, why do you see such a difference (think about the mathematical expressions)?

1 Expert Answer

By:

Leo N.

Thank you this is a homework assignment that I was never able to understand/solve and I wanted to understand before the final exam. Thanks!
Report

04/26/21

David B.

tutor
Thank you for your response, I hope my breakdown of the individual functions helped you understand the code. The only tricky thing is the loop. I find many current courses give examples but don't explain the logic behind the loops. Some teachers like to show off and give code that they don't break down. For example, the entire for loop could be done in one line (see below) , but I broke it down into individual lines so the reader could learn how to work within a loop. for (i in 1:25) x1<- c(x1,mean(sample(x,40, replace=TRUE)))
Report

04/26/21

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.