Create multiple regressions for each group of data

4 views (last 30 days)
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?

Answers (0)

Categories

Find more on Linear and Nonlinear Regression in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!