Control for Confounding Variables in a Linear Regression Model

조회 수: 23(최근 30일)
Johanna Popp
Johanna Popp 2022년 3월 12일
댓글: Johanna Popp 2022년 3월 14일
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!

채택된 답변

Jeff Miller
Jeff Miller 2022년 3월 12일
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.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by