# Error "\`x\` and \`y\` must share the same src," when trying to include covariates in lm\_meta

**URL:** https://forum.biobakery.org/t/error-x-and-y-must-share-the-same-src-when-trying-to-include-covariates-in-lm-meta/2533
**Category:** MMUPHin
**Created:** [August 30, 2021, 5:59pm UTC](https://forum.biobakery.org/t/error-x-and-y-must-share-the-same-src-when-trying-to-include-covariates-in-lm-meta/2533 "2021-08-30T17:59:28Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![drelo](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/drelo/32/566_2.png) [@drelo](https://forum.biobakery.org/u/drelo)
#### Post date: [August 30, 2021, 5:59pm UTC](https://forum.biobakery.org/t/error-x-and-y-must-share-the-same-src-when-trying-to-include-covariates-in-lm-meta/2533/1 "2021-08-30T17:59:28Z")

</div>

Dear all,

I already used MMUPHin with MetaPhlAn data but now while including HUMAnN pathways results and after reading a little more about the program I tried to include 2 covariates like “age”, “sex”. These covariates are not present in one study. I also tried MaAsLin2 to explore this results too.

When I try the tutorial with my own data…

```auto
pathway <- read_tsv("~/andres/HUMAnN/mmuphin_pathsX.tsv")
MeTa <- read_tsv("~/andres/HUMAnN/mmuphin_metadataX.csv")

pathway <- pathway %>% map_if(is.numeric, ~./sum(.)) %>% as.data.frame() %>% 
  column_to_rownames("ID") %>% as.matrix() # transform the data between 0-1
MeTa <- MeTa %>% column_to_rownames("ID") # with rownames

fit_lm_cov <- lm_meta(feature_abd = pathway,
                      batch = "study",
                      exposure = "response",
                      covariates = c("age", "sex"),
                      data = MeTa,
                      control = list(verbose = FALSE))

```

I got this error…

```auto
Error: `x` and `y` must share the same src, set `copy` = TRUE (may be slow).
Run `rlang::last_error()` to see where the error occurred.
Además: Warning messages:
1: In check_batch(df_batch[[batch]], min_n_batch = 2) :
  Batch variable is not a factor as provided and will be converted to one.
2: In lm_meta(feature_abd = pathway, batch = "study", exposure = "response", :
  Covariate age is missing or has only one non-missing value in the following batches; will be excluded from model for these batches:
montes
3: In lm_meta(feature_abd = pathway, batch = "study", exposure = "response", :
  Covariate sex is missing or has only one non-missing value in the following batches; will be excluded from model for these batches:
montes

```

Omitting the covariates…

```auto
fit_lm_cov <- lm_meta(feature_abd = pathway,
                      batch = "study",
                      exposure = "response",
                      data = MeTa,
                      control = list(verbose = FALSE))

```

This worked fine but with results _only_ considering ‘response’ as a variable.

If I omit ‘montes’ from both files and rerun it and I got the same error

```auto
Error: `x` and `y` must share the same src, set `copy` = TRUE (may be slow).

```

I wonder if I can include these covariates in this step maybe I am missing something with the format. Thank you very much for your help

I am attaching the pathways file [here](https://drive.google.com/file/d/1RjZZKXy715eMtlDldXwimd85dpZP7TY-/view?usp=sharing)  
metadata = [mmuphin\_metadataX.csv](https://forum.biobakery.org/uploads/short-url/hCBGCywSQPjfq5l8zH4CUcrr6Za.csv) (6.4 KB)

Best,

Andrés

---

<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: [August 31, 2021, 1:24pm UTC](https://forum.biobakery.org/t/error-x-and-y-must-share-the-same-src-when-trying-to-include-covariates-in-lm-meta/2533/2 "2021-08-31T13:24:58Z")

</div>

Hi Andrés. This error has to do with how you have age encoded as A,B,C. Right now MMUPHin can’t handle fixed effects for categorical variables with more than two categories.

Tagging @sma to discuss the fix. I think if the `control` argument to `lm_meta` can take an entry for `reference` and then pass that to `Maaslin2_wrapper`, that should make it work. Will that be feasible Siyuan?

---

<div class="post-metadata">

### Author: ![drelo](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/drelo/32/566_2.png) [@drelo](https://forum.biobakery.org/u/drelo)
#### Post date: [August 31, 2021, 4:57pm UTC](https://forum.biobakery.org/t/error-x-and-y-must-share-the-same-src-when-trying-to-include-covariates-in-lm-meta/2533/3 "2021-08-31T16:57:41Z")

</div>

Thanks for your help Andrew, we coded the age as a discrete variable to use LEfSe first, we kept that in MaAsLin… then by inertia it got dragged as discrete into MMUPHin. I went back to the original numbers and the analysis run fine. Thanks for your help.

The package is great, maybe it is planned for future iterations like it was commented [for MaAsLin](https://forum.biobakery.org/t/formatting-maaslin-plots-and-heatmap/2119/2) but a follow up question or request would be to ask if there is a way to manually adjust the size of the ‘feature label’ in the forest .pdf plot, with pathways or broadly speaking HUMAnN data the large name is abbreviated since it can’t fit the page.

---

<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: [August 31, 2021, 5:38pm UTC](https://forum.biobakery.org/t/error-x-and-y-must-share-the-same-src-when-trying-to-include-covariates-in-lm-meta/2533/4 "2021-08-31T17:38:28Z")

</div>

I don’t think exposing plot options to the user is planned at the moment. Probably the easiest thing for you to do is get your results into R, regenerate the figure using [metafor::forest](https://www.metafor-project.org/doku.php/plots) (the same function we use), then tweak it as necessary from there.

---

<div class="post-metadata">

### Author: ![drelo](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/drelo/32/566_2.png) [@drelo](https://forum.biobakery.org/u/drelo)
#### Post date: [August 31, 2021, 7:27pm UTC](https://forum.biobakery.org/t/error-x-and-y-must-share-the-same-src-when-trying-to-include-covariates-in-lm-meta/2533/5 "2021-08-31T19:27:45Z")

</div>

I will try that, thanks for the help again.

---

<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: [August 31, 2021, 8:23pm UTC](https://forum.biobakery.org/t/error-x-and-y-must-share-the-same-src-when-trying-to-include-covariates-in-lm-meta/2533/6 "2021-08-31T20:23:51Z")

</div>

Hi all - yes, confirmed this appears to be an issue right now. I think Maaslin2 now requires multi-level variables to start with numerics to specify the reference level. In Andrés’ case the internal Maaslin2 runs are failing as a consequence. I might just throw the original error instead of having Maaslin2 fail silently and then report a nondescript one in its place. Thanks for bringing to my attention!

---

<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: [October 4, 2021, 5:53pm UTC](https://forum.biobakery.org/t/error-x-and-y-must-share-the-same-src-when-trying-to-include-covariates-in-lm-meta/2533/7 "2021-10-04T17:53:22Z")

</div>

Just wanted to confirm that this has been implemented - MMUPHin will correctly relay Maaslin2’s reference level error message. The implementation should be available starting Bioc3.13.

---

<div class="post-metadata">

### Author: ![tschoen](https://avatars.discourse-cdn.com/v4/letter/t/8e7dd6/32.png) [@tschoen](https://forum.biobakery.org/u/tschoen)
#### Post date: [March 25, 2022, 4:07pm UTC](https://forum.biobakery.org/t/error-x-and-y-must-share-the-same-src-when-trying-to-include-covariates-in-lm-meta/2533/8 "2022-03-25T16:07:55Z")

</div>

Hi, I have a similar issue:  
out ← MMUPHin::lm\_meta(feature\_abd = reads,  
batch = “Batch”,  
exposure = “Category”,  
covariates = “X”,  
data = metadata,  
control = list(reference = c(“X,X1”), verbose = FALSE)

The X is a factor of 12 Categories, but even with the inclusion of the reference level the code is not working and I get the following error:  
Error in `auto_copy()`: ! `x` and `y` must share the same src.  
Is there a solution for this?

---

<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: [March 25, 2022, 10:43pm UTC](https://forum.biobakery.org/t/error-x-and-y-must-share-the-same-src-when-trying-to-include-covariates-in-lm-meta/2533/9 "2022-03-25T22:43:34Z")

</div>

Hi - could you share your input files, please? Feel free to email me at [syma.research@gmail.com](mailto:syma.research@gmail.com). Thanks, Siyuan

---

<div class="post-metadata">

### Author: ![drelo](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.biobakery.org/drelo/32/566_2.png) [@drelo](https://forum.biobakery.org/u/drelo)
#### Post date: [May 31, 2022, 7:34pm UTC](https://forum.biobakery.org/t/error-x-and-y-must-share-the-same-src-when-trying-to-include-covariates-in-lm-meta/2533/10 "2022-05-31T19:34:11Z")

</div>

> [@sma](#):
>
> Bioc3.13

Dear @sma I am trying this option (passing the reference as as part of the ‘control’ list) now with 2 other variables, both of them have more than 2 levels.

```auto
fit_lm_meta_taxSR <- lm_meta(feature_abd = metaphlanSR,
                         batch = "study",
                         exposure = "response",
                         covariates = c("sex", "age", "drug"),
                         data = MeTaSR, 
        control = list(verbose = FALSE, output = "MetaSR.XY", reference='drug,one'))

```

[Inspired by this reply I also tried…](https://forum.biobakery.org/t/multiple-variables-used-as-the-references/2854/4)

```auto
control = list(verbose = FALSE, output = "MetaXXX", 
                       fixed_effects = c("drug"), reference=c("drug,one"))

```

Here is the version I just re installed

```auto
 tools:::.BioC_version_associated_with_R_version()
[1] ‘3.13’
sessionInfo() ... MMUPHin_1.6.2 

```

My questions are (1) is how is the correct way to pass the reference as part of the _control_ arguments (2) how do I pass multiple variables with their references?

Thanks for your help!

Andrés
