View source: R/residuals.glmssn.R
residuals.glmssn | R Documentation |
residuals.glmssn
is a generic function that has been modified
for glmssn
objects. It produces residuals from glmssn spatial models.
## S3 method for class 'glmssn' residuals(object, cross.validation=FALSE, ...)
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 |
... |
Other arguments |
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,
The response value used for fitting the model
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.
The raw residuals. The observed response value minus the fitted value using only fixed effect estimates (no random effects are included).
Standardized residuals, calculated by dividing the raw residuals by the corresponding estimated standard errors
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. H[i,i] as described for Studentized residuals.
Cook's D, using the method of creating uncorrelated data as for Studentized residuals, and then applying Cook's D.
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.
The leave-one-out cross-validation predictions. Only computed if cross.validation
is set to TRUE.
Estimated standard errors for the leave-one-out cross-validation predictions.
Only computed if cross.validation
is set to TRUE.
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.
Jay Ver Hoef support@SpatialStreamNetworks.com
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.