# Standard error of the sampling distribution and standard deviation

I wanted to verify that the standard error of the sampling distribution = $\sigma/\sqrt{n}$

USAccDeaths

I used this above dataset from R Datasets Package

population parameters

mean(USAccDeaths)
sd(USAccDeaths)

Creating a Sampling Distribution

n=40 #Sample size.
nruns=10000 # Number of samples to draw.
store=double(nruns)
for (run in 1:nruns){
samp=sample(USAccDeaths,n)
store[run]=mean(samp)}

My question is shouldn't

sd(USAccDeaths)/sqrt(n) be approximately equal to sd(store)

when I run this I get values that are completely different

• what is the procedure you adopted for sd(store) ? Also ondicate your summary of results?
– user10619
Commented Dec 4, 2017 at 0:27
• @subhashc.davar, I considered sd(store) to be the standard error of the sampling distribution results- sd(store) [1] 101.5435 and sd(USAccDeaths)/sqrt(n) [1] 151.434 Commented Dec 4, 2017 at 0:55
• How do you compute sd (store)
– user10619
Commented Dec 4, 2017 at 2:36
• explain briefly background of your problem and the data you are worlking on.
– user10619
Commented Dec 4, 2017 at 5:34

## Sampling with replacement

Try this

n_samples=1000
n_sample=40
my.samples<-sample(USAccDeaths,n_sample*n_samples,replace=TRUE)
dim(my.samples)<-c(n_sample,n_samples)
store<-apply(my.samples,2,mean)
sd(store)

151.0806

sd(USAccDeaths)/sqrt(n_sample)

151.434

## Sampling without replacement

I you do not sample with replacement, than you should use the following finite correction $$\sigma_{\bar{X}}=\sqrt{\frac{N-n}{n-1}}\frac{\sigma}{\sqrt{n}}$$

As you can see

sqrt((length(USAccDeaths)-n_sample)/(length(USAccDeaths)-1))*sd(USAccDeaths)/sqrt(n_sample)

101.6645

Which matches the result of your code, where you sampled without replacement

for(run in 1:n_samples){store[run]=mean(sample(USAccDeaths,n_sample))}
sd(store)

101.5435

• should I do do this then samp=sample(USAccDeaths,n,nruns) Commented Dec 4, 2017 at 3:19
• I added an explanation of why your approach produced an error. I also added how to correct your approach, to produce the same result as mine. You sampled without replacement, while assuming that you sampled with replacement. Please see the edited code and tell me if you understand now. Commented Dec 4, 2017 at 3:55
• yes, I was able to verify using my code that sd(store) =sd(USAccDeaths)/sqrt(n) when samp=sample(USAccDeaths,n,replace=TRUE). I guess when I was sampling without replacement, I was getting a standard error consistently smaller than sd(USAccDeaths)/sqrt(n) Commented Dec 4, 2017 at 17:03