dsm.cor {dsm}  R Documentation 
Once a DSM has been fitted to data, this function can be used to check for autocorrelation in the residuals.
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",
...
)
dsm.obj 
a fitted dsm object. 
Transect.Label 
label for the transect (default: 
Segment.Label 
label for the segments (default: 
max.lag 
maximum lag to calculate at. 
resid.type 
the type of residuals used, see

fun 
the function to use, by default 
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 
a plot or a vector of fun
applied at the lags.
Within each Transect.Label
, segments will be sorted
according to their Segment.Label
s. 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
transectsurvey identifier. 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.
David L. Miller
library(Distance)
library(dsm)
# load the data, see ?mexdolphins
data(mexdolphins)
# fit a model
hr.model < ds(distdata, truncation=6000,
key = "hr", adjustment = NULL)
mod1 < dsm(count~s(x,y), hr.model, segdata, obsdata)
# look at lag 1 differences up to a maximum of lag 9, using deviance
# residuals
dsm.cor(mod1, resid.type="deviance", max.lag=9,
Segment.Label="Sample.Label")