This function is used to create Diagnostic Plots and calculate the residuals for a set of model estimates.

avgm_res(
  estimates,
  data,
  response,
  x_vars,
  plots = TRUE,
  res.export = TRUE,
  norm = FALSE,
  show = FALSE
)

Arguments

estimates

A data frame with 2 columns. The first column must hold the variable names and if there is an intercept, the intercept should also have a name in this column. The second column should hold the estimates

data

The data frame used in the model

response

A character equal to the name of the column in data that holds the response variable

x_vars

A character or vector of the explanatory variable names. Should also equal the column names in data that holds the explanatory variable data. The name of the intercept should NOT be included in this vector.

plots

Logical. If TRUE, then diagnostic plots are created and saved

res.export

Logical. If TRUE, then the residuals are saved in a data frame with the observed and fitted values

norm

Logical. If TRUE, a Shapiro-Wilk normality test is performed on the residuals.

show

Logical. If TRUE, the plots will be show in a 1 x 3 paneled figure. If FALSE, the figures will still be saved but not shown so that the user has to plot them. Additionally, if norm = TRUE, the results of a Shapiro-Wilk normality test on the residuals will be printed if show = TRUE.

Value

A list or data frame with the information saved as designated by the plots, res.export, and norm arguments.

Examples

if (FALSE) {

library(MuMIn)
library(AICcmodavg)
library(ggplot2)
library(gridExtra)

## lm.sr is an object returned from sr.LM()
dat <- lm.sr[['Data']][['Anolis.N']]
out <- AIC_avg(lm.sr[['Models']][['Anolis.N']],
               data = dat,
               response = 'Anolis.N',
               x_vars = c(vars, 'sq_Area'),
               groups = data.frame(Genus = 'Anolis',
                                   Status = 'N'),
               cum.weight = 0.95,
               table = FALSE)

vars <- attr(lm.sr[['Models']][['Anolis.N']]$terms,'term.labels')

tmp <- avgm_res(out[, c('Variable', 'Estimate')],
                  data = dat,
                  response = 'Anolis.N',
                  x_vars = vars)

}