How to fix "Cannot directly backTransform an unmarkedEstimate with length > 1" error in R?

1k Views Asked by At

I'm trying to make a line plot of the relationship of density on the real scale, based on estimates from the model (hn.l.s). But I'm stuck on Back-transforming it to real scale. Am I right in backtransforming or should I have gone straight to plot()?

I've tried backTransform(hn.l.s, type="state") instead of "det" but neither works.

dist<-seq(0,60,15)
obs<-as.matrix(dat[,1:4])
site_covs<-data.frame(shrub=dat[,c("d.shrub")],light=dat[,c("light")])
umf<-unmarkedFrameDS(y=obs,siteCovs=site_covs,dist.breaks=c(dist),survey="point",unitsIn="m")
hn.1.s<-distsamp(~1~shrub,umf,keyfun="halfnorm",output="density",unitsOut="ha")
pred.hn.l.s<-predict(hn.l.s,"state",se.fit=TRUE)
backTransform(hn.l.s, type="det")

Error in .local(obj, ...) : Cannot directly backTransform an unmarkedEstimate with length > 1.

I was expecting to get a detection estimate from:

backTransform(hn.l.s, type="det") 

Which would have given me a number:

sigma<-[the number]

Then I would have estimated the half-normal exp:

hn.l.s@estimates

And gotten:

b<-exp([a diff number])

Then calculated:

p.hn.l.s<-1-exp(-(dist/sigma)^-b)

And gotten a plot with:

plot(dist,p.hn.l.s,type="l",xlim=c(0,60), ylim=c(0,1), xlab="Distance", ylab="Detection probability")
1

There are 1 best solutions below

0
filups21 On

Without a reproducible example, I can't give you a precise answer, but basically, you can only use backTransform when there are no covariates. If there ARE covariates, then you need to specify the covariate values at which to make the back transformation. You can do that using the linearComb function (see the unmarked manual here). You can then use backTransform on the results of the linearComb function.