对于以下数据集:
1 2 3 4 5
yes 181 93 141 186 198
No 14 11 11 23 21
这是数据集
data_frame(rating=1:5, No=c(167,82, 132, 182, 200), Yes=c(28, 22, 20, 27,
29))
0表示存在头痛,1表示没有头痛,1至5表示对药物的依从率。我如何计算这些数据的奇数比率?这是我的代码:
library (epiR)
epi.2by2(tbl_dow, method ='cohort.count', conf.level= 0.95)
但没有奏效。它有以下错误:
Error in data.frame(est = cmOR.p, lower = cmOR.l, upper = cmOR.u) :
arguments imply differing number of rows: 0, 1
答案 0 :(得分:0)
数据
df1 <- structure(list(X1 = c(181L, 14L), X2 = c(93L, 11L), X3 = c(141L,
11L), X4 = c(186L, 23L), X5 = c(198L, 21L)), .Names = c("X1",
"X2", "X3", "X4", "X5"), class = "data.frame", row.names = c("0",
"1"))
假设您想要每个类别的每个0/1的优势比,请使用apply:
apply(df1,2, FUN=function(x) x[[2]]/sum(x))
X1 X2 X3 X4 X5
0.07179487 0.10576923 0.07236842 0.11004785 0.09589041