Using Looping function for linear regression

Hello,
I am relatively new to Matlab and was finally able to figure out how to runa linear regression using categorical variables.
My formula for regression is stated below:
regression = fitlm(classdata,'interactions','ResponseVar','testscores',...
'PredictorVars',{'sex','interview_age','IQscores'},...
'CategoricalVar',{'sex'})
Wherein:
Data is 'classdata'
Dependent Variable is 'testscore'
Independent Variable 1 is 'sex'
Independent Variable 2 is 'interview_age'
Independent Variable 3 is 'IQscores'
I want to conduct the same regression on on all columns 9 through 12, using the same 3 Independent variables. Therefore the dependent variable will change with each regression in the loop, while the independent variables remain constant. I tried the following formula to acheive this:
_______________________________________________________________
classdata = readtable('/Users/work/Documents/Matlab/practicematlab2.xlsx')
for lc = (9:1:12)
fit = fitlm(classdata,'interactions','ResponseVar','T(lc)',...
'PredictorVars',{'sex','interview_age','IQscores'},...
'CategoricalVar',{'sex'})
end
However, this formula does not work at all. What's the correct looping formula for this function? Any help would be REALLY appreciated.
Thank you.

답변 (0개)

질문:

2021년 3월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by