# 09_04 R example - Generate N observations from Normal...

This preview shows pages 1–3. Sign up to view the full content.

Sheet1 Page 1 ## Generate N observations from Normal distribution with mean mu and standard deviation std N = 25 mu = 6 std = 2 datax = rnorm(N, mu, std) ## View the observations datax ## Sort the observations in ascending order sort(datax) ## Calculate the sample mean and variance meanx = mean(datax) meanx varx = var(datax) varx ## The "help" function help(sort) help(rnorm) ## Number of simulations S = 1000 ## Initialize the output meanall meanall = c(1:S) ## Simulations for (i in 1:S){ datax = rnorm(N, mu, std) meanall[i] = mean(datax)} ## View meanall meanall ## Histogram of meanall - should look bell shaped hist(meanall, breaks=20) ## Mean of meanall - should be close to mu mean(meanall) mu ## Variance of meanall - should be close to (std^2)/N var(meanall) (std^2)/N ########## ## Group 1 - Normal(mu1, std) ## Group 2 - Normal(mu2, std) N = 25 mu1 = 6 mu2 = 5

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Sheet1 Page 2 std = 2 data1 = rnorm(N, mu1, std) data2 = rnorm(N, mu2, std) ## Compute the sample mean of each group
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

09_04 R example - Generate N observations from Normal...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online