FunResplot: Residual plot with resampling

View source: R/FunResplot.R

FunResplotR Documentation

Residual plot with resampling

Description

FunResplot plots four model diagnostic residual plots to check model assumptions.

Usage

FunResplot(
  obj,
  plots = 1:4,
  method = c("rnorm", "resampling"),
  num = 100,
  set_seed = FALSE,
  change_mfrow = TRUE,
  plot_title = TRUE
)

Arguments

obj

model (e.g. object of type lm)

plots

1=Tukey-Anscombe, 2=Normal, 3=Scale-Location, 4=Leverage. Several can be plotted e.g. plots = c(1,2)

method

how should resampling residuals be obtained for Tukey-Anscombe plots. rnorm: residuals are drawn from a normal distribution with variance equal the estimated variance of the observed residuals. resampling: residuals are drawn from observed residuals with replacment

num

number of resampling iterations (number of gray lines)

set_seed

boolean. Automatically set a constant seed in the function

change_mfrow

boolean. Automatically adjust mfrow if length(plots) > 1

plot_title

boolean. Should there be a title above the figure.

Value

Nothing is returned. Plots are plotted

Author(s)

Marcel Dettling

Examples

## generate data
x <- 1:100
y <- rnorm(100, x + 10, 10)

## fit model
fit <- lm(y ~ x)
plot(y ~ x)
abline(fit)

## plot residual plots
FunResplot(fit)
FunResplot(fit, plots = 1:2, num = 20)

## another good method
## see anova r-script 05_nitrogen
nitro.sim <- nitro

set.seed(12)
opar <- par(mfrow = c(4, 5))
for(i in 1:20){
  nitro.sim[, "y"] <- simulate(fit)
  fit.sim <- update(fit, data = nitro.sim)
  plot(fit.sim, which = 1)
}
par(opar)


retodomax/FunRZ documentation built on July 30, 2023, 6:42 p.m.