compare.fits: Compare the fits of two models

View source: R/compare.fits.R

compare.fitsR Documentation

Compare the fits of two models

Description

This function takes two fitted models as input and plots them to visually compare how the two differ in terms of fit. It can take a glm, rlm, lm, and randomForest model (and maybe others as well). The function takes a flexplot-like formula as input.

Usage

compare.fits(
  formula,
  data,
  model1,
  model2 = NULL,
  return.preds = F,
  report.se = F,
  re = F,
  pred.type = "response",
  num_points = 50,
  clusters = 3,
  ...
)

Arguments

formula

A formula that can be used in flexplot. The variables inside must not include variables outside the fitted models.

data

The dataset containing the variables in formula

model1

The fitted model object (e.g., lm) containing the variables specified in the formula

model2

The second fitted model object (e.g., lm) containing the variables specified in the formula

return.preds

Should the function return the predictions instead of a graphic? Defaults to F

report.se

Should standard errors be reported alongside the estimates? Defaults to F.

re

Should random effects be predicted? Only applies to mixed models. Defaults to F.

pred.type

What type of predictions should be outputted? This is mostly for glm models. Defaults to "response."

num_points

Number of points used for predictions. Larger numbers = slower algorithm, but smoother predictions.

clusters

For visualizing mixed models, this specifies the number of clusters to display

...

Other parameters passed to flexplot

Value

Either a graphic or the predictions for the specified model(s)

Author(s)

Dustin Fife

Examples

data(exercise_data)
mod1 = lm(weight.loss~therapy.type + motivation, data=exercise_data)
mod2 = lm(weight.loss~therapy.type * motivation, data=exercise_data)
compare.fits(weight.loss~therapy.type | motivation, data=exercise_data, mod1, mod2)

dustinfife/flexplot documentation built on Sept. 23, 2024, 9:01 p.m.