Check for autocorrelation in residuals

Description

Once a DSM has been fitted to data, this function can be used to check for autocorrelation in the residuals.

Usage

1
2
3
4
dsm.cor(dsm.obj, Transect.Label = "Transect.Label",
  Segment.Label = "Segment.Label", max.lag = 10,
  resid.type = "scaled.pearson", fun = cor, ylim = c(0, 1),
  subset = "all", ...)

Arguments

dsm.obj

a fitted dsm object.

Transect.Label

label for the transect (default: Transect.Label). Using different labels can be useful when transects are split over geographical features or when transects are surveyed multiple times.

Segment.Label

label for the segments (default: Segment.Label).The result of calling order() must make sense.

max.lag

maximum lag to calulate at.

resid.type

the type of residuals used, see residuals.gam and residuals.gam. Defaults to "scaled.pearson" in the GAM case and "normalized" in the GAMM case (which are equivalent).

fun

the function to use, by default cor, must take two column vectors as arguments.

ylim

user defined limits in y direction.

subset

which subset of the data should the correlation function be calculated on?

...

other options to pass to plot.

Value

a plot or a vector of fun applied at the lags.

Details

Within each Transect.Label, segments will be sorted according to their Segment.Labels. This may require some time to get right for your particular data. If one has multiple surveys where transects are revisited, for example, one may want to make Transect.Label a unique transect-survey id. Neither label need to be included in the model, they must just be present in the $data field in the model. This usually means that they have to be in the segment data passed to dsm.

The current iteration of this function will only plot correlations nicely, other things are up to you but you can get the function to return the data (by assigning the result to an object).

If there are NA values in the residuals then the correlogram will not be calculated. This usually occurs due to NA values in the covariates (so the smoother will not have fitted values there). Code like 'any(is.na(dsm.obj$data))' might be helpful.

Author(s)

David L. Miller

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 library(Distance)
 library(dsm)

 data(mexdolphins)
 attach(mexdolphins)

 hr.model <- ds(distdata, max(distdata$distance),
                key = "hr", adjustment = NULL)
 mod1<-dsm(N~s(x,y), hr.model, segdata, obsdata)

 dsm.cor(mod1,resid.type="d",max.lag=9,Segment.Label="Sample.Label")
 detach("mexdolphins")

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.