Simulated sampling distribution of mean or other statistic
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.
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. (3rd edn, 2010) Data Analysis and Graphics Using R, 3rd edn, Sections 3.3 and 3.4
help(plotSampDist)
## 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[j-1] 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)) }
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.