error in parboot for occuRN

130 views
Skip to first unread message

Jeffrey Royle

unread,
Nov 17, 2017, 6:21:18 PM11/17/17
to unma...@googlegroups.com
hi all,
 I have this error (below) when I try to run parboot for an occuRN model. This is strange because it seems to have been introduced in the 0.12-2 version of unmarked  (doesn't exist in 0.11 version).  
 I will fix this of course but I wonder if anyone else has encountered this error (it seems vaguely familiar to me...)
thanks
andy
 
> umfRN_b200_rev <- unmarkedFrameOccu(y=y, siteCovs=site_covs_rev)
>
> test2 <- occuRN(formula= ~ 1 ~  APP+GP + Fnat+Silvicultura+ Cana  , data= umfRN_b200_rev)
>
> chisq2 <- function(fm) {
+   observed <- getY(umfRN_b200_rev)
+   expected <- fitted(fm)
+   sum((observed - expected)^2/expected, na.rm=T)  
+ }
>
> pb_rev <- parboot(test2, statistic = chisq2, nsim = 20)
Error in .local(object, ...) :
  no slot of name "K" for this object of class "unmarkedFitOccuRN"
>

Tyler Petroelje

unread,
May 8, 2020, 6:01:09 PM5/8/20
to unmarked
Hi Andy,

Did you ever figure out what caused this? I seem to be having a similar issue currently. Ran on both version 0.12-3 and 1.0.0


> fmRNnull <- occuRN(~1 ~1,data=c.umf,K=40,method="BFGS",se=TRUE)
>
> fitstats <- function(Mod_global2) {
+   observed <- getY(Mod_global2@data)
+   expected <- fitted(Mod_global2)
+   resids <- residuals(Mod_global2)
+   sse <- sum(resids^2,na.rm=TRUE)
+   chisq <- sum((observed - expected)^2 / expected,na.rm=TRUE)
+   freeTuke <- sum((sqrt(observed) - sqrt(expected))^2,na.rm=TRUE)
+   out <- c(SSE=sse, Chisq=chisq, freemanTukey=freeTuke)
+   return(out)
+ }
> pb <- parboot(fmRNnull, fitstats, nsim=10000, report=1)
Error in .local(object, ...) : 
  no slot of name "K" for this object of class "unmarkedFitOccuRN"
In addition: Warning messages:
1: In truncateToBinary(object@data@y) :
  Some observations were > 1.  These were truncated to 1.
2: In truncateToBinary(y) :


Thanks!

- Tyler

Ken Kellner

unread,
May 8, 2020, 6:24:49 PM5/8/20
to unmarked
Hi Tyler,

You have to supply a K argument to the fitted function for occuRN models at the moment in order for it to work. If you don't it instead looks for a nonexistent K slot which is something we should fix. So something like the following should work:

> fitstats <- function(Mod_global2) {
+   observed <- getY(Mod_global2@data)
+   expected <- fitted(Mod_global2, K=40) #### add K here
+   resids <- residuals(Mod_global2)
+   sse <- sum(resids^2,na.rm=TRUE)
+   chisq <- sum((observed - expected)^2 / expected,na.rm=TRUE)
+   freeTuke <- sum((sqrt(observed) - sqrt(expected))^2,na.rm=TRUE)
+   out <- c(SSE=sse, Chisq=chisq, freemanTukey=freeTuke)
+   return(out)
+ }
> pb <- parboot(fmRNnull, fitstats, nsim=10000, report=1)


Ken

Jeffrey Royle

unread,
May 8, 2020, 6:30:52 PM5/8/20
to unma...@googlegroups.com
hi all,
 Ken is indeed right -- that will work.  I thought for sure we had a trap in the fitted() to default the value of K for that function.. At any rate, we will fix this.
regards
andy


--
You received this message because you are subscribed to the Google Groups "unmarked" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/unmarked/7f79ba5f-dad4-44d7-b28e-4b8e200932e7%40googlegroups.com.

Ken Kellner

unread,
May 8, 2020, 6:35:37 PM5/8/20
to unmarked
Turns out it isn't quite that simple, since residuals() looks for K also. I attached a script that overwrites the fitted and residual methods, if you source it in after loading unmarked your original code should work, as a workaround until we fix it.

Ken
To unsubscribe from this group and stop receiving emails from it, send an email to unma...@googlegroups.com.
fix_occuRN.R

Jeffrey Royle

unread,
May 8, 2020, 6:37:27 PM5/8/20
to unma...@googlegroups.com
interestingly we do have the fitted() function for occuRN looking for object@K from the occuRN function. The problem is, occuRN doesn't return K in the fit list!  So if we change that, then at least "fitted" will work... let me do that.  I'll also check residuals()



To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/unmarked/faf415cc-d7f3-460b-93c0-92682142d075%40googlegroups.com.

Jeffrey Royle

unread,
May 8, 2020, 6:42:29 PM5/8/20
to unma...@googlegroups.com
I just pushed a change to occuRN to return K in the fit list... I think if you install from github then things should work out.  I will test it this weekend.
regards
andy

Tyler Petroelje

unread,
May 11, 2020, 9:39:30 AM5/11/20
to unma...@googlegroups.com
Many thanks, Andy and Ken,

The workaround to provide K to fitted and residuals worked. I'll pull the latest commit from github and see how that works as well.

Thanks again,

- Tyler

Reply all
Reply to author
Forward
0 new messages