Adding covariates to a mofaflex model #151
-
|
Hello, I'm trying to create a mofa model using the expression of over 5000 proteins from an olink assay. I managed to add some information as guiding variables (inflammation status and diagnosis) and now, I want to add the age and sex of my samples as covariates to adjust for them. I tried the code next: model = mfl.MOFAFLEX(
mdata,
mfl.ModelOptions(
n_factors=15,
weight_prior="SnS",
likelihoods="Normal"
),
mfl.DataOptions(
# scale_per_group = F as all samples belong to the same condition
# and reference and we specify the annotation key
scale_per_group = False,
annotations_varm_key = "annotations",
plot_data_overview = False,
guiding_vars_obs_keys = {
"Inflamed" : {"single_group": "inflammed"},
"Diagnosis" : {"single_group": "diagnosis"}
},
covariates_obs_key = {
"age" : {"single_group": "inflammed"},
"sex" : {"single_group": "diagnosis"}
}
),
mfl.TrainingOptions(
seed=42,
save_path="./data/MOFA/model_v4.txt", # save the model on disk
lr=0.01,
early_stopper_patience=5000
)
)But it doesn't use the informations: >>> model.covariates
{}
>>> model.covariates_names
{}All the informations (inflammation status, diagnosis, Age and Sex) are inside the mdata.obs dataframe. Do you have any idea of what I did wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
The As a side note, you can also use the simpler syntax |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for this quick answer. I observed that some factors were associated with age and sex. I wanted to try to remove this association by adjusting for those information similarly as I would do it for a differential analysis. |
Beta Was this translation helpful? Give feedback.
When you're referring to differential analysis, I'm assuming you mean something like (in R formula notation)
expression ~ condition + age + sexwhere you're interested in theconditioneffect. What that does is that your linear model does fit coefficients for age and sex, but you only use the condition coefficient for further analysis, since that one should no longer be influenced by age and sex. So you don't remove the association, you control for it.Similarly, in factor models such as MOFA-FLEX, if you have some factors that are correlated with age and sex, you can focus your downstream analysis on the other factors, which should then not be influenced by age and sex. The guiding varia…