data formatting for gdistsamp()

42 views
Skip to first unread message

Marc Kery

unread,
Oct 13, 2023, 5:26:59 AM10/13/23
to unma...@googlegroups.com
Dear all,

I have a formatting problem with a generalized HDS model, i.e., gdistsamp(). We have 6 surveys with 3 distance classes at a total of 225 sites.

Formatting the unmarked data frame seems to work, see part of the summary:

unmarkedFrame Object

225 sites
Maximum number of observations per site: 18
Mean number of observations per site: 17.97
Number of primary survey periods: 6
Number of secondary survey periods: 1
Sites with at least one detection: 129

Tabulation of y observations:
   0    1    2    3 <NA>
3445  527   63    9    6

.......

Yearly-site-level covariates:
    observer          pow           licz        date      
 Min.   :1.000   M      :450   Min.   :1   Min.   :-1.00  
 1st Qu.:1.000   C      :420   1st Qu.:2   1st Qu.:17.00  
 Median :2.000   W      :360   Median :3   Median :31.00  
 Mean   :1.993   K      :300   Mean   :3   Mean   :32.19  
 3rd Qu.:3.000   L      :268   3rd Qu.:4   3rd Qu.:48.00  
 Max.   :3.000   (Other):448   Max.   :5   Max.   :65.00  
 NA's   :4       NA's   :  4               NA's   :4      

Then, we try to fit a simple model ....

fm1hn <- gdistsamp(lambdaformula = ~1, phiformula = ~1, 

   pformula = ~1, keyfun = "halfnorm", output = "density", unitsOut = "ha", 

   mixture = "P", K = 50, se = TRUE, data = umf, method = 'BFGS', 

  control = list(trace = TRUE, REPORT = 1))

... on which we get the following error:
Error in data.frame(..., check.names = FALSE) :
  arguments imply differing number of rows: 2250, 1350

We do have a couple missing values both in the response and in the yearly site covariates. Would that be the source of the problem ?

Thanks and best regards  --- Marc





Ken Kellner

unread,
Oct 13, 2023, 7:42:49 AM10/13/23
to unma...@googlegroups.com
Hi Marc,

gdistsamp should just drop sites with missing values, rather than give an error like you are seeing. I haven't been able to
replicate your issue with testing data. I think I have to look at your specific unmarked frame (which looks correct) to see if there is something unique about it - can you email it to me as an Rdata or Rds file?

Thanks

Ken
> --
> *** Three hierarchical modeling email lists ***
> (1) unmarked (this list): for questions specific to the R package unmarked
> (2) SCR: for design and Bayesian or non-bayesian analysis of spatial capture-recapture
> (3) HMecology: for everything else, especially material covered in the books by Royle & Dorazio (2008), Kéry & Schaub (2012), Kéry & Royle (2016, 2021) and Schaub & Kéry (2022)
> ---
> 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/ZR0P278MB08697C410EDAD6F695FCA16CEBD2A%40ZR0P278MB0869.CHEP278.PROD.OUTLOOK.COM.

Jeffrey Royle

unread,
Oct 13, 2023, 8:00:19 AM10/13/23
to unma...@googlegroups.com
hi Marc,
 not exactly sure about this one but I have seen that error before -- my only thought right now is it might be due to a data structure problem, like having a dataframe when a matrix is expected or something peculiar like that. Anyhow I'd be glad to take a look at this this afternoon if you send me the materials.
regards
andy


Ken Kellner

unread,
Oct 13, 2023, 8:42:48 AM10/13/23
to unma...@googlegroups.com
Hi Marc,

There seem to be two problems here -

1. The number of values in yearlySiteCovs doesn't match the observation data. There's 2250 values in the yearlySiteCovs, but there should be 225 (num sites) * 6 (num periods) = 1350. Probably this should have been caught at an earlier stage when making the unmarked frame.

2. The distance breaks have an issue. They are c(0, 50, 10, 150) but presumably should be c(0, 50, 100, 150).

Not sure exactly how to fix (1) without knowing the dataset but if you just subset to the first 1350 rows and fix the distance breaks, the model runs.

Ken
> > <https://groups.google.com/d/msgid/unmarked/ZR0P278MB08697C410EDAD6F695FCA16CEBD2A%40ZR0P278MB0869.CHEP278.PROD.OUTLOOK.COM?utm_medium=email&utm_source=footer>
> > .
> >
>
> --
> *** Three hierarchical modeling email lists ***
> (1) unmarked (this list): for questions specific to the R package unmarked
> (2) SCR: for design and Bayesian or non-bayesian analysis of spatial capture-recapture
> (3) HMecology: for everything else, especially material covered in the books by Royle & Dorazio (2008), Kéry & Schaub (2012), Kéry & Royle (2016, 2021) and Schaub & Kéry (2022)
> ---
> 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/CAE%2BwgF31mr15TKbs8zC4vXzM1upU75KEW-8iXmNt1%3Dey%2BC2kDg%40mail.gmail.com.

Marc Kery

unread,
Oct 13, 2023, 8:48:48 AM10/13/23
to unma...@googlegroups.com
Dear Ken,

that's embarrassing .... thanks a lot for helping so quickly ! Will look into these.

Best regards  --- Marc




From: unma...@googlegroups.com <unma...@googlegroups.com> on behalf of Ken Kellner <con...@kenkellner.com>
Sent: Friday, October 13, 2023 14:42
To: unma...@googlegroups.com <unma...@googlegroups.com>
Subject: Re: [unmarked] data formatting for gdistsamp()
 

Marc Kery

unread,
Oct 13, 2023, 10:49:08 AM10/13/23
to unma...@googlegroups.com
Dear Ken, Andy,

thanks for your help. Indeed, the two problems that Ken pointed out were at the root of our problem. We had subsetted the response data (y), but failed to make the corresponding subsetting also for the covariates (and strangely, this was not flagged as an error when forming the unmarked data frame).

Happy week-end,

Marc



From: unma...@googlegroups.com <unma...@googlegroups.com> on behalf of Marc Kery <marc...@vogelwarte.ch>
Sent: Friday, October 13, 2023 14:48

Ken Kellner

unread,
Oct 13, 2023, 11:09:06 AM10/13/23
to unma...@googlegroups.com
I'll add a check during unmarked frame construction to hopefully avoid this issue in the future.

Ken
> To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com<mailto:unmarked+u...@googlegroups.com>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/unmarked/ZR0P278MB0869CDBFB2D4ECF982BE5C99EBD2A%40ZR0P278MB0869.CHEP278.PROD.OUTLOOK.COM<https://groups.google.com/d/msgid/unmarked/ZR0P278MB0869CDBFB2D4ECF982BE5C99EBD2A%40ZR0P278MB0869.CHEP278.PROD.OUTLOOK.COM?utm_medium=email&utm_source=footer>.
>
> --
> *** Three hierarchical modeling email lists ***
> (1) unmarked (this list): for questions specific to the R package unmarked
> (2) SCR: for design and Bayesian or non-bayesian analysis of spatial capture-recapture
> (3) HMecology: for everything else, especially material covered in the books by Royle & Dorazio (2008), Kéry & Schaub (2012), Kéry & Royle (2016, 2021) and Schaub & Kéry (2022)
> ---
> 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/ZR0P278MB08690EEBC996A2C48F335504EBD2A%40ZR0P278MB0869.CHEP278.PROD.OUTLOOK.COM.

Marc Kery

unread,
Oct 13, 2023, 11:17:53 AM10/13/23
to unma...@googlegroups.com
Excellent, thanks !

Marc


Sent: Friday, October 13, 2023 17:09
Reply all
Reply to author
Forward
0 new messages