Error in parboot: invalid size argument

105 views
Skip to first unread message

Adrienne Beatrice

unread,
Feb 10, 2020, 11:59:38 AM2/10/20
to unmarked
Hello everyone,
I'm having trouble finding any information about this error in the group or anywhere else, and haven't been able to fix it on my own.
I have created and run my global model in gdistsamp and would now like to run a GOF test with bootstrap iterations to determine model fit.
I ran fitstats, which seems to work fine, but then when I run the bootstrap function I get an error about an "invalid second argument 'size'".
Any thoughts??

> fitstats <- function(g.global) {
+   observed <- getY(g.global@data)
+   expected <- fitted(g.global)
+   resids <- residuals(g.global)
+   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)
+ }

> (g.pb <- parboot(g.global, fitstats, nsim=10, report=5))
t0 = 97959.52 3578.87 2954.002
Error in rmultinom(1, N, prob = cp.it) : invalid second argument 'size' In addition: Warning messages: 1: In rnbinom(1, mu = lambda[i], size = alpha) : NAs produced 2: In rbinom(1, Ns, phi[i, t]) : NAs produced

Jim Baldwin

unread,
Feb 10, 2020, 1:18:14 PM2/10/20
to unma...@googlegroups.com
rmultinom will produce such a warning message when size = NA and rnbinom will produce the warning you see when size = 0.  Because you needed to add na.rm=TRUE to fitstats, is it possible that one of the bootstrap selections resulted in no data?

Jim

--
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/ad92eeff-4b76-4593-96d7-e385ccb884fc%40googlegroups.com.

Adrienne Beatrice

unread,
Feb 10, 2020, 1:28:34 PM2/10/20
to unmarked
Thank you for your input.
How would I know if one of the bootstrap selections resulted in no data?
Would it be better if I just elminated transects with NA values so that I didn't need the na.rm argument?
To unsubscribe from this group and stop receiving emails from it, send an email to unma...@googlegroups.com.

Jim Baldwin

unread,
Feb 10, 2020, 1:43:32 PM2/10/20
to unma...@googlegroups.com
Without seeing your data, that is about all I can suggest.  If that doesn't work, you might have to share the data with someone.  Lots of these kinds of issues are very data dependent.

Jim

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/9fb427c9-711b-4b43-ade2-982255cda521%40googlegroups.com.

Adrienne Beatrice

unread,
Feb 10, 2020, 3:27:43 PM2/10/20
to unmarked
I ended up removing the transects where some of the corresponding covariant data had NA values. This fixed the problem and allowed me to run the parboot function!

However, this means I had to remove 3 out of 102 transects. It's not a huge issue, since I don't have the corrsponding covariate data anyways, however, I'd ideally like the observations with their distances to be included as those transects may still influence the detection function.
Is there any way around this? 

Kery Marc

unread,
Feb 10, 2020, 3:34:03 PM2/10/20
to unma...@googlegroups.com
Dear Adrienne,

the cheapest means of dealing with missing covariate values in your situation is to simply replace the missings with the mean of the covariate values measured at the other sites. There are more elegant, and more correct ways of dealing with missing covariates, but they are all much more complicated in a sense, and since you only have a very small proportion of sites with missing covariates, doing this cheap solution will hardly affect anything.

Best regards  --- Marc



From: unma...@googlegroups.com [unma...@googlegroups.com] on behalf of Adrienne Beatrice [chit...@gmail.com]
Sent: 10 February 2020 21:27
To: unmarked
Subject: Re: [unmarked] Error in parboot: invalid size argument

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/6bd85456-067d-4955-9fe8-c83ddd07dfe2%40googlegroups.com.

Ken Kellner

unread,
Feb 10, 2020, 4:02:28 PM2/10/20
to unmarked
This looks like a bug to me, I filed a report here:

To unsubscribe from this group and stop receiving emails from it, send an email to unm...@googlegroups.com.

Adrienne Beatrice

unread,
Feb 11, 2020, 11:20:16 AM2/11/20
to unmarked
That does seem to the be issue I am referring to Ken.
I think a quick and dirty method like Marc describes is reasonable way to correct for the issue given the low number of transects it impacts.
Thank you all for your input. It is greatly appreciated!

-Adrienne

Jim Baldwin

unread,
Feb 11, 2020, 11:45:25 AM2/11/20
to unma...@googlegroups.com
I am much more conservative than Marc.  Unless one could justify (to others and not just to yourself) that the reason for missing data was not related to the factors being investigated, I would not plug in the averages or use fancier imputation methods.  If one can justify the use of the imputation methods, that's great.  But not at all just to make software not print errors or warnings.  This is especially true if one might face court challenges if some management decisions were to be based on your analysis.

Jim


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/85d701c7-d4ab-4e57-bb9c-bf2a44cea0e3%40googlegroups.com.

Kery Marc

unread,
Feb 11, 2020, 12:10:02 PM2/11/20
to unma...@googlegroups.com
Dear Jim,

thanks for your perspective on this. So what would you do in such an example: throw out the cases with missing covariates ?

Best regards  --- Marc



From: unma...@googlegroups.com [unma...@googlegroups.com] on behalf of Jim Baldwin [jbald...@gmail.com]
Sent: 11 February 2020 17:45
To: unma...@googlegroups.com

Adrienne Beatrice

unread,
Feb 11, 2020, 12:28:05 PM2/11/20
to unmarked
That's a fair point Jim.
The reason for the missing values is because those data collection days are missing.
The missing values are only for my vegetation covariates (mean basal area, shannon diversity index), because, unfortunately, the survey data when those transects were walked has been lost.
In this case, it seems reasonable to fill in the mean.
Would you agree?

Jim Baldwin

unread,
Feb 11, 2020, 12:28:59 PM2/11/20
to unma...@googlegroups.com
Admittedly, I'm a bit cranky in my old age.

If this was for a Master's Thesis or a homework problem, the consequences of any action would likely not be major no matter what was done.  But hopefully one would be able to come to the conclusion that the data was "missing at random" and just toss those sites (because there are so few sites) or perform some simple imputation.

If this was for supporting an upcoming land management decision (or a medical decision for a pharmaceutical company), I would investigate and document the cause for the "missingness."  Depending on the kind of "missingness", I'd make a decision of whether to perform some sort of imputation, drop the offending sites, or not do the analysis at all and treat that as a lesson learned.  (Yes, I know few would feel they have the luxury of not doing the analysis.  But that might be considered more often than not.)  If the analysis is still to be performed and reported, then the missingness and the associated actions need to be well documented and justified and prominently included in the report.

Jim


Kery Marc

unread,
Feb 12, 2020, 2:58:47 AM2/12/20
to unma...@googlegroups.com

Dear Jim,

 

very thoughtful comments, thanks. These are big and important considerations and you are quite right to remind people of this big-picture perspective.

 

On the other hand, since Adrienne may not end up in a congress hearing with her study, I still think she could just choose the cheap solution and either mean-impute or drop. And since it’s such a minute part of her data set that’s missing, it won’t materially matter probably.

 

Best regards  - Marc

Jim Baldwin

unread,
Feb 12, 2020, 9:15:43 AM2/12/20
to unma...@googlegroups.com
No disagreement here.  Your advice is good.

As a statistician I just feel the need to remind (nag? badger?) folks of the difference between the willingness and the ability do make certain assumptions or perform certain actions.

Jim

Adrienne Beatrice

unread,
Feb 12, 2020, 2:09:47 PM2/12/20
to unmarked
Thank you both for your input.
I really appreciate the discussion and the reminder that every action should be done with an appreciation of the repercussions.
-Adrienne
+   observed <- getY(g.g...@data)

--
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 unma...@googlegroups.com.

--
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 unma...@googlegroups.com.

--
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 unma...@googlegroups.com.

--
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 unma...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages