Simulations of distributions

The central limit theorem is perhaps the most important concept in statistics. For any distribution with finite mean and standard deviation, samples taken from that population will tend towards a normal distribution around the mean of the population as sample size increases. Furthermore, as sample size increases, the variation of the sample means will decrease.

The following examples use the R stats program to show this graphically. The first example uses a uniform (rectangular) distribution. An example of this case is of a single die with the values of 1-6. The second example is of two dice with totals ranging from 2-12. Notice that although one die produces a rectangular distribution, two dice show a distribution peaking at 7. The next set of examples show the distribution of sample means for samples of size 1 .. 32 taken from a rectangular distribution.

This figure was produced using the following R code.

#distributions of a single six sided die
#generate a uniform random distribution from min to max
numcases
#end of first demo

Distribution of two dice

Distribution of two dice. The sum of two dice is not rectangular, but is peaked at the middle (hint, how many ways can you get a 2, a 3, ... a 7, .. 12.).
The following R code produced this figure.

#generate a uniform random distribution from min to max for numcases samples of size 2
numcases
#end of second demo

Samples from a continuous uniform random distribution

We can generalize the case of 1 or two dice to the case of samples of varying size taken from a continuous distribution ranging from 0-1. This next simulation shows the distribution of samples of sizes 1, 2, 4, ... 32 taken from a uniform distribution. Note, for each sample, we are finding the average value of the sample, rather than the sum as we were doing in the case of the dice.

##show distribution of sample means of varying size samples
numcases
#do the same thing, but this time show a boxplot
numcases
#Demonstration of the effect of sample size on distributions
#each sample is then replicated numcases times
filename
Some simple measures of central tendency

More on the psych package

The psych package is a work in progress. The current released version is 1.3.2. Updates are added sporadically, but usually at least once a quarter. The development version is always available at the pmc repository.

If you want to help us develop our understanding of personality, please take our test at SAPA Project.