### Model specification ###
data("munichrent03")
## Treat ordered factors as unordered factors.
options(contrasts=c("contr.treatment","contr.treatment"))
model.rent <- lm(rent ~ yearc + I(yearc^2) + rooms + area*location + upkitchen,
data=munichrent03)
if (FALSE) {
### Basic usage ###
## RStudio users may need to change the graphic device, see details.
options(device = "x11")
## Using defaults
fxInteractive(model.rent)
## Switch text output to LaTeX
fxInteractive(model.rent, latex2console = TRUE)
## Continental European number format in LaTeX output
fxInteractive(model.rent, latex2console = TRUE, xtable.decimal.mark = ",", xtable.big.mark = ".")
## Save plot as PDF to current working directory when 'Snapshot' is clicked
fxInteractive(model.rent, snapshot.plot = TRUE)
## Change color scheme and line types
fxInteractive(model.rent, col = rep(c(1,2,4),each = 2), lty = c(1,5))
## Change separation characters
fxInteractive(model.rent, factor.sep = "-", level.sep = ">")
## Suppress legend
fxInteractive(model.rent, legend.add = FALSE)
## Suppress rug plot
fxInteractive(model.rent, rug.ticksize = NA)
## Set initial values of metric covatiates
fxInteractive(model.rent, initial.values = list(yearc=1990, rooms=3, area=80))
## Preselect covariate, plot type and groups
fxInteractive(model.rent, preselect.var = "yearc", preselect.type = "marginal",
preselect.groups = c(2,4,6))
## Preselect covariate and plot type and change axis annotations
fxInteractive(model.rent, preselect.var = "yearc", preselect.type = "effect",
xlab = "year of construction", ylab = "net rent (EUR)")
### Visualization of statistical concepts ###
## Nonlinear effect
fxInteractive(model.rent, preselect.var = "yearc")
## Nonparametric effect
require("splines")
model.rent.bs <- lm(rent ~ bs(yearc) + rooms + area*location + upkitchen,
data = munichrent03)
model.rent.bs$data <- munichrent03
fxInteractive(model.rent.bs, preselect.var = "yearc")
# Note that the data must be attached to the fitted-model object
# afterwards, see section 7 of the vignette for details.
## Interaction effect (directly)
fxInteractive(model.rent, preselect.var = "area")
## Interaction effect (indirectly)
fxInteractive(model.rent, preselect.var = "yearc")
# manipulate slider for 'area'
### Additional examples ###
## Customize device for printing
fxInteractive(model.rent,
dev.width = 6,
dev.width.legend = 4,
dev.height = 6,
dev.pointsize = 6,
col = c("red","darkred","blue","darkblue","green","darkgreen"),
legend.width.factor = 1.1,
vline.actual = FALSE,
snapshot.plot = TRUE,
graphics.filename = "munichrent-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.rent,
initial.values = list(yearc=1990, rooms=3, area=80),
preselect.var = "area",
preselect.type = "marginal",
autosave.plot = TRUE,
graphics.filename = "fig-rent-area-marg",
legend.width.factor = 1.05)
## Modifications for models with many groups
# Increase space for legend and squeeze panel controls
model.rent.moregroups <- lm(rent ~ yearc + I(yearc^2) + rooms + area*location
+ upkitchen + bathtile, data = munichrent03)
fxInteractive(model.rent.moregroups,
dev.width.legend = 9,
legend.cex = 1,
box.type.height = 65,
box.group.character.width = 6,
box.group.line.height = 28,
dist.obj.height = 2)
# Squeeze legend and panel controls
model.rent.manygroups <- lm(rent ~ yearc + I(yearc^2) + rooms + area
+ district + upkitchen, data = munichrent03)
fxInteractive(model.rent.manygroups,
dev.width.legend = 6,
legend.cex = 0.65,
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.rent.manygroups <- lm(rent ~ yearc + I(yearc^2) + rooms + area
+ district + upkitchen, data = munichrent03)
index.groups <- c(3,4,17,18,49,50)
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.rent.manygroups,
preselect.var = "area",
preselect.groups = index.groups,
col = vec.col,
lty = vec.lty)
}
Run the code above in your browser using DataLab