index out of bounds because... can't solve error
2 次查看(过去 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
0 个评论
采纳的回答
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.)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Regression 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!