简体   繁体   中英

Confidence Interval of Sample Means using R

My dataframe contains sampling means of 500 samples of size 100 each. Below is the snapshot. I need to calculate the confidence interval at 90/95/99 for mean.

head(Means_df)
  Means
1 14997
2 11655
3 12471
4 12527
5 13810
6 13099

I am using the below code but only getting the confidence interval for one row only. Can anyone help me with the code?

tint <- matrix(NA, nrow = dim(Means_df)[2], ncol = 2)
for (i in 1:dim(Means_df)[2]) {
  temp <- t.test(Means_df[, i], conf.level = 0.9)
  tint[i, ] <- temp$conf.int
}
colnames(tint) <- c("lcl", "ucl")

Means_df is a data frame with 500 rows and 1 column. Therefore

dim(Means_df)[2]

will give the value 1 .

Which is why you only get one value.

Solve the problem by using dim(Means_df)[1] or even better nrow(Means_df) instead of dim(Means_df)[2] .

For any single mean, eg 14997, you can not compute a 95%-CI without knowing the variance or the standard deviation of the data, the mean was computed from. If you have access to the standard deviation of each sample, you can than compute the standard error of the mean and with that, easily the 95%-CI. Apparently, you lack the Information needed for the task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM