Regress out a variable using stepwiselm?

5 次查看(过去 30 天)
Hi all,
I have a table that contains M x N predictor variables and a M x 1 response variable. The first M/2 x N predictor observations come from the same subject as the remaining M/2 x N observations (i.e. if I have 100 rows, data in rows 1:50 come from subject 1:50, and data in rows 51:100 come from subject 1:50 - they are different measures of the same subject, e.g. left arm length and right arm length).
I want to build a linear model that predicts the response variable from the predictor variables, while accounting for the fact that there is a relationship (i.e. interaction) between rows 1 and 51, rows 2 and 52, rows 3 and 53 etc. I've tried adding an index column to the table -- without much success.
I'm unsure about how to add this term in stepwiselm, or whether another function might be more appropriate?
Thank you!

采纳的回答

Ayush Aniket
Ayush Aniket 2023-11-29
Hi Michaela,
I understand that you want to fit a linear model to your data that predicts the response variable from the predictor variables, while accounting for the fact that there is a relationship between rows in the data.
The function “stepwiselmperforms stepwise regression and its goal is to find a model that includes only the predictors that significantly contribute to the model, thereby simplifying the model without sacrificing explanatory power. This will not be suitable for your data which has an inherent relationship between rows.
For your dataset, you can use a mixed-effects model, which allows you to include both fixed effects (the predictor variables) and random effects (the subject-specific effects). In MATLAB, you can use the "fitlme" function from the Statistics and Machine Learning Toolbox to fit a linear mixed-effects model.
The relationship information can be fed to the ‘formula’ argument of the "fitlme" function. For more information about the function and relevant examples, please refer to the following documentation page:
Hope it helps!

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by