开发者

Calculating standard deviation of samples with boostrapping in R

开发者 https://www.devze.com 2023-04-08 05:43 出处:网络
Imagine: I have sampled 10,000 humans and measured their height in cm, and drawn the distribution as follows:

Imagine: I have sampled 10,000 humans and measured their height in cm, and drawn the distribution as follows:

# Generate sample data
sampleSize = 10000
sampleData = round(rnorm(n=sampleSize, mean=175, sd=14))

# Draw histogram of sample
h = hist(sampleData, breaks=max(sampleData)-min(sampleData))

######################################################################
# Calculate the mean of the measurement
meanMeasure = mean(sampleData)
meanMeasure
abline(v=meanMeasure, col="red")

# Calculate the standard deviation of the measurement
sdMeasure = sd(sampleData)
sdMeasure
rect(
    xleft=meanMeasure-sdMeasure,
    ybottom=min(h$counts),
    xright=meanMeasure+sdMeasure,
    ytop=max(h$counts),
    col="#0000ff22"
)

Now I want to estimate how large the standardDeviation is for each measured body height. I thought that bootstrapping my original dataset would be a good method, i.e sampling body sizes from my original dataset with replacement.

Is this a good method? How can I perform this analysis in R (e.g. sta开发者_JAVA百科ndard deviation for each height in a bootstrap analysis with 1000 cycles)?


If you measure each individual only once there is no way of obtaining the standard deviation "for each measured body height". Bootstrapping can only be used if you have more than one datapoint for which you want to obtain an estimate.

For obtaining the standard deviation "for each measured body height" , each body height would have to be measured more than once.

If you, however, want to obtain an bootstrapped estimate of the standard deviation of you overall sample, then the other two answers apply.

Furthermore, this question would be better suited on crossvalidated.com.


It's entirely unnecessary to use bootstrapping for that purpose when your sample size is so large. If you wanted to know the extent of plausible variation in the standard deviation in samples of only 100 or 200 or maybe even 500 individuals, then bootstrapping would be informative. But with 10,000 individuals the bootstrap variation in the standard deviation is going to be very, very small.


Bootstrapping is usually employed to calculate the variance of an estimator, in your case, the sample mean height. When you're just looking to find the variance of the heights of people, you don't need to do a bootstrap.

Why do we bootstrap? Because for our one sample we only have one sample mean. So we need many samples to get many sample means to calculate the variance of that estimator. Bootstrapping is a way to get many pseudo-samples when we only have one.

In your case, we already have many individual observations of heights, so we don't need any more---we can just calculate the variance directly based upon our "real" observations.

0

精彩评论

暂无评论...
验证码 换一张
取 消