resids: Residual Analysis

View source: R/resids.r

residsR Documentation

Residual Analysis

Description

Examines the residuals from the fit of the model to determine whether spatial dependence exists. Operates on objects of class dpart.

Usage

## S3 method for class 'dpart'
resids(object, LonID, LatID, predID, plot = TRUE)
## S3 method for class 'bag'
resids(object, LonID, LatID, predID, plot = TRUE)

## S3 method for class 'dpart'
resids(object, LonID, LatID, predID, plot = TRUE)

## S3 method for class 'bag'
resids(object, LonID, LatID, predID, plot = TRUE)

Arguments

object

object of class dpart.

LonID

column name for longitude.

LatID

column name for latitude.

predID

predator ID

plot

logical. Whether plotting should be performed

Details

Produces a variogram of the residuals to check for spatial dependence.

Value

Outputs the residuals and a variogram plot of the residuals for checking.

See Also

objects to See Also as variog

Examples

# Load data
#data(yftdiet)  

# Load the prey taxa data
#data(PreyTaxonSort)

# Assigning prey colours for default palette
#val <- apc(x = yftdiet, preyfile = PreyTaxonSort, check = TRUE)
#node.colsY <- val$cols
#dietPP <- val$x   # updated diet matrix with Group assigned prey taxa codes

# Fitting the classification tree
#yft.dp <- dpart(Group ~ Lat + Lon + Year + Quarter + SST  + Length, 
#                   data = dietPP, weights = W, minsplit = 10,
#                                     cp = 0.001)
                                    
# Pruning the tree
#yft.pr <- prune(yft.dp, se = 1)                   

# Checking residuals
#yft.resid <- resids(yft.pr, LonID = "Lon", LatID = "Lat", 
#     predID = "TripSetPredNo", plot = TRUE) # need to compute resids from bootstrapping
    
# Bagging
# Bagging with NO spatial bootstrapping (nBaggs set to something small)
#yft.bag <- bagging(Group ~ Lat + Lon + Year + Quarter + SST  + Length,
#                     data = dietPP, weights = W, minsplit = 50,
#                     cp = 0.001, nBaggs = 10, predID = "TripSetPredNo")
                    
# Checking for spatial dependence
#yft.bag.resid <- resids(yft.bag, LonID = "Lon", LatID = "Lat", 
#predID = "TripSetPredNo", plot = TRUE) # need to compute resids from bootstrapping
          
                    

pkuhnert/diet documentation built on June 10, 2025, 2:59 a.m.