hmsc-r / HMSC

GNU General Public License v3.0
99 stars 36 forks source link

MCMC convergence for spatial random effects #129

Open cabuelow opened 2 years ago

cabuelow commented 2 years ago

Hello,

I'm using hmsc to model the response of 43 waterbird species to river threats in 133 basins (watershed boundaries). I'm having trouble fitting the model with a spatial random effect; the mcmc chains are not mixing or sampling well.

The code and data for fitting the model are here: https://github.com/cabuelow/waterbird-multivar-glm. If you have any advice for improving convergence, it would be great to know.

Many thanks in advance, Christina

ovaskain commented 2 years ago

Hi,

I had a quick look at your script and did not find anything especially suspicious, everything looked like nicely organized. I did not find those MCMC mixing statistics (e.g. Gelman factors) from your github, are those visible somewhere?

Otso

From: Christina @.> Sent: perjantai 10. joulukuuta 2021 1:03 To: hmsc-r/HMSC @.> Cc: Subscribed @.***> Subject: [hmsc-r/HMSC] MCMC convergence for spatial random effects (Issue #129)

Hello,

I'm using hmsc to model the response of 43 waterbird species to river threats in 133 basins (watershed boundaries). I'm having trouble fitting the model with a spatial random effect; the mcmc chains are not mixing or sampling well.

The code and data for fitting the model are here: https://github.com/cabuelow/waterbird-multivar-glm. If you have any advice for improving convergence, it would be great to know.

Many thanks in advance, Christina

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/hmsc-r/HMSC/issues/129, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEIYMZR27LAHYHM6RM2RCE3UQEYTZANCNFSM5JXWNJJQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

cabuelow commented 2 years ago

Thank-you for taking a look at the scripts - I appreciate it. Also, my apologies, I should have clarified that the I am only struggling to obtain convergence for the alpha parameter. The effective sample sizes and potential scale reduction factors for the beta and omega parameters are fine.

I have placed an image of the MCMC trace and posterior density plots for the alpha parameters on the github repo: https://github.com/cabuelow/waterbird-multivar-glm

The posterior density plots seem to suggest that the scale of spatial autocorrelation is close to 0 - could this contribute to poor convergence on this parameter? Also, if the scale of the spatial effect is in fact near 0, would it be appropriate to exclude a spatial random effect from the final model?

ovaskain commented 2 years ago

Hi,

Out of these, factor 1 is most important (factors are ordered according to decreasing relevance). What we see is that one chain (green) is stuck to zero whereas the remaining two show very nice mixing around some non-zero value. Getting occasionally stuck to zero (as happens with chains 3-5) is expected because zero has probability 0.5 in the prior. What is not so nice is that for factor 1 one chain is all the time in zero and the others are not – that is an indication of non-ideal mixing. If it is important to quantify the probability of spatial signal AND feasible for you to run the chains still 10 times longer (or run more chains in parallel), you could do that. But there is no evidence against spatial signal / not reason to drop the random effect.

O2

From: Christina @.> Sent: sunnuntai 12. joulukuuta 2021 23:33 To: hmsc-r/HMSC @.> Cc: Ovaskainen, Otso T @.>; Comment @.> Subject: Re: [hmsc-r/HMSC] MCMC convergence for spatial random effects (Issue #129)

Thank-you for taking a look at the scripts - I appreciate it. Also, my apologies, I should have clarified that the I am only struggling to obtain convergence for the alpha parameter. The effective sample sizes and potential scale reduction factors for the beta and omega parameters are fine.

I have placed an image of the MCMC trace and posterior density plots for the alpha parameters on the github repo: https://github.com/cabuelow/waterbird-multivar-glm

The posterior density plots seem to suggest that spatial autocorrelation is close to 0 - could this contribute to poor convergence on this parameter? Also, if the scale of the spatial effect is in fact near 0, would it be appropriate to exclude a spatial random effect from the final model?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/hmsc-r/HMSC/issues/129#issuecomment-991974484, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEIYMZQ465ATEYF3NFEQ3MDUQUIKPANCNFSM5JXWNJJQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

cabuelow commented 2 years ago

Thanks Otso, that's very helpful. I went ahead and ran the 4 chains 10 times longer, but unfortunately one of the chains for factor 1 is still stuck at zero. For the purposes of this analysis, it is not of great importance that we quantify the probability of the spatial signal. Would you recommend keeping the spatial random effect as is, despite non-ideal mixing? Or would it be best to try an alternative approach to account for spatial-autocorrelation?

jarioksa commented 2 years ago

I think the idea of giving extra weight (0.5) to zero is to allow suggesting "no spatial dependence" instead of having tiny and unimportant near-zero values which actually were better interpreted as "no spatial dependence".

ovaskain commented 2 years ago

I would surely keep the spatial random effect in the model in spite of the non-ideal mixing, as with that you do account for spatial autocorrelation. Even if the estimate of the alpha parameter may not be fully reliable, you do have there the factors that capture spatial variation.

Best,

Otso

From: Christina @.> Sent: keskiviikko 15. joulukuuta 2021 5:40 To: hmsc-r/HMSC @.> Cc: Ovaskainen, Otso T @.>; Comment @.> Subject: Re: [hmsc-r/HMSC] MCMC convergence for spatial random effects (Issue #129)

Thanks Otso, that's very helpful. I went ahead and ran the 4 chains 10 times longer, but unfortunately one of the chains for factor 1 is still stuck at zero. For the purposes of this analysis, it is not of great importance that we quantify the probability of the spatial signal. Would you recommend keeping the spatial random effect as is, despite non-ideal mixing? Or would it be best to try an alternative approach to account for spatial-autocorrelation?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/hmsc-r/HMSC/issues/129#issuecomment-994262348, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEIYMZWFDXE4HAURZFPRIWDURAEYPANCNFSM5JXWNJJQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

cabuelow commented 2 years ago

Thanks so much, it's been very helpful being able to get such quick answers to questions while using hmsc, and I'm really enjoying learning how to fit jsdm's with this package. I'll keep the spatial random effect in the model above.