regress function error for matrix multiplication

조회 수: 1 (최근 30일)
Luca
Luca 2021년 4월 17일
댓글: Luca 2021년 4월 21일
Hi,
I tried to regress stock returns on market returns and I get this error:
Applying the function '@(x,y){regress(y,x)}' to the 10562nd group of data generated the following error:
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows
in the second matrix. To perform elementwise multiplication, use '.*'.
This is my code.
%% creating variables
A = [ones(size(subset1.MRET)), subset1.MRET];
b = subset1.RET;
%% run regression
[group5, years4, ID3] = findgroups(subset1.years, subset1.ID);
m1 = splitapply(@(x,y) {regress(y,x)}, A, b, group4);
A is a 64121190x2 Matrix
The first column are ones to include the constant and the second column are the Marketreturns.
b is a 64121190x1 Vector
With the stock returns in it.
Does somone know how to deal with this error.
It worked for me, when i used a subset of only 2 stocks.
The dataset is unfortunaltly to big to ubload.
Thank you in advance
  댓글 수: 2
Shashank Gupta
Shashank Gupta 2021년 4월 20일
For some reason, I am not able to regenerate the error which you are getting, but by the look of it, it seems like some kind of mismatch in input dimension provided to the function. I can further investigate if you can provide me "subset1.Years" and "subset1.ID" may be.
Luca
Luca 2021년 4월 21일
Thank you for your answer. I found the problem there were to many NaN in some years to run the regression.

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

답변 (0개)

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by