Migration from dsm 1.1.3 to 2.1.5

11 November 2013

General notes/preamble

Model fitting

Old call example:

dsm.14 <- dsm.fit(ddfobject=ddf.2, response='indiv.abund',
                  model.defn=list(fn='gam',family='quasipoisson'),
                  wghts=NULL, link='log', formula=~s(longitude),
                  obsdata=obs.dat.14, segdata=sample.dat.14,
                  convert.units=.001)

In new dsm this should be specified:

dsm.14.new <- dsm(ddf.obj=ddf.2, engine='gam', group=FALSE, 
                  family=quasipoisson(log), weights=NULL,
                  formula=N~s(longitude),
                  observation.data=obs.dat.14,
                  segment.data=sample.dat.14,
                  convert.units=.001)

Notes:

The response can be one of the following:

Response Description
N, abundance count in each segment
Nhat, abundance.est estimated abundance per segment, estimation is via a Horvitz-Thompson estimator. This should be used there are covariates in the detection function.
D, density density per segment
presence interpret the data as presence/absence (remember to change the family argument to binomial())

Prediction

Old call example:

dsm.predict.15 <- dsm.predict(model=dsm.14,newdata=grid.15, off.set=444)

New call example:

dsm.predict.15 <- predict(model=dsm.14,newdata=grid.15, off.set=444)

No real change here except that we now call down to the appropriate predict method (for gam, glm etc). You could also ignore off.set and have it as a variable in newdata, if there is a column called off.set in newdata, then the function argument off.set is ignored.

Returned object is exactly as before (vector of length nrow(newdata)), so you need to sum() for total abundance.

Variance estimation

Moving block

Looks like in the old regime, you had to do something funny mergeing data into the model object (picking out relevant lines only):

var.dat <- read.table(file='C:\\Users\\eric\\AppData\\Local\\Temp\\dst21303\\var.dat.r',
                      header=TRUE, sep='\t', comment.char='')
dsm.tmp <- dsm.14
dsm.tmp$result$data <- merge(dsm.tmp$result$data, var.dat)

I think this was to include the Bootstrap.Sample.Label into the model data. If that was the case then you can use the code above jsut removing the $result in the above.

Old call example:

dsm.var.16 <- dsm.var.movblk(dsm.object=dsm.tmp, pred.data = grid.15,
                             n.boot=10, block.size=3, off.set=444,
                             samp.unit.name='Bootstrap.Sample.Label',
                             progress.file='C:\\Users\\eric\\AppData\\Local\\Temp\\dst21303\\bootprog.txt',
                             bar = FALSE)

New call example:

dsm.var.16 <- dsm.var.movblk(dsm.object=dsm.tmp, pred.data = grid.15,
                             n.boot=10, block.size=3, off.set=444,
                             samp.unit.name='Bootstrap.Sample.Label',
                             progress.file='C:\\Users\\eric\\AppData\\Local\\Temp\\dst21303\\bootprog.txt',
                             bar = FALSE)

Notes

Analytic variance

The two other functions dsm.var.gam and dsm.var.prop also estimate the variance. The first by standard GAM theory (using the delta method to combine detection function and GAM uncertainties), the second using MVB’s trick. The respective manual pages for these functions should provide all the information you require.

Other stuff

Model checking

Fitting stuff

Internal functions that might be useful

References

Dunn, P K, and G K Smyth. “Randomized Quantile Residuals.” Journal of Computational and Graphical Statistics 5, no. 3 (1996): 236–244.