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

1 次查看(过去 30 天)
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 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by