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.
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, ...)
number of random variables to sum (1 or more).
total number of observations (per random variable).
distribution functions of individual random variables to sum. These can be "normal"
, "uniform"
, "exponential"
, or "binomial"
.
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 (see hist
).
whether to show the row-wise sum of the independent random variables (show="sum"
), or their mean (show="mean"
).
object of class "clt"
for print
and plot
methods.
optional arguments for print
and plot
methods.
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.)
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.
# 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