Learn R Programming

sjPlot (version 1.7)

sjp.lm: Plot linear models

Description

Depending on the type, this function plots beta coefficients (estimates) of linear regressions with confidence intervalls as dot plot (forest plot), model assumptions for linear models or slopes and scatter plots for each single coefficient. See type for details.

Usage

sjp.lm(fit, type = "lm", sort.est = TRUE, title = NULL,
  axisLabels.x = NULL, axisLabels.y = NULL, showAxisLabels.y = TRUE,
  axisTitle.x = "Estimates", axisLimits = NULL, geom.colors = "Set1",
  geom.size = 3, interceptLineType = 2, interceptLineColor = "grey70",
  breakTitleAt = 50, breakLabelsAt = 25, gridBreaksAt = NULL,
  coord.flip = TRUE, showValueLabels = TRUE, labelDigits = 2,
  showPValueLabels = TRUE, showModelSummary = TRUE, lineColor = "blue",
  showCI = TRUE, ciLevel = 0.95, pointAlpha = 0.2, pointColor = "black",
  showScatterPlot = TRUE, showLoess = FALSE, loessLineColor = "red",
  showLoessCI = FALSE, loessCiLevel = 0.95, useResiduals = FALSE,
  showOriginalModelOnly = TRUE, completeDiagnostic = FALSE,
  printPlot = TRUE)

Arguments

Value

Depending on the type, in most cases (insisibily) returns the ggplot-object with the complete plot (plot) as well as the data frame that was used for setting up the ggplot-object (df).

Details

  • Iftype = "lm"and fitted model only has one predictor, no forest plot is shown. Instead, a regression line with confidence interval (in blue) is plotted by default, and a loess-smoothed line without confidence interval (in red) can be added if parametershowLoessisTRUE.
  • Iftype = "pred", regression lines with confidence intervals for each single predictor of the fitted model are plotted, i.e. all predictors of the fitted model are extracted and each of them are fitted against the response variable.
  • Iftype = "ma"(i.e. checking model assumptions), please note that only three parameters are relevant:fit,completeDiagnosticandshowOriginalModelOnly. All other parameters are ignored.
  • Iftype = "vif", the Variance Inflation Factors (check for multicollinearity) are plotted. As a rule of thumb, values below 5 are considered as good and indicate no multicollinearity, values between 5 and 10 may be tolerable. Values greater than 10 are not acceptable and indicate multicollinearity between model's predictors.

See Also

Examples

Run this code
# --------------------------------------------------
# plotting estimates of linear models as forest plot
# --------------------------------------------------
# fit linear model
fit <- lm(airquality$Ozone ~ airquality$Wind + airquality$Temp + airquality$Solar.R)

# plot estimates with CI
sjp.lm(fit, gridBreaksAt = 2)

# plot estimates with CI without standardized beta-values
# and with narrower tick marks (because "gridBreaksAt" was not specified)
sjp.lm(fit)

# ---------------------------------------------------
# plotting regression line of linear model (done
# automatically if fitted model has only 1 predictor)
# ---------------------------------------------------
data(efc)
# fit model
fit <- lm(neg_c_7 ~ quol_5, data=efc)
# plot regression line
sjp.lm(fit)
# plot regression line with label strings
sjp.lm(fit,
       axisLabels.x = "Quality of life",
       axisLabels.y = "Burden of care",
       showLoess = TRUE)

# --------------------------------------------------
# plotting regression lines of each single predictor
# of a fitted model
# --------------------------------------------------
# fit model
fit <- lm(tot_sc_e ~ c12hour + e17age + e42dep, data=efc)

# reression line and scatter plot
sjp.lm(fit, type = "pred")

# reression line w/o scatter plot
sjp.lm(fit,
       type = "pred",
       showScatterPlot = FALSE)

# --------------------------
# plotting model assumptions
# --------------------------
sjp.lm(fit, type = "ma")

Run the code above in your browser using DataLab