Control for Confounding Variables in a Linear Regression Model
27 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!