brianstock / MixSIAR

A framework for Bayesian mixing models in R:
http://brianstock.github.io/MixSIAR/
91 stars 75 forks source link

Is it possible to define the order of categorial covariates? #337

Open chiating9283 opened 1 year ago

chiating9283 commented 1 year ago

Hello,

I've used MixSiar for to estimate the contribution of POM size classes to POM mixtures stable isotope composition. I would like to use season_yr as a categorial covariate to see if the contributions differed between seasons. The model converged and looks fine and consistent with nano-POM dominating in my system. However, when I show the interval plots, all the seasons are mixed like "winter 2010, winter 2011, spring 2010, spring 2011, summer 2010, summer 2011, autumn 2010, autumn 2011, etc" instead of "winter 2010, spring 2010, summer 2010, autumn 2010, winter 2011, spring 2011, summer 2011, autumn 2011 etc" on my figure. May you tell me how to order my categorial covariates so I wouldn't need to do it by hand please? Because I have 27 seasons so it's really hard to change everything by hand on the metafile with powerpoint.

Thank you very much contributionbyseason tif

brianstock commented 1 year ago

Hi,

I don't think you should have to manually modify after plotting. I would try manipulating the mixsiar output (data frame of posterior estimates), and you can always modify the code for the interval plot if needed.

On Wed, Mar 22, 2023, 9:01 AM chiating9283 @.***> wrote:

Hello,

I've used MixSiar for to estimate the contribution of POM size classes to POM mixtures stable isotope composition. I would like to use season_yr as a categorial covariate to see if the contributions differed between seasons. The model converged and looks fine and consistent with nano-POM dominating in my system. However, when I show the interval plots, all the seasons are mixed like "winter 2010, winter 2011, spring 2010, spring 2011, summer 2010, summer 2011, autumn 2010, autumn 2011, etc" instead of "winter 2010, spring 2010, summer 2010, autumn 2010, winter 2011, spring 2011, summer 2011, autumn 2011 etc" on my figure. May you tell me how to order my categorial covariates so I wouldn't need to do it by hand please? Because I have 27 seasons so it's really hard to change everything by hand on the metafile with powerpoint.

Thank you very much [image: contributionbyseason tif] https://user-images.githubusercontent.com/128579413/226833806-91c0c72a-df69-4b8f-9f70-1746bfdf6e2d.jpg

— Reply to this email directly, view it on GitHub https://github.com/brianstock/MixSIAR/issues/337, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHDA47TIQ62TYQOGTNS5JLW5KWU3ANCNFSM6AAAAAAWDOVWQI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

chiating9283 commented 1 year ago

Hi Brian, Thank you very much for you fast reply. I see. Can you give more instructions on how I can do that with a small example please? I tried to modify in the plot_interval function with "groupby" but I don't think it works. I'd also like to be sure if it's possible to define the order of the sources appearing on the interval figure such as "micro, nano, pico" instead of "nano, pico, micro" for example. Which line do we use to define please? Here I attach my example if needed. The script is in the txt file. tef.csv consumer.csv test.txt source.csv The R.data file is too big to be attached. If needed I'll send with a link.

Thank you very much!

Chia-Ting

brianstock commented 1 year ago

Hi Chia-Ting,

I think the issue is that MixSIAR reads in your mix/consumer data file and then calls factor() on the covariate column, so there is no way to tell MixSIAR to use a different order of the factor levels.

You could fork MixSIAR and make changes to the load_mix_data function on lines 139-153 where it defines the factor levels and labels. Or you could modify the plot_intervals function to be specific to what you need. Sorry, I don't have time to do this for you... good luck!

AndrewLJackson commented 1 year ago

you could probably work with the raw output and create your own plots summarising the posterior distributions. This way you could redefine the order of the factor variables to your preference. There are instructions in the manual and vignettes on how to do this https://github.com/brianstock/MixSIAR/blob/master/inst/mixsiar_manual_small.pdf