Scaling axis in a GLM plot with library “effects”

♀尐吖头ヾ 提交于 2020-01-03 03:15:28

问题


i'm a biology graduate trying to plot my GLMM using R and the library "effects".

I'm trying to plot my model using this string, and it works perfectly.

library(effects) 
mod.cowles <- glmer((preshunt)~road+(1|area),family=binomial)
eff.cowles <- allEffects(mod.cowles) 
plot(eff.cowles, main= FALSE,rug=FALSE,colors=1, band.colors=3, col=1)

My problem is that i need the axis with the same lims, starting from 0 to 0.5 values and with the same scaling. I'm trying doing that by adding them in the script

mod.cowles <- glmer((preshunt)~road+(1|area),family=binomial)
eff.cowles <- allEffects(mod.cowles) 
plot(eff.cowles, main= FALSE,rug=FALSE,colors=1, band.colors=3, col=1, xlim=c(0,0.5), ylim=c(0,0.5))

But then R just decide to give me an empty graph, not even with correct axis.

Can anybody give me a hint on how to solve this problem?


回答1:


I wrote to the author of the function John Fox and got a reply that the values on y are actually on logit scale (:facepalm:, it's a logistic regression!). It's fairly trivial to convert "raw" values to logit and back.

Here's a reproducible example:

library(effects) 
library(lme4)

mod.cowles <- glmer(volunteer ~ extraversion + (1|sex), 
                    family=binomial, data = Cowles) # doesn't converge
eff.cowles <- allEffects(mod.cowles) 

plot(eff.cowles, main= FALSE,rug=FALSE,colors=1, band.colors=3, col=1, 
     xlim=c(0, 20), ylim = qlogis(c(0.1, 0.6))) # also log(c(.1, .6)/c(.6, .1))

You can set ylim = qlogis(c(0.01, 0.99)) and you'll get the below plot. Mind that this is on logit scale where 0 and 1 are (-)Inf.

qlogis(seq(0, 1, by = 0.1))
[1] -Inf -2.1972246 -1.3862944 -0.8472979 -0.4054651 0.0000000
    0.4054651 0.8472979 1.3862944 2.1972246 Inf




回答2:


Even though this post is quite old, this might still be of help or for other people experiencing the same problem. I came across the same trouble with an empty graph & wrong axis scale and figured it has to do with the version of R or rather some packages. Changing to a newer version solved the problem.



来源:https://stackoverflow.com/questions/35697833/scaling-axis-in-a-glm-plot-with-library-effects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!