Control for Confounding Variables in a Linear Regression Model

11 views (last 30 days)
Hi All,
I am trying to fit a multiple linear regression model to my data using the function fitlm(x) and I'm wondering how to go about controlling for some confounding variables in the model, and later the prediction of my dependent variable. Are there different possibilities to do so? I was using the regress(x) function ro regress out the confounding variables & then using the residuals of the independent variables to fit the model. I'm not sure if that's the correct approach and I'm thankful for any suggestions and input!
Thanks,
Johanna

Accepted Answer

Jeff Miller
Jeff Miller on 12 Mar 2022
Suppose you have a variable X that you would like to predict from a set of predictors P and you want to control for some other variables C. The standard approach is to make a comparison between two models:
% I probably don't have the syntax quite right because I don't use fitlm
% much, but hopefully this will convey the idea:
mdl1 = fitlm(x,C); % predict x from C alone
mdl2 = fitlm(x,[C P]); % predict x from C & P
The improvement of mdl2 over mdl1 (e.g., increase in SSmodel, decrease in SSerror) is then attributed to the predictors in P "controlling for" those in C. For more detail, you might look at Chapter 15 of this online book.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by