index out of bounds because... can't solve error

조회 수: 1 (최근 30일)
Robert
Robert 2015년 6월 24일
댓글: Robert 2015년 6월 24일
I am performing a stepwise regression and looping through data, this performs 6 stepwise regressions. I then try to output some of the data. As you can see on the code below, I want to extract the INMODEL data and SSTotal data.
When I run the code I get the outputs for INMODEL for regressions 1 and 2, fantastic. However the SSTotal only comes out for the first regression, giving me the following error for the second regression
"Attempted to access STATS.SStotal(2);
index out of bounds because
numel(STATS.SStotal)=1".
I don't understand the error, as it works for the INMODEL but not SSTotal. Any help greatly appreciated
[rows, cols]=size(A11);
% initialize matrix to store the data
pvalues=zeros(rows, cols)-1;
coefficients=zeros(rows,cols);
r2=zeros(rows,cols);
for i = 1:rows
for j = 1:cols
y=zeros(8,1)
x=zeros(8,6)
for m=1:8
y(m)=TOP((m-1)*rows+i,j);
x(m,1)=Approx1((m-1)*rows+i,j);
x(m,2)=Approx2((m-1)*rows+i,j);
x(m,3)=Approx3((m-1)*rows+i,j);
x(m,4)=Approx4((m-1)*rows+i,j);
x(m,5)=Approx5((m-1)*rows+i,j);
x(m,6)=Approx6((m-1)*rows+i,j);
end
%Run the stepwise Regression
if sum(sum(isnan(x)),2)==0 && sum(isnan(y))==0
xx=x(:,1:6); yy=y(:,1);
[B,SE,PVAL,INMODEL,STATS,NEXTSTEP,HISTORY]= ...
stepwisefit(xx,yy,'penter',.05);
inApprox1(i,j)=INMODEL(1); %comes out fine
inApprox2(i,j)=INMODEL(2); %Comes out fine
sstotApprox1(i,j)=STATS.SStotal(1); %Comes out fine
sstotApprox2(i,j)=STATS.SStotal(2); %ERROR
end
end
end

채택된 답변

Walter Roberson
Walter Roberson 2015년 6월 24일
The SStotal is documented as "Total sum of squares of the response". As it is a total, I would expect there to be only a single value. Perhaps you want SSresid "Sum of squares of the residuals", which possibly has one entry for each residual (but I am not certain of that.)
  댓글 수: 1
Robert
Robert 2015년 6월 24일
Thank you for your response, I think you're right. I get the same error for residuals. The reason I am trying to get SStotal and SSresidual is the calculate R squared, which is not a stepwisefit output, perhaps I am going about it the wrong way...

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Gaussian Process Regression에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by