【发布时间】:2020-10-23 20:42:24
【问题描述】:
我有一组数据,除了找到每个组的列的平均值之外,我还想找到一个 置信区间。样本数据如下:
id <- c(1101:1108)
age <- c(12,15,14,12,3,1,2,5)
length <- c(52,62,63,58,79,45,65,25)
result <- c("TRUE","FALSE","TRUE","FALSE","TRUE","FALSE","TRUE","FALSE")
data<-data.frame(id, age, length, result)
id age length result
1 1101 12 52 TRUE
2 1102 15 62 FALSE
3 1103 14 63 TRUE
4 1104 12 58 FALSE
5 1105 3 79 TRUE
6 1106 1 45 FALSE
7 1107 2 65 TRUE
8 1108 5 25 FALSE
我要做的是计算每组结果的长度参数的平均值和 0.95 置信区间,所以我使用了下面的代码:
g <- data %>% select(length,result) %>% group_by(result) %>% summarise(Ave_length=mean(length, na.rm=TRUE))
为了计算每个组的置信区间,我使用了gmodels 包中的以下函数
ci(data$length[data$result=="TRUE"], 0.95)
ci(data$length[data$result=="TRUE"], 0.95)
但是,我得到的是一条警告消息“警告消息: 在 ci.numeric(data$length[data$result == "TRUE"], 0.95) 中: 没有类或未知类。使用默认计算。”
您对我如何解决这个问题有什么建议吗?或者有没有其他函数可以用来计算置信区间
【问题讨论】:
-
这是一条警告消息,而不是错误
-
@akrun 谢谢,我编辑了我的问题,仍然有这个警告,我可以相信它产生的结果吗?
-
只是
ci的方法不同,即methods('ci')找不到数据的class,所以使用ci.numeric的默认选项
标签: r group-by confidence-interval