biocore / BIRDMAn

Bayesian Inferential Regression for Differential Microbiome Analysis
BSD 3-Clause "New" or "Revised" License
22 stars 5 forks source link

How to include random variables in the formula #83

Open PaulaEterovick opened 1 year ago

PaulaEterovick commented 1 year ago

Dear @gibsramen and @mortonjt,

I built a formula to look for the effects of two variables likely affecting tadpole gut microbiome: temperature (with 5 levels) and nitrate concentration (with three levels), but I also have two random variables (aquarium and PCRreplicate) that I don't know how to include as random variables. I see you included random variables in your model in the original BIRDMAn paper, but I couldn't find the formula anywhere (sorry if I missed it).

This is my formula at the moment (without the random variables):

formula="C(Temperature, Diff, levels=['18C', '22C', '26C', '28C', 'Fluctuating'])*C(Nitrate, Diff, levels=['control','N50','N100'])"

Thank you very much for the availability to help Paula

mortonjt commented 1 year ago

Hi, you probably didnt find it because there was no formula. The random effects were directly specified in the model.

The easiest thing to do is to merge aquarium and PCRreplicate into a single column and use the negative Binomial lme https://github.com/biocore/BIRDMAn/blob/main/birdman/templates/negative_binomial_lme.stan

Alternatively you can build your own custom stan model from scratch, which is more work, but would give you more control over the priors specified over your two random vars

On Tue, Aug 22, 2023 at 8:48 AM Paula Cabral Eterovick < @.***> wrote:

Dear @gibsramen https://github.com/gibsramen and @mortonjt https://github.com/mortonjt,

I built a formula to look for the effects of two variables likely affecting tadpole gut microbiome: temperature (with 5 levels) and nitrate concentration (with three levels), but I also have two random variables (aquarium and PCRreplicate) that I don't know how to include as random variables. I see you included random variables in your model in the original BIRDMAn paper, but I couldn't find the formula anywhere (sorry if I missed it).

This is my formula at the moment (without the random variables):

formula="C(Temperature, Diff, levels=['18C', '22C', '26C', '28C', 'Fluctuating'])*C(Nitrate, Diff, levels=['control','N50','N100'])"

Thank you very much for the availability to help Paula

— Reply to this email directly, view it on GitHub https://github.com/biocore/BIRDMAn/issues/83, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA75VXNFZ4V6EVROPY4L3JLXWRIZ7ANCNFSM6AAAAAA3ZNJGUI . You are receiving this because you were mentioned.Message ID: @.***>

PaulaEterovick commented 1 year ago

Dear @mortonjt, Thank you very much for the fast reply. Unfortunately I have no previous knowledge on programming and I can't understand how to apply this to my data. I can understand the notebook interface and I'm using this example for guidance. Is it possible to adapt it to my variables?

https://github.com/gibsramen/BIRDMAn-demo/blob/main/notebooks/default_model.ipynb

mortonjt commented 1 year ago

Its possible, but it would require understanding the codebase on top of edits. Youd need to swap out with the NegativeBinomialLME https://github.com/biocore/BIRDMAn/blob/main/birdman/default_models.py#L249

On Tue, Aug 22, 2023 at 3:02 PM Paula Cabral Eterovick < @.***> wrote:

Dear @mortonjt https://github.com/mortonjt, Thank you very much for the fast reply. Unfortunately I have no previous knowledge on programming and I can't understand how to apply this to my data. I can understand the notebook interface and I'm using this example for guidance. Is it possible to adapt it to my variables?

https://github.com/gibsramen/BIRDMAn-demo/blob/main/notebooks/default_model.ipynb

— Reply to this email directly, view it on GitHub https://github.com/biocore/BIRDMAn/issues/83#issuecomment-1688146154, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA75VXMRLPFRCANI6JNLJWTXWSUWZANCNFSM6AAAAAA3ZNJGUI . You are receiving this because you were mentioned.Message ID: @.***>

PaulaEterovick commented 1 year ago

Thank you very much, @mortonjt I am trying to use the model you suggested, but I just found the notebook in https://github.com/gibsramen/BIRDMAn-demo/blob/main/notebooks/custom_model_lme.ipynb as reference and I am missing something while specifying the variables (as the example is set for a variable with just two states and all individuals have samples from each). I have PCR replicates that work like this (two per individual), however what I really want to compare is not the PCR replicates, but either two variables (with 3 and 5 states) or the combination of both (with 15 states). Is there a notebook somewhere with an example that would be closer to my data? If not, is it feasible to tell me what cells need to be adjusted and how?