ggResidpanel is an R package for creating panels of diagnostic plots for a model using ggplot2 and interactive versions of the plots using plotly.
The code below shows how ggResidpanel can be installed from CRAN. If desired, the development version of ggResidpanel can be installed from GitHub.
Load the ggResidpanel package.
Here are some resources for learning how to use ggResidpanel:
The package provides five functions that allow the user to assess diagnostic plots from a model. These functions are:
resid_panel: Creates a panel of diagnostic plots of the residuals from a model
resid_interact: Creates an interactive panel of diagnostic plots of the residuals form a model
resid_xpanel: Creates a panel of diagnostic plots of the predictor variables
resid_compare: Creates a panel of diagnostic plots from multiple models
resid_auxpanel: Creates a panel of diagnostic plots for model types not included in the package
Currently, ggResidpanel allows the first four functions listed above to work with models fit using the functions of
lme (from nlme), and
glmer (from lme4 or fit using lmerTest). Each of these functions is applied below to show the panel that is output from the function. The functions have multiple input options such as the formatting options of
penguins data used in the examples below is included in ggResidpanel.
## 'data.frame': 125 obs. of 4 variables: ## $ heartrate: num 88.8 103.4 97.4 85.3 60.6 ... ## $ depth : num 5 9 22 25.5 30.5 32.5 38 32 6 10.5 ... ## $ duration : num 1.05 1.18 1.92 3.47 7.08 ... ## $ bird : Factor w/ 9 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
This function creates a panel of residual diagnostic plots given a model. It allows the user to select a panel of plots from the options in the package or create their own panel by selecting from the plots available for this function.
This function creates interactive versions of residual diagnostic plot panels given a model. Similar to
resid_panel, it allows the user to select a panel of plots from the options in the package or to create their own panel by selecting from the plots available for this function.
This function creates a panel of plots of the residuals or response variable versus the predictor (x) variables in the model.
This function creates a panel of residual diagnostic plots given a list of models. This allows the user to compare the diagnostic plots from multiple models.
# Fit the model with a log transformation of the response variable and a # quadratic term for duration penguin_model_log2 <- lme4::lmer(log(heartrate) ~ depth + duration + I(duration^2) + (1|bird), data = penguins) # Plot the residual and normal quantile plots for the two models resid_compare(list(penguin_model, penguin_model_log2), plots = c("resid", "qq"))
This function creates a panel of residual diagnostic plots given inputs of residuals and fitted values to use for models not accepted by
resid_panel. Users can select from panel options in the package or create their own panel from the plots available for this function.
# Fit a regression tree to the penguins data penguin_tree <- rpart::rpart(heartrate ~ depth + duration, data = penguins) # Obtain the predictions from the model on the observed data penguin_tree_pred <- predict(penguin_tree) # Obtain the residuals from the model penguin_tree_resid <- penguins$heartrate - penguin_tree_pred # Create a panel with the residual and index plot resid_auxpanel(residuals = penguin_tree_resid, predicted = penguin_tree_pred, plots = c("resid", "index"))