admin管理员组文章数量:1186278
The following mosaic plot code, using very toy data, indicates a significance value as part of the legend. This appears to be calculated using the same chi-sq approximation used in base R
, as confirmed by the relevant line of code (i.e. chisq.test()
).
Is there a relatively simple way of over-writing the chi-sq result in the legend with, say, a p-value derived from Fisher's Exact test (i.e. using fisher.test()
)? Or is there a possible option in the vcd
package?
tbl <- ( cbind(c(15,10),c(1,10)) )
dimnames(tbl) <- list(outcome = c("So fun!","Meh!"), adjustment = c("A","B"))
stats::chisq.test( tbl, correct = FALSE ) ## p-value = 0.004631
vcd::mosaic(tbl,
gp = shading_hcl,
split_vertical = TRUE,
main = "Toy Example")
stats::fisher.test( tbl ) ## p-value = 0.009091
The following mosaic plot code, using very toy data, indicates a significance value as part of the legend. This appears to be calculated using the same chi-sq approximation used in base R
, as confirmed by the relevant line of code (i.e. chisq.test()
).
Is there a relatively simple way of over-writing the chi-sq result in the legend with, say, a p-value derived from Fisher's Exact test (i.e. using fisher.test()
)? Or is there a possible option in the vcd
package?
tbl <- ( cbind(c(15,10),c(1,10)) )
dimnames(tbl) <- list(outcome = c("So fun!","Meh!"), adjustment = c("A","B"))
stats::chisq.test( tbl, correct = FALSE ) ## p-value = 0.004631
vcd::mosaic(tbl,
gp = shading_hcl,
split_vertical = TRUE,
main = "Toy Example")
stats::fisher.test( tbl ) ## p-value = 0.009091
Share
Improve this question
edited Jan 26 at 22:12
Big Old Dave
asked Jan 26 at 22:06
Big Old DaveBig Old Dave
3492 silver badges12 bronze badges
1 Answer
Reset to default 2One way is to manually add the Fisher exact test using the grid
package:
# Your code
tbl <- ( cbind(c(15,10),c(1,10)) )
dimnames(tbl) <- list(outcome = c("So fun!","Meh!"), adjustment = c("A","B"))
stats::chisq.test( tbl, correct = FALSE ) ## p-value = 0.004631
vcd::mosaic(tbl,
shade = FALSE,
split_vertical = TRUE,
main = "Toy Example")
stats::fisher.test( tbl ) ## p-value = 0.009091
# New code
fisher_p <- fisher.test(tbl)$p.value
grid::grid.text(
label = paste0("Fisher's Exact p = ", format.pval(fisher_p, digits = 3)),
x = grid::unit(0.5, "npc"),
y = grid::unit(0.1, "npc")
)
本文标签: rHow to display Fisher39s Exact rather than Chisq pvalue on vcdmosaic plot legendStack Overflow
版权声明:本文标题:r - How to display Fisher's Exact rather than Chi-sq p-value on vcd::mosaic plot legend - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738293729a2073285.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论