Hello,
I have a table named 'T' containing a set of stock returns for different stocks as well as the market return for all days the stock returns are presented. I have divided my table into groups based on the stock and now I am trying to create a regression that uses the stock return as the dependant variable and a constant and the market return as the independant/explainatory variables, however I get the error message 'Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.'
I used the code as follow:
T.Groups = findgroups(T.Numero)
T.Ones = ones(length(T.MarketReturn),1);
X = splitapply(@regress(T.StockReturn,[T.Ones T.MarketReturn]),T,T.Groups);

 채택된 답변

dpb
dpb 2020년 4월 27일

0 개 추천

First argument is just a function handle or an anonymous function -- you mixed metaphors by trying to call a function and call that a handle...
X = splitapply(@(x1,x2,y) regress(y,[x1 x2]),T.Ones,T.MarketReturn,T.StockReturn,T.Groups);

댓글 수: 3

Nabil Benhadda
Nabil Benhadda 2020년 4월 28일
Thank you a lot ! However now 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);
dpb
dpb 2020년 4월 28일
Oh, yeah. splitapply doesn't automagically use a cell array when need.
Did you try the advice given in the error message? It shows exactly how to write for purpose; simply add the {} to return cell.
Nabil Benhadda
Nabil Benhadda 2020년 4월 29일
Thank you again !

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

추가 답변 (0개)

제품

릴리스

R2018b

질문:

2020년 4월 27일

댓글:

2020년 4월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by