The data analyzed here is a sample of individuals collected on a monthly basis. What would be the best way to compute confidence intervals for the monthly sample means, in order to indicate the natural variability that can be expected from this value month after month?
Note: I do not wish to compute confidence intervals for the population mean, but for the sample means, assuming that the population mean is the same accross all months.
Here is an example dataset, where d$y
is the value of interest, and d$m
is the month:
d <- data.frame( y=rnorm(1000,6,6), m=factor(sample(seq(12),1000,replace=T)) )
I would like it to be of the form mean(d$y) + ub(d$m)
and mean(d$y) + ub(d$m)
. How to compute ub
and lb
?
I thought of doing the following for each month j
:
- the size of the sample for month
j
isn <- NROW(subset(d,m==j))
ub <- +qnorm(.975) * sd(d$y) / sqrt(n)
lb <- -qnorm(.975) * sd(d$y) / sqrt(n)
I'm afraid this is not statistically correct. What is the correct way to proceed?
Thanks.