Help with debugging an error: Attempted to access R(1); index out of bounds because numel(R)=0???

7 ビュー (過去 30 日間)
IAn
IAn 2012 年 3 月 23 日
  • Hi, I'm trying to run a bootstrap code that draws a random subsample from a dataset to use for bootstrapping. But now I get this error sequence:*
Attempted to access R(1); index out of bounds because numel(R)=0.
Error in regress (line 76)
p = sum(abs(diag(R)) > max(n,ncolX)*eps(R(1)));
Error in @(bootr)regress(Yfit+bootr,[ones(size(x,1),1),x])
Error in bootstrp (line 165)
bootstat = feval(bootfun,bootargs{:});
Error in RandomSubsampleAnalysis (line 46)
[bootstat2]=bootstrp(rep,@(bootr)regress(Yfit+bootr,[ones(size(x,1),1) x]),resid);
Caused by:
Unable to evaluate BOOTFUN with the supplied arguments.
The funny thing is that it worked fine a couple of hours ago.
my code looks like this:
clc;
warning off all;
replications=1; % number of simulations %
rep=100; % bootstrap replications %
rt1_s=[];
rt2_s=[];
OLS_b_s=[];
OLS_std_b_s=[];
Boot1_b_s=[];
Boot2_b_s=[];
Boot1_std_b_s=[];
Boot2_std_b_s=[];
for i=1:replications
% set subsample size %
ss=100; % cannot exceed full sample size %
load('data.mat');
n=length(data);
index=randsample(n,ss);
data1=data(index,:);
x=data1(:,2:end);
y=data1(:,1);
stats=regstats(y,x,'linear');
t=stats.tstat;
% case resampling
Y=[y ones(size(x,1),1) x];
[bootstat1]=bootstrp(rep,@(x)regress(x(:,1),x(:,2:end)),Y);
subplot(2,2,1), hist(bootstat1(:,1),100)
subplot(2,2,2), hist(bootstat1(:,2),100)
% model-based resampling
Yfit=[ones(size(x,1),1) x]*t.beta;
resid=y-Yfit;
[bootstat2]=bootstrp(rep,@(bootr)regress(Yfit+bootr,[ones(size(x,1),1) x]),resid);
subplot(2,2,3), hist(bootstat2(:,1),100)
subplot(2,2,4), hist(bootstat2(:,2),100)
beta = t.beta; % coefficients - OLS
se = t.se; % standard errors - OLS
Boot1_b=mean(bootstat1)'; % coefficients - case resampling
Boot1_std_b=sqrt(var(bootstat1))'; % standard errors - case resampling
rt1=abs((Boot1_b-t.beta)./Boot1_std_b);
Boot2_b=mean(bootstat2)'; % coefficients - model-based resampling
Boot2_std_b=sqrt(var(bootstat2))'; % standard errors - model-based resampling
rt2=abs((Boot2_b-t.beta)./Boot2_std_b);
rt1_s=[rt1_s;rt1'];
rt2_s=[rt2_s;rt2'];
OLS_b_s=[OLS_b_s;t.beta'];
OLS_std_b_s=[OLS_std_b_s;t.se'];
Boot1_b_s=[Boot1_b_s;Boot1_b'];
Boot2_b_s=[Boot2_b_s;Boot2_b'];
Boot1_std_b_s=[Boot1_std_b_s;Boot1_std_b'];
Boot2_std_b_s=[Boot2_std_b_s;Boot2_std_b'];
end
OLS_b=mean(OLS_b_s)'
OLS_std_b=mean(OLS_std_b_s)'
Boot1_b=mean(Boot1_b_s)'
Boot2_b=mean(Boot2_b_s)'
Boot1_std_b=mean(Boot1_std_b_s)'
Boot2_std_b=mean(Boot2_std_b_s)'
rt1=mean(rt1_s)'
rt2=mean(rt2_s)'
can someone help please?

回答 (1 件)

Stephen
Stephen 2012 年 3 月 23 日
Are bootstrp and bootr functions you've defined? It would be really difficult to debug without seeing those. If the code used to work, and you haven't changed the functions, then I would suggest you should check the "Last Modified" date on the file 'data.mat' to see if that has changed since the last time it worked.
Good Luck,
Stephen
  2 件のコメント
Stephen
Stephen 2012 年 3 月 26 日
Unfortunately, I don't have the statistics toolbox so I don't have thee bootr function either. Have you tried adding breakpoints to the script and stepping in to the function to find where the issue occurs and what the value of R is when the error occurs?
Stephen

サインインしてコメントする。

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by