Error using predict to plot confidence of occupancy

91 views
Skip to first unread message

Billie

unread,
Aug 22, 2019, 1:29:03 AM8/22/19
to unmarked
Dear all
I am hoping someone can please assist.
I am mapping occupancy probability.
I have undertaken model selection. elev_year_group is the top ranking model where occupancy varies by elevation and detection by year_group. This model outputs sensible results and I can predict the occupancy at each monitored point by using the following code:
E.psi<-predict(elev_year_group, type="psi")

I can produce a plot of estimated occupancy without confidence using the following code:

(beta<-coef(elev_year_group))
Elevation<-raster("tasdem25.tif")
attr(sc,"scaled:scale")
ele.s<-(Elevation-348)/265
(beta<-coef(elev_year_group))
logit.psi<-beta[1]+beta[2]*ele.s
psi<-exp(logit.psi)/(1+exp(logit.psi))
plot(psi)

This produces a great map, however when I attempt to map confidence of occupancy using the following code:
ef <- stack(ele.s) #note this is a dummy stack because there is only one raster layer however when I type plot(ef) the correct map is produced
E.psi <- predict(elev_year_group, type="state", newdata=ef)
the following error results
Error in nrow(X) : object 'X' not found

and when I try
E.psi <- predict(elev_year_group, type="psi", newdata=ef)
Error in .local(object, ...) : 
  At least 1 covariate in the formula is not in the raster stack.
   You probably need to assign them using
         'names(object) <- covariate.names'


I would be very grateful for any suggestions.
Regards,
Billie.

Ken Kellner

unread,
Aug 22, 2019, 8:33:25 AM8/22/19
to unmarked
Try this:

ef <- stack(ele.s)
names(ef) <- "ele.s" #assuming elevation is called 'ele.s' in your original state formula in occu()
E.psi <- predict(elev_year_group, type="state", newdata=ef)

Billie

unread,
Aug 27, 2019, 8:27:40 PM8/27/19
to unmarked
Sincere thanks for your suggestion Ken. It appears to have solved the initial problem.
Unfortunately I now get the message:
Error: cannot allocate vector of size 1.3 Gb
My desktop has 16GB ram, and I am running the 64 bit version of R, but perhaps the computation that I am requesting is still too large for my processor?
Regards,
Billie.


Ken Kellner

unread,
Aug 28, 2019, 10:32:58 AM8/28/19
to unmarked
How large is the original raster file? Unmarked makes at least one copy of the data in the raster into memory, and then would write out another similarly sized raster into memory, plus any other overhead. I don't think there's much we can do to address that in the short term, without substantial changes the way predict works on rasters. 

Maybe you could slice your raster up into pieces, run predict on each piece separately, and then stitch them back together? Here's a package that looks like it could do that:


Ken

Billie

unread,
Aug 28, 2019, 7:13:57 PM8/28/19
to unmarked
This is great advice. Many thanks for your time and knowledge.
Billie.
Reply all
Reply to author
Forward
0 new messages