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

1 vue (au cours des 30 derniers jours)
Robert
Robert le 24 Juin 2015
Commenté : Robert le 24 Juin 2015
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

Réponse acceptée

Walter Roberson
Walter Roberson le 24 Juin 2015
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 commentaire
Robert
Robert le 24 Juin 2015
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...

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by