This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

plot(cars)

Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).

The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.

set.seed(1)
sample1= rnorm(n= 10, mean= 20, sd= 2)
sample1
##  [1] 18.74709 20.36729 18.32874 23.19056 20.65902 18.35906 20.97486 21.47665
##  [9] 21.15156 19.38922
#Simulate the generation of a sample of 10 values (n= 10) from a variable X that follows a normal distribution. 
round (mean (sample1), 3)
## [1] 20.264
#The mean of the sample1 (x bar) 
set.seed(2)
sample2= rnorm(n= 10, mean= 20, sd= 2)
sample2
##  [1] 18.20617 20.36970 23.17569 17.73925 19.83950 20.26484 21.41591 19.52060
##  [9] 23.96895 19.72243
#generate a second sample.
round (mean (sample2), 3)
## [1] 20.422
#The mean of the sample2 
sample_means= vector(mode= "numeric")

for(i in 1:100){
  set.seed(i)
  sample_means= c(sample_means, round (mean(rnorm(n= 10, mean= 20, sd= 2)), 2))
}
# generate 100 samples with 10 values, compute the sample mean, and then compare all 100 samples means to the population mean of 20.
sample_means2= vector(mode= "numeric")

for(i in 1:100){
  set.seed(i)
  sample_means2= c(sample_means2, round (mean(rnorm(n= 50, mean= 20, sd= 2)), 2))
}
#compute the sample mean, and compare all 100 samples means to the population mean of 20.
plot (sample_means, xlab= "Sample", ylab= "Xbar", yaxt = "n")
axis(2, at=seq(18,22,0.5), labels=seq(18,22,0.5))
abline(h= 20)

plot (sample_means2, xlab= "Sample", ylab= "Xbar", yaxt = "n")
axis(2, at=seq(18,22,0.5), labels=seq(18,22,0.5))
abline(h= 20)