在生成具有三个变量的表后,如下所示:
salary <- array(
c(38, 12, 102, 141, 12, 9, 136, 383),
dim=c(2, 2, 2),
dimnames=list(exposure = c("exposed", "not"),
disease = c("case", "control"),
salary = c("<1000", ">=1000"))
)
salary
, , salary = <1000
disease
exposure case control
exposed 38 102
not 12 141
, , salary = >=1000
disease
exposure case control
exposed 12 136
not 9 383
该vcd
软件包允许创建这样的马赛克图:
mosaic(salary, shade = T)
其中表面积与单元格中的计数成正比,颜色对应于标准化的 Pearson 残差。
问题是如何计算和提取预期计数?
我知道我可以产生这样的边距:
addmargins(salary)
, , salary = <1000
disease
exposure case control Sum
exposed 38 102 140
not 12 141 153
Sum 50 243 293
, , salary = >=1000
disease
exposure case control Sum
exposed 12 136 148
not 9 383 392
Sum 21 519 540
, , salary = Sum
disease
exposure case control Sum
exposed 50 238 288
not 21 524 545
Sum 71 762 833
如果它是一个 2 x 2 列联表,我会用它chisq.test(x)$expected
来查看预期值,但我不知道如何在 3 路列联表中处理它。