Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Please let me know my mistake. I expected bootstrapping a standard normal data produces a mean of zero and standard deviation of 1, but my example does not. rm(list=ls())

Create random data with a mean of zero and standard deviation of one

V1 <- rnorm(9, mean=0, sd=1); V2 <- rnorm(9, mean=0, sd=1); V3 <- rnorm(9, mean=0, sd=1)
V4 <- rnorm(9, mean=0, sd=1); V5 <- rnorm(9, mean=0, sd=1); V6 <- rnorm(9, mean=0, sd=1)
V7 <- rnorm(9, mean=0, sd=1); V8 <- rnorm(9, mean=0, sd=1)

charDataDiff <-,V2,V3,V4,V5,V6,V7,V8));charDataDiff

rename the columns

colnames(charDataDiff) <- c("s380","s390","s400","s410","s420","s430","s440","s450"); charDataDiff

patchId      <- c("C", "B", "A", "A", "B", "C", "A", "B", "C"); patchId

provide an ordering variable

idColor      <- c("C", "B", "A")

Put all the pieces together to create the data

charDataDiff <-,charDataDiff); charDataDiff

Split the data by patchId

patchSpectrumBiasSplit <- split(charDataDiff, charDataDiff$patchId)

Order the data by idColor

patchSpectrumBiasOrdered <- patchSpectrumBiasSplit[idColor]

Remove the first column

patchSpectrumBias <- lapply(patchSpectrumBiasOrdered, "[", 2:9)


sampleOne   <- function(x) x[sample(seq_len(nrow(x)), replace = TRUE), ]
sampleBoot  <- function(x, n) replicate(n, sampleOne(x), simplify = FALSE)
applyMedian <- function(l), lapply(l, apply, 2, median))
k <- lapply(lapply(patchSpectrumBias, sampleBoot, n = 1000), applyMedian)

Calculate the mean, I expected the mean to be zero following the law of large numbers.

bootMeansBias <-, lapply(k, apply, 2, mean));bootMeansBias

Calculate the standard deviation, I expected the standard deviation to be one

standardError <-, lapply(k, apply, 2, sd));standardError
share|improve this question
Crossposted at… – MattBagg Nov 23 '12 at 18:06
@Matt The cross-post now has been closed and at least one statistically interesting answer has been offered here, so this looks like the right place for this thread to remain. Thanks for flagging it! – whuber Nov 23 '12 at 20:54

You could never expect the mean to be exactly 0 if you were using the law of large numbers. You're not using large numbers in your sample, only your bootstrap. Your bootstrap will build up a representation out of the sample. You're just highlighting a problem in bootstrapping, that the results you get depend on the sample. So, a sample of 9 is very unlikely to have a mean of 0 and can deviate quite a bit from it. A sample of 3 is even worse. Bootstrapping won't fix this.

share|improve this answer

Thank all, I modified my code and realized my mistake. the new code is as follows:

n <-2000 

Create random data with a mean of zero and standard deviation of one

a <- lapply(1:8, function(x)cbind(rnorm(n)))
b <-,a ))

rename the columns

names(b) <- c("s380","s390","s400","s410","s420","s430","s440","s450")

Create a second random data

c <- lapply(1:8, function(x)cbind(rnorm(n)))

rename the columns

d <-, c))

names(d) <- c("s380","s390","s400","s410","s420","s430","s440","s450"); str(d)

Create a list of the above data

e <- list(b,d)


sampleOne   <- function(x) x[sample(seq_len(nrow(x)), replace = TRUE), ]
sampleBoot  <- function(x, nn) replicate(n, sampleOne(x), simplify = FALSE)
applyMean <- function(l), lapply(l, apply, 2, mean))
k <- lapply(lapply(e, sampleBoot, nn = 100), applyMean)

calculate the mean, it is almost zero

bootMeansBias <- round(, lapply(k, apply, 2, mean)),3); bootMeansBias

calculate the standard deviation, it is almost 1

standardError <- round(, lapply(k, apply, 2, sd)),3);standardError
standardDeviation <- standardError*sqrt(n); standardDeviation

Thank you all

Ragy Isaac

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.