[英]Confidence Interval of Sample Means using R
My dataframe contains sampling means of 500 samples of size 100 each. 我的数据框包含500个样本,每个样本的大小为100。 Below is the snapshot.
下面是快照。 I need to calculate the confidence interval at 90/95/99 for mean.
我需要计算平均值为90/95/99的置信区间。
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. Means_df
是具有500行和1列的数据帧。 Therefore 因此
dim(Means_df)[2]
will give the value 1
. 将给出值
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]
. 通过使用
dim(Means_df)[1]
或更好的nrow(Means_df)
代替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. 对于任何单一平均值,例如14997,您都无法在不知道数据方差或标准差的情况下计算95%-CI。 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.
如果可以访问每个样本的标准偏差,则可以计算平均值的标准误,并由此轻松计算95%-CI。 Apparently, you lack the Information needed for the task.
显然,您缺少任务所需的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.