residuals.glmssn: Compute Model Residuals for glmssn Objects In SSN: Spatial Modeling on Stream Networks

Description

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

Usage

 ```1 2``` ```## S3 method for class 'glmssn' residuals(object, cross.validation=FALSE, ...) ```

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.

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.

Author(s)

Jay Ver Hoef support@SpatialStreamNetworks.com

Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22``` ``` 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") ```

SSN documentation built on March 13, 2020, 1:49 a.m.