Error in paste(lvl_batch[ind_exposure & !ind_exposure_cat], collapse = ", ") : object 'lvl_batch' not found

Dear bioBakery team/ users,

I am analyzing some 16S metabarcoding data assessing the effect of different treatments (6 + control levels) on mouse microbiota using in the vitro fermentation system. Since fermentations (i.e., experiment) were run using different donor microbiota and several times I would like to ‘remove’ the donor effect (i.e., experiment) which explains most of the variation in the community [PERMANOVA R2experiment > R2 treatement] to combine the datasets and focus on the treatment and use the experiment as replicates.

I followed the MMUPHin tutorial[Performing meta-analyses of microbiome studies with MMUPHin] and used the adjust_batch function easily.

  fit_adjust_batch <- MMUPHin::adjust_batch(feature_abd = ps %>% otu_table(),
                                            batch = "experiment",
                                            covariates = "treatment",
                                            data = ps %>% sample_data() %>% data.frame(),
                                            control = list(verbose = TRUE))
 

According to PERMANOVA using Aitchinson distance MMUPHin::adjust_batch slightly removed some expeirment related variation (57% vs 61% initially) maintaining a treatment-related source of variation (4.9% vs 4.7% initially).

I am wondering what determine the hability of MMUPHin::adjust_batch to remove the batch related sources of variations.

I am also interested in applying MMUPHin::lm_meta on the same dataset but got the following error:

Warning in check_batch(df_batch[[batch]], min_n_batch = 2) :
  Batch variable is not a factor as provided and will be converted to one.
Found 2 batches
Error in paste(lvl_batch[ind_exposure & !ind_exposure_cat], collapse = ", ") : 
  object 'lvl_batch' not found

Any idea how to solve this? Thanks a ton.

Enclosed some PCoA / PERMANOVA / heatmap.

@sma Should be able to speak to whether it’s appropriate to use adjust_batch for experimental batches rather than separate studies.

I’m not exactly sure what is causing the issue with lm_meta, but I think if you modify your input so that the exposure variable to be a factor with consistent levels across batches, that should fix it. You should be able to see inconsistency in the exposure variable across batches if you run something like this (rename variables in the call to select as appropriate):

input_df %>% select(batch_variable, exposure_variable) %>% unique

Recode the exposure variable to consistently indicate “nontreatment” or “treatment”, then it to be a factor like so:

input_df$exposure_variable = factor(exposure_variable, levels = c("nontreatment", "treatment"))

Hi,

MMUPHin should be able to perform batch normalization as well. My recommendation would be:

  1. Within each donor, perform batch normalization. This is “conditioning” on the donor effects, so that the model doesn’t have to worry about them. Depending on your study design, you might or might not need to adjust for covariates. If batches were balanced between treatments, then I wouldn’t adjust for treatment effects.

  2. Then perform normalization for the donor effects, by pooling the per-donor normalized data together, just as for the original data.

Hope this helps!

Thanks a lot. The error was generated because I had more than two levels. Is it possible to run pairwise test to compare Treatment A, B and C? And not just Treatment vs/ Control.

Best