我在R中使用Grata包中的DRAW和COMPARE_Smooths函数来创建绘图,可视化来自两个逻辑游戏的平滑.我想编辑这些曲线图,以(1)包括原始数据;(2)具有Logistic变换的y轴,以便y轴值表示0-1之间的概率.使用这些函数有什么简单的方法可以做到这一点吗?
使用这些帖子(Gratia package: probability instead of log odds for plotting generalized additive model (GAM)和Plotting GAMM model results with package gratia)的建议,我可以成功地绘制概率图,而不是记录单个模型的赔率,但在使用DRAW on Compare_Smooths对象时,我不确定如何做到这一点.我也不确定如何用一个单独的模型来显示带有重新zoom 的y轴的曲线图上的原始数据.
此外,对于绘制单个模型,我知道添加"residuals=T"可以实现我想要的效果,但同样,使用Compare_Smooths不能做到这一点.
下面是一些示例代码
#simulate data
set.seed(9)
df1 <- data.frame(response=c(rep(0,500), rep(1,500)),
p1 = c(rnorm(500,100,5),rnorm(500,110,3)),
p2 = rnorm(1000,10,2))
df2 <- data.frame(response=sample(c(0,1),1000, replace = T),
p1 = rnorm(1000,80,10),
p2 = rnorm(1000,15,1))
#create models
m1 <- gam(response ~ s(p1,bs="cr") + s(p2, bs="cr"),
data = df1, family=binomial, method = "REML", select=T)
m2 <- gam(response ~ s(p1,bs="cr") + s(p2, bs="cr"),
data = df2, family=binomial, method = "REML", select=T)
#compare smooths
comp <- compare_smooths(m1,m2)
#visualize compared smooths
draw(comp)
#example of desired y-axis scaling for single model
#(two different methods, similar results)
draw(smooth_estimates(m1), fun = inv_link(m1))
draw(m1, constant = coef(m1)[1], fun = inv_link(m1))
#example of raw data on plot for single model
draw(m1, residuals=T)