Create multiple regressions for each group of data
4 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I am trying to divide my table data into groups and calculate regression coefficients for each group using the market return and a constant as explainatory/independant variables and the stock market return as the dependant variable.
I have preceeded as follow:
Work = readtable('Begin Work.xlsx');
Work.Groups = findgroups(Work.Numero);
Work.Ones = ones(length(Work.MarketReturn),1);
%X = splitapply(@(x1,x2,y) regress(y,[x1 x2]),Work.Ones,Work.MarketReturn,Work.StockReturn,Work.Groups);
However, I get the following error message:
Error using splitapply (line 132)
The function '@(x1,x2,y)regress(y,[x1,x2])' returned a non-scalar value when applied to the 1st group of data.
To compute nonscalar values for each group, create an anonymous function to return each value in a scalar cell:
@(x1,x2,y){regress(y,[x1,x2])}
Error in BeginWork (line 20)
X = splitapply(@(x1,x2,y) regress(y,[x1 x2]),Work.Ones,Work.MarketReturn,Work.StockReturn,Work.Groups);
Can anyone please help me with this issue? Or recommend another way to calculate the regressions?
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!