Learn R Programming

learnPopGen (version 1.0.4)

clt: Illustrates the concept of the Central Limit Theorem

Description

The Central Limit Theorem tells us that when independent random variables are added together, the distribution of their sum tends towards a normal distribution, regardless of the shape of their individual distributions. This function attempts to illustrate this concept by allowing the user to visualize the sum of an arbitrary number of different independent random variables with different underlying distributions.

Usage

clt(nvar=1, nobs=1000, df=c("normal","uniform","exponential","binomial"),
		theta=NULL,	breaks="Sturges", show=c("sum","mean"))
	# S3 method for clt
print(x, ...)
	# S3 method for clt
plot(x, ...)

Arguments

nvar

number of random variables to sum (1 or more).

nobs

total number of observations (per random variable).

df

distribution functions of individual random variables to sum. These can be "normal", "uniform", "exponential", or "binomial".

theta

parameter of the distribution functions: variance in the case of df = "normal", maximum value in the case of "uniform" (the minimum value will be assumed to be 0), rate in the case of "exponential".

breaks

breaks (see hist).

show

whether to show the row-wise sum of the independent random variables (show="sum"), or their mean (show="mean").

x

object of class "clt" for print and plot methods.

...

optional arguments for print and plot methods.

Value

Creates a plot showing the observation-wise distribution of the sum or average of the independent random variables.

The distribution of the observation-wise sum or average and the underlying data are also returned invisibly to the user in the form of an object of class "clt". This object can in turn be printed or re-plotted using custom print and plot methods. (See examples.)

Details

The central limit theorem (CLT) establishes that when independent random variables are added together their (normalized) sum will tend towards a normal distribution, regardless of the distribution of the original random variables. That is to say if we were to generate a set of nvar (say) independent, uniform, random variables, normalize each one to have the same variance, and then sum or average the variables by observation, this sum or average will tend towards a normal distribution as the number of random variables (nvar in this function) is increased.

See Also

phenotype.freq

Examples

Run this code
# NOT RUN {
	clt(nvar=1,df="exponential")
	clt(nvar=10,df="exponential")
	object<-clt(nvar=40,df="exponential")
	print(object)
	plot(object)
# }

Run the code above in your browser using DataLab