david-barnett / microViz

R package for microbiome data visualization and statistics. Uses phyloseq, vegan and the tidyverse. Docker image available.
https://david-barnett.github.io/microViz/
GNU General Public License v3.0
102 stars 11 forks source link

Change levels for LM modeling in tax_tree #175

Closed scilexenko closed 3 weeks ago

scilexenko commented 1 month ago

Hi David,

I hope you’re doing well!

I’m encountering an issue with my data, which consists of four levels. I’m trying to change the comparison level to generate different heat trees. I attempted to relevel the factor within my phyloseq object using the following code:

sample_data(phyloseq_g_zz)$Code <- factor(sample_data(phyloseq_g_zz)$Code, levels = c("SNA", "CNA", "SMA", "SVA"))

lm_models2 <- phyloseq_g_zz  %>% 
  taxatree_models(
    ranks = c("Phylum", "Class", "Order", "Family", "Genus", "Species"),
    trans = "log2", trans_args = list(add = "halfmin"),
    formula = ~ Code,
    #variables = "Code", type = lm # modelling function
  ) %>%
  taxatree_models2stats(.keep_models = F) 

However, this doesn’t seem to work as expected when using taxatree_models. Would you be able to help me with this? I would greatly appreciate any guidance you can provide.

Thank you so much in advance! Best regards, Ivan

david-barnett commented 3 weeks ago

Hi Ivan

Without digging into the code, I would guess that taxatree_models probably doesn't sensibly handle factors with more than 2 levels, because I designed it to feed into the taxatree plots. These plots don't really make sense for nominal categorical variables.

You could try converting your factor into 3 dummy variables. This would at least give you directions for associations. But overall, it might not be possible to use (only) taxatree models to achieve your aims.

best David