simresiduals: Simulate Residuals

simresidualsR Documentation

Simulate Residuals

Description

Simulates residuals for a given regression model

Usage

simresiduals(object, ...)
## Default S3 method:
simresiduals(object, nrep=19, simfunction=NULL,
  stdresiduals = NULL, sigma = object$sigma, ...)
## S3 method for class 'glm'
simresiduals(object, nrep=19, simfunction=NULL,
        glm.restype="working", ...)

Arguments

object

result of fitting a regression

nrep

number of replicates

simfunction

if a function, it is used to generate random values for the target variable, with three arguments, which will be fed by the number of observations, the fitted values, and object$sigma in the case of simresiduals.default, respectively.
If TRUE, the appropriate random number generator will be used.
If NULL (default) the standardized residuals of object will be randomly permuted in the case of simresiduals.default. For simresiduals.glm, this is the same as TRUE.

stdresiduals

logical: should standardized residuals be produced?

sigma

scale parameter to be used, defaults to object$sigma

glm.restype

type of residuals to be generated (for glm) Warning: type "deviance" may produce NAs.

...

further arguments passed to forthcoming methods.

Details

The simulated residuals are obtained for the default method by replacing the response variable by permuted standardized residuals of the fitted regression, multiplied by the scale object\$sigma, then fitting the model to these residuals and getting the reseiduals from this new fit. This is repeated nrep times. If standarized residuals are not available, ordinary residuals are used.

For the glm method, the values of the response variable are obtained from simulating according to the model (binomial or Poisson), and the model is re-fitted to these generated values.

Value

A matrix of which each column contains an set of simulated residuals. If standardized residuals are available, attribute "stdresisduals" is the matrix containing corresponding standardized residuals.

Author(s)

Werner A. Stahel, ETH Zurich

Examples

data(d.blast)
r.blast <-
  lm(log10(tremor)~location+log10(distance)+log10(charge),
  data=d.blast)
r.simblast <- simresiduals(r.blast, nrep=5)
showd(r.simblast)
## --------------------------
data(d.babysurvival)
r.babysurv <- lm( Survival~Weight+Age+Apgar1, data=d.babysurvival)
r.simbs <- simresiduals(r.babysurv, nrep=5)
showd(r.simbs)

plgraphics documentation built on Oct. 19, 2023, 3 p.m.