Create multiple regressions for each group of data
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!