我正在尝试计算焦虑率风险因素暴露水平的比值比,对于以下数据产生的数据:
data<-structure(list(exposure = structure(c(3L, 1L, 2L), .Label = c("mild",
"severe", "unaffected"), class = "factor"), count_not_anxious = c(108,
337, 203), count_anxious = c(8, 48, 76)), .Names = c("exposure",
"count_not_anxious", "count_anxious"), row.names = c(NA, -3L), class = "data.frame")
看起来像:
exposure count_not_anxious count_anxious
1 unaffected 108 8
2 mild 337 48
3 severe 203 76
我专门为'epitools'包中的oddsratio()函数安排了数据,但oddsratio(data)
生成以下错误消息:
Error in nrow(x) : object 'x' not found
这是为什么?我是否误解了如何为此功能安排数据?
提前感谢任何建议!
答案 0 :(得分:1)
看起来你可以通过将数据从三列数据帧转换为两行矩阵来实现这一目标......
> dd <- as.matrix(data[,-1]) ## drop first column
> rownames(dd) <- data[,1]
> oddsratio(dd)
结果:
$data
count_not_anxious count_anxious Total
unaffected 108 8 116
mild 337 48 385
severe 203 76 279
Total 648 132 780
$measure
NA
odds ratio with 95% C.I. estimate lower upper
unaffected 1.000000 NA NA
mild 1.891296 0.911011 4.46757
severe 4.956366 2.432386 11.56705
$p.value
NA
two-sided midp.exact fisher.exact chi.square
unaffected NA NA NA
mild 9.001770e-02 1.289249e-01 9.505682e-02
severe 1.579224e-06 1.755645e-06 6.787096e-06
$correction
[1] FALSE
attr(,"method")
[1] "median-unbiased estimate & mid-p exact CI"