Learn R Programming

lessR (version 2.1.1)

sim.mean: Pedagogical Simulation of Sample Means

Description

Show a sequence of sample means and data, all simulated from the same normal population. Useful for developing an intuituion for developing an informal confidence interval, that is, specifying a likely range of values that contain the true population mean, but without a formal probability.

Usage

sim.mean(nrep, n, mu=0, sigma=1, ylim.bound=NULL, 
         show.title=TRUE, show.pop=FALSE, show.data=TRUE, 
         col.grid="grey90", pdf.out=FALSE, pause=FALSE)

Arguments

nrep
Number of samples, that is, repetitions of the experiment.
n
Size of each sample.
mu
Population mean.
sigma
Population standar deviation.
ylim.bound
Specify the maximum deviation of the mean in either direction for the extent of the vertical axis.
show.title
Place a title on the graph that contains the parameter values.
show.pop
Show the population values.
show.data
Show the data values on the text output.
col.grid
Color of the grid lines.
pdf.out
Generate a pdf file with an appropriate title.
pause
Build the graph and the text output confidence interval by confidence interval.

Details

Simulate random normal data and display the resulting sample means, both as text output and graphic output.

Examples

Run this code
# 8 samples, each with a sample size of 10
# mu=0, sigma=1, that is, sample from the standard normal
sim.mean(8, 10)

# 25 sample means with a sample size each of 100
# mu=100, sigma=15
# pause after each interval and show the data
sim.mean(25, 100, mu=100, sigma=15, show.data=FALSE)

Run the code above in your browser using DataLab