Learn R Programming

SSN (version 1.1.17)

residuals.glmssn: Compute Model Residuals for glmssn Objects

Description

residuals.glmssn is a generic function that has been modified for glmssn objects. It produces residuals from glmssn spatial models.

Usage

# S3 method for glmssn
residuals(object, cross.validation=FALSE, ...)

Value

The returned object is of class influenceSSN-class. It similar to a glmssn-classobject; the main difference is that additional columns (described in the details section) have been added to the observed points data.frame.

Arguments

object

an object of class glmssn

cross.validation

logical value indicating whether leave-one-out cross-validation residuals will be computed. The default is FALSE. Setting cross.validation to TRUE may increase processing times for large datasets.

...

Other arguments

Details

When using residual(x) on a glmssn object, the data for which the model was fit is contained in the obspoints slot @SSNPoints@point.data. This data frame contains the response variable for the model, so it is appended with the following columns,

obsval

The response value used for fitting the model

_fit_

For a model z = Xb + e, where X is a design matrix for fixed effects and e contains all random components, then the fit is Xb, where b contains the estimated fixed effects parameters.

_resid_

The raw residuals. The observed response value minus the fitted value using only fixed effect estimates (no random effects are included).

_resid.stand_

Standardized residuals, calculated by dividing the raw residuals by the corresponding estimated standard errors

_resid.student_

Studentized residuals. From a model z = Xb + e, we can create uncorrelated data by taking a model Cz = CXb + Ce, where var(e) = sV, C is the square root inverse of V, and s is an overall variance parameter. Under such a model, the hat matrix is H = CX*inv(X'(C'C)X)*X'C'. Then, the variance of a residual is s(1-H[i,i]), and so the studentized residual is r[i]/sqrt(s(1-H[i,i]), where r[i] is the ith raw residual.

_leverage_

Leverage. H[i,i] as described for Studentized residuals.

_CooksD_

Cook's D, using the method of creating uncorrelated data as for Studentized residuals, and then applying Cook's D.

_resid.crossv_

Cross-validation residuals, obtained from leave-one-out-at-a-time and taking the difference between the observed response value and that predicted after removing it. Only computed if cross.validation was set to TRUE.

_CrossValPred_

The leave-one-out cross-validation predictions. Only computed if cross.validation is set to TRUE.

_CrossValStdErr_

Estimated standard errors for the leave-one-out cross-validation predictions. Only computed if cross.validation is set to TRUE.

Examples

Run this code

	library(SSN)
	# get some model fits stored as data objects
	data(modelFits)
	#NOT RUN use this one
	#fitSp <- glmssn(Summer_mn ~ ELEV_DEM + netID,
	#    ssn.object = mf04p, EstMeth = "REML", family = "Gaussian",
	#    CorModels = c("Exponential.tailup","Exponential.taildown",
	#    "Exponential.Euclid"), addfunccol = "afvArea")
	#for examples only, make sure fitSp has the correct path
	#if you use importSSN(), path will be correct
	fitSp$ssn.object <- updatePath(fitSp$ssn.object, 
		paste0(tempdir(),'/MiddleFork04.ssn'))

  resids <- residuals(fitSp)
  class(resids)
  names(resids)
  plot(resids)
  hist(resids, xlab = "Raw Residuals")
  qqnorm(resids)

  resids.df <- getSSNdata.frame(resids)
  plot(resids.df[,"_resid_"], ylab = "Raw Residuals")

Run the code above in your browser using DataLab