필터 지우기
필터 지우기

Error using regstats (RESPONSES and DATA must have the same number of rows)

조회 수: 1 (최근 30일)
Hello!
I must deliver the code for an Econometrics exam and everything is running smoothly except for the following error:
Error using regstats
RESPONSES and DATA must have the same number of rows.
Error in FinancialEconometrics_Homework (line 515)
out=regstats(PInde(:,i),F);
that refers to this part of the code:
out=regstats(PInde(:,i),F);
APToutBtM(i,1:6)=out.beta';
APToutBtM(i,7:12)=out.tstat.t';
APToutBtM(i,13)=out.adjrsquare;
APTresBtM(:,i)=out.r;
I don't know how to solve the problem.
PInde is a 97x25 double matrix and F is a 403x5 double matrix.
Could you please help me?
Thank you

채택된 답변

Walter Roberson
Walter Roberson 2024년 3월 6일
regstats(y,X,model) performs a multilinear regression of the responses in y on the predictors in X. X is an n-by-p matrix of p predictors at each of n observations. y is an n-by-1 vector of observed responses.
So the number of rows of X and y must be the same.
You are using PIndel(:,i) as the y, which will be 97 x 1
You are using F as the X, which will be 403 x 5.
The number of rows of 97 x 1 does not match the number of rows of 403 x 5, so this will fail.
  댓글 수: 5
Walter Roberson
Walter Roberson 2024년 3월 7일
intercept = ones(size(Me));
intercept = intercept(:,1);
What is the point of that? Why not just
intercept = ones(size(Me,1),1);
FEDERICA
FEDERICA 2024년 3월 7일
You're right, thank you for your suggestion! I'm really sorry, I'm still learning to write codes in MatLab and often I just make the same things my professor does during the lectures.

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

추가 답변 (1개)

FEDERICA
FEDERICA 2024년 3월 8일
Problem solved! Thank you for your help :)

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by