Simulates the sample distribution of the specified statistic,
for samples of the size(s) specified in numINsamp
.
Additionally a with replacement) sample is drawn from the
specified population.
1 2 3  simulateSampDist(rpop = rnorm, numsamp = 100, numINsamp = c(4, 16),
FUN = mean, seed=NULL
)

rpop 
Either a function that generates random samples from the specified distribution, or a vector of values that define the population (i.e., an empirical distribution) 
numsamp 
Number of samples that should be taken. For close approximation of the asymptotic distribution (e.g., for the mean) this number should be large 
numINsamp 
Size(s) of each of the 
FUN 
Function to calculate the statistic whose sampling distribution is to be simulated 
seed 
Optional seed for random number generation 
List, with elements values
, numINsamp
and FUN
values 
Matrix, with dimensions 
numINsamp 
Input value of 
numsamp 
Input value of 
John Maindonald
Maindonald, J.H. and Braun, W.J. (2nd edn, 2006) Data Analysis and Graphics Using R, 2nd edn, Section 4.1
help(plotSampDist)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28  ## By default, sample from normal population
simAvs < simulateSampDist()
par(pty="s")
plotSampDist(simAvs)
## Sample from empirical distribution
simAvs < simulateSampDist(rpop=rivers)
plotSampDist(simAvs)
## The function is currently defined as
function(rpop=rnorm, numsamp=100, numINsamp=c(4,16), FUN=mean,
seed=NULL){
if(!is.null(seed))set.seed(seed)
funtxt < deparse(substitute(FUN))
nDists < length(numINsamp)+1
values < matrix(0, nrow=numsamp, ncol=nDists)
if(!is.function(rpop)) {
x < rpop
rpop < function(n)sample(x, n, replace=TRUE)
}
values[,1] < rpop(numsamp)
for(j in 2:nDists){
n < numINsamp[j1]
for(i in 1:numsamp)values[i, j] < FUN(rpop(n))
}
colnames(values) < paste("Size", c(1, numINsamp))
invisible(list(values=values, numINsamp=numINsamp, FUN=funtxt))
}

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
All documentation is copyright its authors; we didn't write any of that.