
Last chance! 50% off unlimited learning
Sale ends in
### Model specification ###
data("creditdata")
## Treat ordered factors as unordered factors.
options(contrasts=c("contr.treatment","contr.treatment"))
model.cd <- glm(credit ~ amount + I(amount^2) + age + duration*teleph + housing,
family=binomial, data=creditdata)
if (FALSE) {
### Basic usage ###
## RStudio users may need to change the graphic device, see details.
options(device = "x11")
## Using defaults
fxInteractive(model.cd)
## Switch text output to LaTeX
fxInteractive(model.cd, latex2console = TRUE)
## Continental European number format in LaTeX output
fxInteractive(model.cd, latex2console = TRUE, decimal.mark = ",", big.mark = ".")
## Save plot as PDF to current working directory when 'Snapshot' is clicked
fxInteractive(model.cd, snapshot.plot = TRUE)
## Change color scheme and line types
fxInteractive(model.cd, col = rep(c(2,4),each = 3), lty = c(1,3,5))
## Change separation characters
fxInteractive(model.cd, factor.sep = "-", level.sep = ">")
## Suppress legend
fxInteractive(model.cd, legend.add = FALSE)
## Suppress rug plot
fxInteractive(model.cd, rug.ticksize = NA)
## Set initial values of metric covatiates
fxInteractive(model.cd, initial.values = list(amount=5000, age=30, duration=24))
## Preselect covariate, plot type and groups
fxInteractive(model.cd, preselect.var = "duration", preselect.type = "response",
preselect.groups = c(2,5))
## Preselect covariate and plot type and change axis annotations
fxInteractive(model.cd, preselect.var = "duration", preselect.type = "response",
xlab = "duration (months)", ylab = "probability of credit default")
### Visualization of statistical concepts ###
## Nonparametric effect
require("splines")
model.cd.bs <- glm(credit ~ bs(amount) + age + duration*teleph + housing,
family = binomial, data = creditdata)
fxInteractive(model.cd.bs, preselect.var = "amount")
## Generalized additive model
require("mgcv")
model.cd.mgcv <- gam(credit ~ s(amount) + age + duration*teleph + housing,
family = binomial, data = creditdata)
fxInteractive(model.cd.mgcv)
## Interaction effect (directly)
fxInteractive(model.cd, preselect.var = "duration")
## Interaction effect (indirectly)
fxInteractive(model.cd, preselect.var = "age")
# manipulate slider for 'duration'
## Quasi-complete separation
# example from Kleiber, Zeileis (2008), p. 130ff
require("AER")
data("MurderRates")
model.mr <- glm(I(executions > 0) ~ time + income + noncauc + lfp + southern,
family = binomial, data = MurderRates)
fxInteractive(model.mr, preselect.var = "income", preselect.type = "response")
### Additional examples ###
## Customize device for printing
fxInteractive(model.cd,
dev.width = 6,
dev.width.legend = 4,
dev.height = 6,
dev.pointsize = 6,
col = c("darkred","red","salmon","darkblue","blue","lightblue"),
legend.width.factor = 1.1,
vline.actual = FALSE,
snapshot.plot = TRUE,
graphics.filename = "creddefault-termplot",
mar = c(2.5,2.5,1,1)+0.1,
mgp = c(1.5,0.5,0),
tcl = -0.3)
## Save predefined plot automatically
fxInteractive(model.cd,
initial.values = list(amount=5000, duration=24, age=30),
preselect.var = "duration",
preselect.type = "link",
autosave.plot = TRUE,
graphics.filename = "fig-creddefault-duration-link",
legend.width.factor = 1.05)
## Modifications for models with many groups
# Increase space for legend and squeeze panel controls
model.cd.moregroups <- glm(credit ~ amount + I(amount^2) + age
+ duration*teleph + housing + job, family = binomial, data = creditdata)
fxInteractive(model.cd.moregroups,
dev.width.legend = 9,
legend.cex = 1,
box.type.height = 90,
box.group.character.width = 6,
box.group.line.height = 25,
dist.obj.height = 2)
# Squeeze legend and panel controls
model.cd.manygroups <- glm(credit ~ amount + I(amount^2) + age
+ duration*teleph + housing + intuse, family = binomial, data = creditdata)
fxInteractive(model.cd.manygroups,
dev.width.legend = 6,
legend.cex = 0.54,
box.type.height = 90,
box.group.character.width = 6,
box.group.line.height = 25,
dist.obj.height = 2)
# Note that checkbox for groups grows beyond screen
# Preselect groups and specifiy color and line types directly
model.cd.manygroups <- glm(credit ~ amount + I(amount^2) + age
+ duration*teleph + housing + intuse, family = binomial, data = creditdata)
index.groups <- c(1,11,21,31,41,51)
vec.col <- NULL
vec.col[index.groups] <- c(1:6)
vec.lty <- NULL
vec.lty[index.groups] <- rep(c(1,2), each = 3)
fxInteractive(model.cd.manygroups,
preselect.var = "amount",
preselect.groups = index.groups,
col = vec.col,
lty = vec.lty)
}
Run the code above in your browser using DataLab