DSM- extract the CV as shapefile

15 views
Skip to first unread message

Lisa Marie Leclerc

unread,
Apr 29, 2024, 10:43:39 AMApr 29
to distance-sampling
Hi, 

I was wondering what will be the R script to extract the CV of a DSM, as a shapefile to visualize the variance estimate in ARC GIS.  

Thanks 

Lisa


Eric Rexstad

unread,
Apr 29, 2024, 1:59:18 PMApr 29
to Lisa Marie Leclerc, distance-sampling
Lisa

Here is a very simple answer to your question, based upon the use of dsm_var_gam​ for estimating uncertainty from your dsm​ model. The following code is based around the example provided at this case study website

I have omitted much of the code, leaving the fitting of a simple dsm​ model to data and using dsm_var_gam​ for variance estimation. I encourage you to look at the help​ for the function dsm_var_gam​ to learn the structure of the object produced by this function.

library(dsm)
load("mexdolphins-extra.rda")
data(mexdolphins)
library(rgdal)
library(maptools)
library(plyr)
proj4string(survey.area) <- CRS("+proj=longlat +datum=WGS84")
lcc_proj4 <- CRS("+proj=lcc +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs ")
survey.area <- spTransform(survey.area, CRSobj=lcc_proj4)
survey.area <- data.frame(survey.area@polygons[[1]]@Polygons[[1]]@coords)
names(survey.area) <- c("x", "y")
library(Distance)
detfc.hr.null <- ds(distdata, max(distdata$distance), key="hr", adjustment=NULL)
dsm.xy.depth <- dsm(count~s(x,y,k=10) + s(depth,k=20), detfc.hr.null, segdata, obsdata, method="REML")
summary(dsm.xy.depth)
plot(dsm.xy.depth, select=2)
dsm.xy.depth.pred <- predict(dsm.xy.depth, preddata, preddata$area)
preddata.var <- split(preddata, 1:nrow(preddata))
dsm.xy.depth.var <- dsm_var_gam(dsm.xy.depth, pred.data=preddata.var,off.set=preddata$area)
summary(dsm.xy.depth.var)

cv.by.gridcell <- sqrt(dsm.xy.depth.var$pred.var)/dsm.xy.depth.pred

The final step produces CV values for all 1374 prediction grid cells in this project. I have not attached the spatial coordinates to these CV values. Those spatial coordinates are contained in the object pred.polys​ You can combine the two to create something I suspect you can export to ArcGIS.  I suspected the main part of your question was how to compute the CV from the elements contained within an object created by dsm_var_gam​. I hope this answers your question.

From: distance...@googlegroups.com <distance...@googlegroups.com> on behalf of Lisa Marie Leclerc <lisalec...@gmail.com>
Sent: 29 April 2024 15:43
To: distance-sampling <distance...@googlegroups.com>
Subject: [distance-sampling] DSM- extract the CV as shapefile
 
--
You received this message because you are subscribed to the Google Groups "distance-sampling" group.
To unsubscribe from this group and stop receiving emails from it, send an email to distance-sampl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/distance-sampling/e874ca2a-d136-45b5-a4f3-99e02cc361een%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages