error when running marginal occupancy

104 views
Skip to first unread message

Rachel Townsend

unread,
Jul 13, 2021, 1:38:39 PM7/13/21
to unmarked
Hi,

I am looking at three species data similar to Rota 2016 but I have a long term data set and analyzing by season. I have 12 seasons and I have gotten results for all but one, which is why I can't figure this out. I'm able to fit the model and get AIC but when I go to run marginal occupancy I am getting an error message. See code below:

fit4 <- occuMulti(detFormulas,occFormulas,rotadata)
fit4

#marginal occupancy bobcat
marbob <- (predict(fit4,'state',newdata=rotadata,species='bobcat'))

Error in quantile.default(newX[, i], ...) : 
  missing values and NaN's not allowed if 'na.rm' is FALSE

Any insight? I have NAs in my matrices for weeks the cameras weren't running and that hasn't caused this error in the other seasons. Thank you!!

Ken Kellner

unread,
Jul 13, 2021, 1:57:17 PM7/13/21
to unmarked
Does fit4 have NaNs in the summary?

What happens if you run

marbob <- (predict(fit4,'state',species='bobcat'))

If you want occupancy predictions for your actual sites, you don't need to provide the original dataset as newdata.

Ken

Rachel Townsend

unread,
Jul 14, 2021, 12:36:12 PM7/14/21
to unmarked
Hi Ken, thanks for your response. I tried your suggestion leaving out the original datset and got the same error. I do not get NaNs in my summary (pasted below). I'm stumped.

Call:
  occuMulti(detformulas = detFormulas, stateformulas = occFormulas, 
            data = rotadata)

Occupancy:
                                                   Estimate       SE             z P(>|z|)
[bobcat] (Intercept)               -0.41327   0.5135 -0.8049  0.4209
[bobcat] hike                          -0.00708   0.0298 -0.2375  0.8123
[coyote] (Intercept)               -1.40421   0.6091 -2.3054  0.0211
[coyote] hike                           0.06936   0.0284  2.4456  0.0145
[gryfox] (Intercept)                0.21220   0.4149  0.5114  0.6091
[gryfox] hike                          10.66987 196.8486  0.0542  0.9568
[bobcat:coyote] (Intercept)  0.91570   0.5714  1.6026  0.1090
[bobcat:gryfox] (Intercept)  0.98199   0.5806  1.6912  0.0908
[coyote:gryfox] (Intercept) -0.08743   0.6099 -0.1433  0.8860

Detection:
  Estimate     SE      z  P(>|z|)
[bobcat] (Intercept)   -1.306 0.0947 -13.79 2.94e-43
[coyote] (Intercept)   -1.153 0.1171  -9.85 7.12e-23
[gryfox] (Intercept)   -0.531 0.0657  -8.09 5.92e-16

AIC: 3039.993 

Ken Kellner

unread,
Jul 15, 2021, 11:30:22 AM7/15/21
to unmarked
I think the issue is likely related to your estimate of gryfox [hike] where it looks like you have a separation problem due to the huge estimate and SE. Perhaps you didn't have any 'hike' sites where gray foxes were detected or vice-versa? The huge SE is likely causing issues with calculating the prediction and the error term. You could try setting the argument se.fit=FALSE.
However due to the very poor parameter estimate I would probably not use the results of this specific model as-is anyway.
If you are able to email me the fitted model as an Rdata off-list, I can take a look to make sure that's the reason.

Ken

Rachel Townsend

unread,
Jul 20, 2021, 2:39:55 PM7/20/21
to unmarked
Hi Ken,

I was wondering why I had such a large value for gryfox [hike]. ok, I will run that again, save it and email to you. 

One other thing. I updated Unmarked last week and am now getting an error on seasons that ran previous to me binning the data. Again, trying to run marginal occupancy: 

fit4 <- occuMulti(detFormulas,occFormulas,rotadata)
fit4

#marginal occupancy bobcat
marbob <- (predict(fit4,'state',newdata=rotadata,species='bobcat'))
Error in .local(object, ...) : newdata must be a data frame

 Do I need to add something to the predict syntax to get it to recognize "rotadata" - the UnmarkedFrameOccuMulti?

Thanks again,

Rachel

Ken Kellner

unread,
Jul 21, 2021, 10:32:27 AM7/21/21
to unmarked
Hi Rachel,

I'm not sure exactly what's going on with predict here, I'll have to look. However I would suggest an adjustment to your code here anyway. When predicting, you either want to generate marginal occupancy for your actual sites (and their associated covariate values), or for new "sites" with new combinations of covariates (e.g., when generating a smooth curve for a figure). If you want predictions for your actual sites, don't provide any newdata and you'll get back what you want. If you want to predict based on new combinations of covariates, provide them in a data frame, not an unmarkedFrame.

Ken

Rachel Townsend

unread,
Jul 23, 2021, 12:19:00 PM7/23/21
to unmarked
Hi Ken, I suppose that simplifies things. I am looking at predictions for actual sites (cameras) so it makes sense that my code should look like this?

marbob <- (predict(fit4,'state',species='bobcat'))
marbob <- (predict(fit4,'state',species='bobcat'))
max(marbob$Predicted)
min(marbob$Predicted)
head(marbob)
bdat <-data.frame(marbob,occu_covs_raw$hike)
head(bdat)

plot(occu_covs_raw$hike,marbob$Predicted,ylim=c(0,1))

And then I would do the same for two species conditional occupancy, right? i.e:

#conditional occupancy for bobcat conditional on coyote
bobcoyp=(predict(fit4,'state',species=1,cond=2)) #bobcat | coyote present

bobcoym=predict(fit4,'state',species=1,cond=-2) #bobcat | coyote present

max(bobcoyp$Predicted)
min(bobcoyp$Predicted)

Thanks so much for your help, I really appreciate it!

Rachel
Reply all
Reply to author
Forward
0 new messages