私の問題
およびmcnemar.test
_ _ ggplot2
_ggalluvial
私のテストデータ:
df <- data.frame(timepoint=rep(0:2, each=10),response=c("A","A","A","A","A","A","A","A","B","B","A","A","A","A","A","A","A","B","B","B","A","B","B","B","B","B","A","A","B","B"),variable=rep(c("var1","var2"),each=5, 3), subject=rep(1:5,6))
df$timepoint <- factor(df$timepoint, level=c(1,0,2), labels=c("method_A","baseline","method_B"))
df %>% add_count(timepoint,variable,response) %>% add_count(timepoint,variable) %>% mutate(freq=n/nn*100) %>% mutate(total=1) -> df
私のプロット:
ggplot(df,
aes(x = timepoint, stratum = response, alluvium = subject,
y = total,
fill = response, label = paste(freq,"%") )) +
geom_flow() +
geom_stratum(alpha = .5) +
geom_text(stat = "stratum", size = 3) +
theme(legend.position = "none") +
facet_grid(.~variable)
私に与えます:
私が取得しようとしているもの:
mcnemar.test
ここで、ベースラインと方法 A および B の間の従属比率を比較する (p 値など)の結果を示す括弧を追加したいと思います。
私は(http://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots/76-add-p-values-and-significance-levels-to-ggplots/)stat_compare_means
からのようなものについて考えました. ただし、平均を比較する方法のみをカバーしていますが、どのように比率を比較できますか? 私の実際のデータ セットは非常に大きいため、テスト結果を自動的に ggplot に追加する方法を見つけようとしています。ggpubr
stat_compare_means