Define a set of independent variables for fitlm

조회 수: 2 (최근 30일)
alpedhuez
alpedhuez 2020년 12월 6일
댓글: Star Strider 2020년 12월 7일
Suppose I have a table T with labels
visitors price proxy_January proxy_February proxy_March
I want to run a regression
visitors = a + b*price + c_1*proxy_January + ...
A brute force way is to write down
X=[T.price T.proxy_January (then the rest of proxy variables)]
and run
mdl = fitlm(X,T.visitors)
But I would like to have Matlab to write down all the proxy variables instaad of me listing all by hand.
I understand that I can get the list of labels with T.Properties.VariableNames but I need to get the list of labels and data. Please advise.

채택된 답변

Star Strider
Star Strider 2020년 12월 6일
Possibly:
X = T{:,2:end};
then:
mdl = fitlm(X,T.visitors)
If ‘T’ has only numeric variables, that should work. .
  댓글 수: 4
alpedhuez
alpedhuez 2020년 12월 6일
Thank you.
Star Strider
Star Strider 2020년 12월 7일
As always, my pleasure!
(My apologies for the delay in responding.)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by