Random effects in Package Unmarked?

2,000 views
Skip to first unread message

Shannon

unread,
Sep 8, 2011, 7:36:31 PM9/8/11
to unmarked
Wondering if package unmarked as the capacity to include random (as
opposed to fixed) effects in models? For example a random effect of
site or route. I'm using function pcount. I actually just started
exploring this package. I can do this analysis using R2WinBUGS, but I
was kind of hoping for a simpler non-WinBUGS way to do this analysis
so I can pass it off to a colleague and let them do their own analysis.

Andy Royle

unread,
Sep 8, 2011, 8:29:30 PM9/8/11
to unma...@googlegroups.com

hi Shannon,
 at this point in time, it does not although we would like to go in that direction in the future.  I would recommend WinBUGS.
regards,
andy

 
-----unma...@googlegroups.com wrote: -----

To: unmarked <unma...@googlegroups.com>
From: Shannon <shannon...@gmail.com>
Sent by: unma...@googlegroups.com
Date: 09/08/2011 07:36PM
Subject: [unmarked] Random effects in Package Unmarked?

Guillaume Souchay

unread,
Oct 20, 2016, 4:14:31 PM10/20/16
to unmarked
Hi Andy,

I was wondering if the project to include the possibility to use random effect in Unmarked was still not considered. 
The add of random effect (e.g. temporal random effect) is easly done using BUGS/JAGS but it can be quite time consuming when dealing with very large dataset.
So, any news on this subject?

Cheers,
Guillaume

Jeffrey Royle

unread,
Oct 20, 2016, 7:03:58 PM10/20/16
to unma...@googlegroups.com
Dear Guillaume,
 I agree this would be a useful advance but it is such a major change in technology that it's highly unlikely to ever happen unless we find an extremely ambitious graduate student to pursue that or else, by some miracle, receive a huge chunk of funding to hire a post-doc. 

 Right now we're focused on cleaning up and completely the core technologies (closed and open N-mixture, distance sampling, multinomial mixtures, occupancy models).

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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Guillaume Souchay

unread,
Oct 24, 2016, 4:06:49 AM10/24/16
to unmarked
Dear Andy,

Thanks for the update.
Good luck to find some funding, anyway, thanks for the great job accomplished until now and good luck for the cleaning ! 

Cheers,

Guillaume
To unsubscribe from this group and stop receiving emails from it, send an email to unmarked+u...@googlegroups.com.

Ben Wilson

unread,
Jun 13, 2020, 3:09:05 PM6/13/20
to unmarked
Andy,

I just wanted to confirm that there is still not a way to use random effects in Unmarked? 

Thanks for all you do,
Ben

Kery Marc

unread,
Jun 13, 2020, 3:10:51 PM6/13/20
to unma...@googlegroups.com
Nope. Have to go down the Bayesian route.



From: unma...@googlegroups.com [unma...@googlegroups.com] on behalf of Ben Wilson [bwil...@gmail.com]
Sent: 13 June 2020 20:46
To: unmarked
Subject: Re: [unmarked] Random effects in Package Unmarked?

Ken Kellner

unread,
Jun 13, 2020, 4:54:40 PM6/13/20
to unmarked
I've been working on a new package that might eventually help address this gap. It's meant to be a sort of middle ground between unmarked and BUGS. It has an interface nearly identical to unmarked, that uses Stan in the background to fit the models. The main advantages are that you can fit models with random effects (using lme4 syntax), get posterior distributions, and have access to all the cool cutting edge diagnostic stuff in rstan and related packages.

For example, you can fit a single-season occupancy model with a random effect on psi like this:

library(ubms)

umf <- unmarkedFrameOccu(y=y, siteCovs=dat_occ, obsCovs=dat_p)

ufit <- stan_occu(~x2~x1+ (1 | group), umf, chains=3)

which gives:


Call:
stan_occu(formula = ~x2 ~ x1 + (1 | group), data = umf, chains = 3)

Occupancy:
                Estimate    SD   2.5%  97.5% n_eff Rhat
(Intercept)        0.215 0.270 -0.327  0.740   979 1.01
x1                -0.499 0.114 -0.730 -0.283  3695 1.00
sigma [1|group]    1.241 0.253  0.825  1.819  1772 1.00

Detection:
            Estimate     SD  2.5% 97.5% n_eff  Rhat
(Intercept)    0.329 0.0619 0.206 0.447  4147 0.999
x2             0.532 0.0588 0.418 0.647  4514 1.000

LOOIC: 2310.822

While not as fast as unmarked, it can be pretty fast due to the efficient Stan sampler and because the likelihoods are marginalized. So far I've only implemented Stan versions of occu(), occuRN(), and pcount() but working to add more. If anyone wants to test or contribute, here's the github repo:


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

joaquin...@gmail.com

unread,
Jul 11, 2022, 2:17:06 PM7/11/22
to unmarked
Dear Ken, I'm trying to fit this random effect model with unmarked using ubms but it doesn't work. It says that Stan model 'occu' does not contain samples. Some chains had errors. I runned your example and works fine. Do you have any idea of the potential problem?

I have just one two-level factor covariate for abundance and no detectability covariate. My random effect is the farm identity, as multiple observations were taken in the same farm.

Thanks in advance,

joaquin



Marc Kery

unread,
Jul 11, 2022, 2:24:20 PM7/11/22
to unmarked
Dear Joaquin,

do you have just two farms ? If so, then I would not treat farm as a random-effects factor. And perhaps that is the reason for why ubms throws an error.

Best regards  -- Marc

From: unma...@googlegroups.com <unma...@googlegroups.com> on behalf of joaquin...@gmail.com <joaquin...@gmail.com>
Sent: Monday, July 11, 2022 20:17
To: unmarked <unma...@googlegroups.com>
--
*** 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.

Joaquín Aldabe

unread,
Jul 11, 2022, 2:36:36 PM7/11/22
to unma...@googlegroups.com
Hi Marc, thanks for your response. I have 6 farms. I counted birds on each farm in two different seasons and want to compare abundance differences between seasons. In each farm I took several counts.

Best,
joaquin

You received this message because you are subscribed to a topic in the Google Groups "unmarked" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/unmarked/dChRYcvox6U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to unmarked+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/unmarked/ZR0P278MB08697B6E068D4C572A86F4C8EB879%40ZR0P278MB0869.CHEP278.PROD.OUTLOOK.COM.


--
Joaquín Aldabe

Departamento de Sistemas Agrarios y Paisajes Culturales
Centro Universitario de la Región Este, Universidad de la República, Uruguay
Ruta 15 (y Ruta 9), Km 28.500, Departamento de Rocha  
                                                          https://sites.google.com/site/perfilprofesionaljoaquinaldabe/home

Ken Kellner

unread,
Jul 11, 2022, 3:19:01 PM7/11/22
to unma...@googlegroups.com
Hi Joaquin,

Can you copy and send the complete message you get when you try to run the model?

Ken

On Mon, Jul 11, 2022 at 03:36:19PM -0300, Joaquín Aldabe wrote:
> Hi Marc, thanks for your response. I have 6 farms. I counted birds on each
> farm in two different seasons and want to compare abundance differences
> between seasons. In each farm I took several counts.
>
> Best,
> joaquin
>
> El lun, 11 jul 2022 a las 15:24, Marc Kery (<marc...@vogelwarte.ch>)
> escribió:
>
> > Dear Joaquin,
> >
> > do you have just two farms ? If so, then I would not treat farm as a
> > random-effects factor. And perhaps that is the reason for why ubms throws
> > an error.
> >
> > Best regards -- Marc
> > ------------------------------
> > *From:* unma...@googlegroups.com <unma...@googlegroups.com> on behalf
> > of joaquin...@gmail.com <joaquin...@gmail.com>
> > *Sent:* Monday, July 11, 2022 20:17
> > *To:* unmarked <unma...@googlegroups.com>
> > *Subject:* Re: [unmarked] Random effects in Package Unmarked?
> > ------------------------------
> > *From:* unma...@googlegroups.com [unma...@googlegroups.com] on behalf of
> > Ben Wilson [bwil...@gmail.com]
> > *Sent:* 13 June 2020 20:46
> > *To:* unmarked
> > *Subject:* Re: [unmarked] Random effects in Package Unmarked?
> > <https://groups.google.com/d/msgid/unmarked/f3b57970-6658-42d1-aa49-0ef9ab4c4542o%40googlegroups.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/f42e9987-43ef-4109-a833-e1140398e9cen%40googlegroups.com
> > <https://groups.google.com/d/msgid/unmarked/f42e9987-43ef-4109-a833-e1140398e9cen%40googlegroups.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 a topic in the
> > Google Groups "unmarked" group.
> > To unsubscribe from this topic, visit
> > https://groups.google.com/d/topic/unmarked/dChRYcvox6U/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to
> > unmarked+u...@googlegroups.com.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/unmarked/ZR0P278MB08697B6E068D4C572A86F4C8EB879%40ZR0P278MB0869.CHEP278.PROD.OUTLOOK.COM
> > <https://groups.google.com/d/msgid/unmarked/ZR0P278MB08697B6E068D4C572A86F4C8EB879%40ZR0P278MB0869.CHEP278.PROD.OUTLOOK.COM?utm_medium=email&utm_source=footer>
> > .
> >
>
>
> --
> *Joaquín Aldabe*
>
> Departamento de Sistemas Agrarios y Paisajes Culturales
> Centro Universitario de la Región Este, Universidad de la República, Uruguay
> Ruta 15 (y Ruta 9), Km 28.500, Departamento de Rocha
>
> https://sites.google.com/site/perfilprofesionaljoaquinaldabe/home
>
> --
> *** 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/CAMM93%3D%2BsiBouhw%2B5sRzQ%2B8Wbv295az0LiAG9h5hmLLpnuCkRyA%40mail.gmail.com.

Joaquín Aldabe

unread,
Jul 11, 2022, 3:24:20 PM7/11/22
to unma...@googlegroups.com
sure:

fm <- stan_occu(~1 ~Temporada + (1|Propietario), umf1, chains=3, cores=3)#this is my model
here are whatever error messages were returned
[[1]]

Stan model 'occu' does not contain samples.

[[2]]

Stan model 'occu' does not contain samples.

[[3]]

Stan model 'occu' does not contain samples.

Error: Fitting model failed
In addition: Warning message:
In .local(object, ...) :
  some chains had errors; consider specifying chains = 1 to debug



--
Joaquín Aldabe

Ken Kellner

unread,
Jul 11, 2022, 3:39:21 PM7/11/22
to unma...@googlegroups.com
I'd probably have to look at this myself to be able to help. Can you send the umf1 object as an .Rdata or .Rds file to me off-list? email: contact at kenkellner.com
> > https://groups.google.com/d/msgid/unmarked/Ysx3nY8rAmXmMGnJ%40COYOTE.
> >
>
>
> --
> *Joaquín Aldabe*
>
> Departamento de Sistemas Agrarios y Paisajes Culturales
> Centro Universitario de la Región Este, Universidad de la República, Uruguay
> Ruta 15 (y Ruta 9), Km 28.500, Departamento de Rocha
>
> https://sites.google.com/site/perfilprofesionaljoaquinaldabe/home
>
> --
> *** 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/CAMM93%3DKnmTbGm%3DX5YdTc8ae1XuMZSrLGtjvuUEYrat3vkZX1zw%40mail.gmail.com.

Ken Kellner

unread,
Jul 12, 2022, 11:15:26 AM7/12/22
to unma...@googlegroups.com
Following up on this, the issue was that the y-matrix was a matrix of counts, not 1/0 presence-absence. unmarked will automatically truncate count data to presence-absence when running an occupancy analysis, but ubms does not.

Ken
> To view this discussion on the web visit https://groups.google.com/d/msgid/unmarked/Ysx8Yt9pdWGdgbL4%40COYOTE.
Reply all
Reply to author
Forward
0 new messages