how to run multiple number of regressions?

1 回表示 (過去 30 日間)
alpedhuez
alpedhuez 2021 年 7 月 29 日
編集済み: alpedhuez 2021 年 7 月 30 日
I have table T with
Date Location Sales Visitors
1/1 NY 10 5
1/1 LA 7 3
1/2 NY 9 5
1/2 LA 4 1
Then I want to run regressions
(sales)=a_i*(visitor)+b_i
for each i = {NY, LA}. Is there any simpler way to do this?

採用された回答

dpb
dpb 2021 年 7 月 29 日
tRegress=rowfun(@(x,y)polyfit(x,y,1),T,'GroupingVariables',{'Location'}, ...
'InputVariables',{'Visitors','Sales'}, ...
'NumOutputs',1, ...
'OutputVariableNames',{'Coefficients'});
  3 件のコメント
dpb
dpb 2021 年 7 月 30 日
tRegress=rowfun(@(x,y)fitlm(x,y,'linear'),T,'GroupingVariables',{'Location'}, ...
'InputVariables',{'Visitors','Sales'}, ...
'NumOutputs',1, ...
'OutputVariableNames',{'Model'}, ...
'OutputFormat',"cell");
If it gets too much more complicated may have to use an m-file for the function instead of anonymous function...also have to switch to a cell output to catenate the model outputs instead of table.
alpedhuez
alpedhuez 2021 年 7 月 30 日
編集済み: alpedhuez 2021 年 7 月 30 日
Let me work on it.

サインインしてコメントする。

その他の回答 (0 件)

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by