# Error in paste(lvl\_batch\[ind\_exposure & !ind\_exposure\_cat\], collapse = ", ") : object 'lvl\_batch' not found

**URL:** <https://forum.biobakery.org/t/error-in-paste-lvl-batch-ind-exposure-ind-exposure-cat-collapse-object-lvl-batch-not-found/2561>\
**Category:** MMUPHin\
**Created:** [September 6, 2021, 3:36pm UTC](https://forum.biobakery.org/t/error-in-paste-lvl-batch-ind-exposure-ind-exposure-cat-collapse-object-lvl-batch-not-found/2561 "2021-09-06T15:36:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fconstancias](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fconstancias/32/190_2.png) [@fconstancias](https://forum.biobakery.org/u/fconstancias)\
**Post date:** [September 6, 2021, 3:36pm UTC](https://forum.biobakery.org/t/error-in-paste-lvl-batch-ind-exposure-ind-exposure-cat-collapse-object-lvl-batch-not-found/2561/1 "2021-09-06T15:36:55Z")

</div>

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](https://bioconductor.org/packages/release/bioc/vignettes/MMUPHin/inst/doc/MMUPHin.html)] and used the adjust\_batch function easily.

```auto
  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:

```auto
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.

 ![MMUPHin](https://canada1.discourse-cdn.com/flex027/uploads/biobakery/original/2X/1/192bca682ff12835b89511433adb987baf9afd15.jpeg)

---

<div class="post-metadata">

**Author:** ![andrewGhazi](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/andrewghazi/32/2950_2.png) [@andrewGhazi](https://forum.biobakery.org/u/andrewGhazi)\
**Post date:** [September 6, 2021, 4:08pm UTC](https://forum.biobakery.org/t/error-in-paste-lvl-batch-ind-exposure-ind-exposure-cat-collapse-object-lvl-batch-not-found/2561/2 "2021-09-06T16:08:59Z")

</div>

@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"))`

---

<div class="post-metadata">

**Author:** ![sma](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@sma](https://forum.biobakery.org/u/sma)\
**Post date:** [September 8, 2021, 2:28pm UTC](https://forum.biobakery.org/t/error-in-paste-lvl-batch-ind-exposure-ind-exposure-cat-collapse-object-lvl-batch-not-found/2561/3 "2021-09-08T14:28:36Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![fconstancias](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/fconstancias/32/190_2.png) [@fconstancias](https://forum.biobakery.org/u/fconstancias)\
**Post date:** [September 17, 2021, 9:08am UTC](https://forum.biobakery.org/t/error-in-paste-lvl-batch-ind-exposure-ind-exposure-cat-collapse-object-lvl-batch-not-found/2561/4 "2021-09-17T09:08:40Z")

</div>

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
