-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Error arises on line 11 of varprop_check
dsm_var_prop produces a reasonable standard error for the Gomex dolphins, but the last line of dsm_var_prop is to return a result including a call to varprop_check that generates the error.
Attempt to manufacture MRE from the Gomex data. Requires artificially creating a Beaufort value at the segment level (requirement of using dsm_var_prop for variance estimation).
library(dsm)
library(ggplot2)
load("mexdolphins-extra.rda") # must be downloaded from distanceexamples website
data(mexdolphins)
library(rgdal)
library(maptools)
library(plyr)
# tell R that the survey.area object is currently in lat/long
proj4string(survey.area) <- CRS("+proj=longlat +datum=WGS84")
# proj 4 string
# using http://spatialreference.org/ref/esri/north-america-lambert-conformal-conic/
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 ")
# project using LCC
survey.area <- spTransform(survey.area, CRSobj=lcc_proj4)
# simplify the object
survey.area <- data.frame(survey.area@polygons[[1]]@Polygons[[1]]@coords)
names(survey.area) <- c("x", "y")
# given the argument fill (the covariate vector to use as the fill) and a name,
# return a geom_polygon object
# fill must be in the same order as the polygon data
grid_plot_obj <- function(fill, name, sp){
# what was the data supplied?
names(fill) <- NULL
row.names(fill) <- NULL
data <- data.frame(fill)
names(data) <- name
spdf <- SpatialPolygonsDataFrame(sp, data)
spdf@data$id <- rownames(spdf@data)
spdf.points <- fortify(spdf, region="id")
spdf.df <- join(spdf.points, spdf@data, by="id")
# seems to store the x/y even when projected as labelled as
# "long" and "lat"
spdf.df$x <- spdf.df$long
spdf.df$y <- spdf.df$lat
geom_polygon(aes_string(x="x",y="y",fill=name, group="group"), data=spdf.df)
}
library(Distance)
detfc.hr.null <- ds(distdata, max(distdata$distance), key="hr", adjustment=NULL)
gof_ds(detfc.hr.null)
detfc.hr.beau<-ds(distdata, max(distdata$distance), formula=~beaufort,
key="hr", adjustment=NULL)
gof_ds(detfc.hr.beau)
segdata$beaufort <- rpois(nrow(segdata), 1.2)
segdata$beaufort <- ifelse(segdata$beaufort<5, segdata$beaufort, 4)
dsm.beau.xy <- dsm(count~s(x,y), detfc.hr.beau, segdata, obsdata, method="REML")
summary(dsm.beau.xy)
dsm.xy.pred <- predict(dsm.beau.xy, preddata, preddata$area)
preddata.var <- split(preddata, 1:nrow(preddata))
dsm.xy.var <- dsm_var_gam(dsm.beau.xy, pred.data=preddata.var,
off.set=preddata$area)
summary(dsm.xy.var) # var_gam is happy
dsm.xy.varprop <- dsm_var_prop(dsm.beau.xy, pred.data=preddata.var,
off.set=preddata$area) #var_prop is not happy
summary(dsm.xy.varprop)
I don't know the purpose of varprop_check so I don't know if simply eliminating the call to the function in the last line of dsm_var_prop is a viable solution to the problem.
Other inconsistencies: object names in the list returned by dsm_var_prop do not correspond with object names used in summary.dsm_varprop; e.g. first element of list is pred.var, but summary thinks there is an element var