# also see examples in ?effect
# plot predictorEffects
mod <- lm(prestige ~ education + log(income)*type + women, Prestige)
plot(predictorEffects(mod, ~ income), axes=list(grid=TRUE))
plot(predictorEffects(mod, ~ income), lines=list(multiline=TRUE),
axes=list(grid=TRUE))
plot(predictorEffects(mod, ~ type), lines=list(multiline=TRUE),
axes=list(grid=TRUE),
confint=list(style="bars"))
mod.cowles <- glm(volunteer ~ sex + neuroticism*extraversion,
data=Cowles, family=binomial)
eff.cowles <- allEffects(mod.cowles, xlevels=list(extraversion=seq(0, 24, 6)))
eff.cowles
as.data.frame(eff.cowles[[2]]) # neuroticism*extraversion interaction
plot(eff.cowles, 'sex', axes=list(grid=TRUE,
y=list(lab="Prob(Volunteer)"),
x=list(rotate=90)),
lines=list(lty=0))
plot(eff.cowles, 'neuroticism:extraversion',
axes=list(y=list(lab="Prob(Volunteer)",
ticks=list(at=c(.1,.25,.5,.75,.9)))))
plot(Effect(c("neuroticism", "extraversion"), mod.cowles,
se=list(type="Scheffe"),
xlevels=list(extraversion=seq(0, 24, 6))),
axes=list(y=list(lab="Prob(Volunteer)",
ticks=list(at=c(.1,.25,.5,.75,.9)))))
# \donttest{
# change color of the confidence bands to 'black' with .15 transparency
plot(eff.cowles, 'neuroticism:extraversion',
axes=list(y=list(lab="Prob(Volunteer)",
ticks=list(at=c(.1,.25,.5,.75,.9)))),
confint=list(col="red", alpha=.3))
plot(eff.cowles, 'neuroticism:extraversion',
lines=list(multiline=TRUE),
axes=list(y=list(lab="Prob(Volunteer)")),
lattice=list(key.args = list(x = 0.65, y = 0.99, corner = c(0, 1))))
# use probability scale in place of logit scale, all lines are black.
plot(eff.cowles, 'neuroticism:extraversion',
lines=list(multiline=TRUE, lty=1:8, col="black"),
axes=list(y=list(type="response", lab="Prob(Volunteer)")),
lattice=list(key.args = list(x = 0.65, y = 0.99, corner = c(0, 1))),
confint=list(style="bands"))
plot(effect('sex:neuroticism:extraversion', mod.cowles,
xlevels=list(extraversion=seq(0, 24, 6))),
lines=list(multiline=TRUE))
plot(effect('sex:neuroticism:extraversion', mod.cowles,
xlevels=list(extraversion=seq(0, 24, 6))),
lines=list(multiline=TRUE),
axes=list(y=list(type="response")),
confint=list(style="bands"),
lattice=list(key.args = list(x=0.75, y=0.75, corner=c(0, 0))))
# }
if (require(nnet)){
mod.beps <- multinom(vote ~ age + gender + economic.cond.national +
economic.cond.household + Blair + Hague + Kennedy +
Europe*political.knowledge, data=BEPS)
# \donttest{
plot(effect("Europe*political.knowledge", mod.beps,
xlevels=list(political.knowledge=0:3)))
# }
plot(effect("Europe*political.knowledge", mod.beps,
xlevels=list(political.knowledge=0:3),
fixed.predictors=list(given.values=c(gendermale=0.5))),
axes=list(y=list(style="stacked"), x=list(rug=FALSE), grid=TRUE),
lines=list(col=c("blue", "red", "orange")))
}
if (require(MASS)){
mod.wvs <- polr(poverty ~ gender + religion + degree + country*poly(age,3),
data=WVS)
plot(effect("country*poly(age, 3)", mod.wvs))
# \donttest{
plot(effect("country*poly(age, 3)", mod.wvs), lines=list(multiline=TRUE))
plot(effect("country*poly(age, 3)", mod.wvs),
axes=list(y=list(style="stacked")),
lines=list(col=c("gray75", "gray50", "gray25")))
plot(effect("country*poly(age, 3)", latent=TRUE, mod.wvs))
# }
}
mod.pres <- lm(prestige ~ log(income, 10) + poly(education, 3) + poly(women, 2),
data=Prestige)
eff.pres <- allEffects(mod.pres)
# \donttest{
plot(eff.pres)
plot(eff.pres[1:2])
# }
plot(eff.pres[1],
axes=list(x=list(income=list(transform=list(
trans=log10, inverse=function(x) 10^x),
ticks=list(at=c(1000, 2000, 5000, 10000, 20000))))))
mod <- lm(log(prestige) ~ income:type + education, data=Prestige)
p1 <- predictorEffects(mod, ~ income)
# log-scale for response
plot(p1, lines=list(multiline=TRUE))
# log-scale, with arithmetic tick marks
plot(p1, lines=list(multiline=TRUE),
axes=list(y=list(transform=list(trans=log, inverse = exp),
lab="prestige", type="rescale")))
# arithmetic scale and tick marks, with other arguments
plot(p1, lines=list(multiline=TRUE), grid=TRUE,
lattice=list(key.args=list(space="right", border=TRUE)),
axes=list(y=list(transform=exp, lab="prestige")))
Run the code above in your browser using DataLab