gpt4 book ai didi

r - 使用点图可视化前/后匹配余额统计数据

转载 作者:行者123 更新时间:2023-12-04 10:02:19 25 4
gpt4 key购买 nike

为了直观地显示匹配过程前后的协变量平衡,我编写了以下代码:

library(lattice)
library(gridExtra)

StandBias.df= data.frame(
Category= rep(c("A", "B", "C", "D", "E", "F"), 2),
Groups = factor(c(rep("0", 6), rep("1", 6))),
Values = c(0.26, 0.4, 0.3, 0.21, 0.6, 0.14, 0.12, -0.04, -0.23, 0.08, 0.14, -0.27))

d1<-dotplot(Category ~Values, data = StandBias.df, groups = Groups,
main = "Standardized Mean Differences", col = c("black", "grey50"), pch=c(22,15), xlab=NULL,
key=list(text=list(c("Pre-Matching", "Post-Matching")),
points=list(col = c("black", "grey50"), pch=c(22,15)),
space="bottom", border=T))

Ttest.df = data.frame(
Category= rep(c("A", "B", "C", "D", "E", "F"), 2),
Groups = factor(c(rep("0", 6), rep("1", 6))),
Values = c(0.12, 0.02, 0.69, 0.19, 0.05, 0.01, 0.62, 0.77, 0.54, 0.24, 0.92, 0.51))


d2<-dotplot(Category ~Values, data = Ttest.df, groups = Groups,
main = "p-values", col = c("black", "grey50"), pch=c(22,15), xlab=NULL,
key=list(text=list(c("Pre-Matching", "Post-Matching")),
points=list(col = c("black", "grey50"), pch=c(22,15)),
space="bottom", border=T))

grid.arrange(d1,d2,nrow=1)

问题:
我想在 0.1 处为 p 值 (d2) 和 [-0.25; 0.25] 用于标准化平均值 (d1),因此我们有平衡/不平衡的视觉截止值。

这是我尝试过的:
对于 d1,我在最后一行之后添加了以下几行,即

...
space ="bottom", border=T),

panel=function(...){
panel.abline(v=0.25)
panel.abline(v=-0.25)}
)

修改后的代码生成一个带有请求的垂直线但没有数据点的图。

任何想法都非常受欢迎!

非常感谢。

最佳答案

你快到了。编写自定义面板时,您需要包含原始面板代码,否则不会绘制任何内容。

因此,面板函数应如下所示(将 panel.dotplot(...) 添加到您的代码中):

panel=function(...){
panel.dotplot(...)
panel.abline(v=0.25)
panel.abline(v=-0.25)
}

完整代码:
d1<-dotplot(Category ~Values, data = StandBias.df, groups = Groups,
main = "Standardized Mean Differences", col = c("black", "grey50"), pch=c(22,15), xlab=NULL,
key=list(text=list(c("Pre-Matching", "Post-Matching")),
points=list(col = c("black", "grey50"), pch=c(22,15)),
space="bottom", border=T),
panel=function(...){
panel.dotplot(...)
panel.abline(v=0.25)
panel.abline(v=-0.25)
}
)

Ttest.df = data.frame(
Category= rep(c("A", "B", "C", "D", "E", "F"), 2),
Groups = factor(c(rep("0", 6), rep("1", 6))),
Values = c(0.12, 0.02, 0.69, 0.19, 0.05, 0.01, 0.62, 0.77, 0.54, 0.24, 0.92, 0.51))


d2<-dotplot(Category ~Values, data = Ttest.df, groups = Groups,
main = "p-values", col = c("black", "grey50"), pch=c(22,15), xlab=NULL,
key=list(text=list(c("Pre-Matching", "Post-Matching")),
points=list(col = c("black", "grey50"), pch=c(22,15)),
space="bottom", border=T),
panel=function(...){
panel.dotplot(...)
panel.abline(v=0.25)
panel.abline(v=-0.25)
}
)

grid.arrange(d1,d2,nrow=1)

enter image description here

关于r - 使用点图可视化前/后匹配余额统计数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12246677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com