Learn R Programming

lessR (version 2.6)

simMeans: Pedagogical Simulation of Sample Means over Repeated Samples

Description

Show a sequence of sample means and data, all simulated from the same normal population. Useful for developing an intuition 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

simMeans(ns, n, mu=0, sigma=1, ylim.bound=NULL, 
         show.title=TRUE, show.data=TRUE, max.data=10, 
         col.grid="grey90", pause=FALSE,
         sort=NULL, set.mu=FALSE, digits.d=2,
         main=NULL, pdf.file=NULL, pdf.width=5, pdf.height=5)

Arguments

ns
Number of samples, that is, repetitions of the experiment.
n
Size of each sample.
mu
Population mean.
sigma
Population standard 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.data
Show the data values on the text output.
max.data
Maximum number of data values per sample on the text output.
col.grid
Color of the grid lines.
pause
Build the graph and the text output sample by sample.
sort
Sort the output by the means in ascending order. By default is TRUE unless se.mu or pause is TRUE
set.mu
Have the program randomly set mu and sigma, usually to guess the correct value.
digits.d
Sort the output by the means in ascending order.
main
Title of graph.
pdf.file
Name of the pdf file to which graphics are redirected.
pdf.width
Width of the pdf file in inches.
pdf.height
Height of the pdf file in inches.

Details

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

If pause=TRUE, then the true population values are not revealed as the simulation progresses. These values are saved in the user's workspace and can be revealed by entering their names at the user prompt, mu and sigma.

Examples

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

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

Run the code above in your browser using DataLab