Why code fail to bootstrap when points lower than a certain limit?
6 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone,
My script stop bootstraping when the observtions are lower than a certain limit. May someoen suggets how can i fix this or what are the other possible wayes to bootstrap and computing 99%, 95% and 68% or 50% of the bootsrap population? (data is also attached)
ss = readmatrix('data.csv');
nBoot=2000;
for i=1:148;
bb=ss(:,i);
X = bb(~isnan(bb));
[bci(:,i),bmeans(:,i)] = bootci(nBoot,{@mean,X},'alpha',.23,'type','per');
bmu(i,1) = mean(bmeans(:,i));
end
R_bound=bci';
R_mean=bmu;
R_upper=R_bound(:,2);
R_lower=R_bound(:,1);
(The dataset consist of numbers and NaN values, after removing NaN the actual values for bootsrap within each colum are varies between 2 to 40. However, the code stop wokring when the total enteries are lower than 2). For example, the above code working when i remove few columns with low data points
ss = readmatrix('data.csv');
ss(:,[15, 17, 18, 35, 36, 45]) = []; % removing columns with few data points.
nBoot=2000;
for i=1:142;
bb=ss(:,i);
X = bb(~isnan(bb));
[bci(:,i),bmeans(:,i)] = bootci(nBoot,{@mean,X},'alpha',.23,'type','per');
bmu(i,1) = mean(bmeans(:,i));
end
R_bound=bci';
R_mean=bmu;
R_upper=R_bound(:,2);
R_lower=R_bound(:,1);
May someone help me out here.
Thank you!
0 件のコメント
回答 (1 件)
Varun
2023 年 9 月 15 日
Hi Andi,
I understand that you are facing error using “bootci” function. You are reading “data.csv” file in which you are calling “bootci” function corresponding to each column.
I executed your script on my device and found the root cause of the issue. As you are using “X = bb(~isnan(bb));” before calling “bootci” function, which assignes non-nan values in X. The documentation of “bootci” states that while calling it as “bootci(nBoot,{@mean,X}”, ‘X’ should be a vector that means it should have at least 2 values. But for the 35th and 36th column, the datatype of ‘X’ is scalar which is not permitted in “bootci” function.
To resolve the issue, I added a check as follows just after “X = bb(~isnan(bb));”. Please refer the updated code:
ss = readmatrix('data.csv');
nBoot=2000;
for i=1:148;
bb=ss(:,i);
X = bb(~isnan(bb));
%%% Added a check if X is a scalar
if isscalar(X)
disp(i);
continue;
end
[bci(:,i),bmeans(:,i)] = bootci(nBoot,{@mean,X},'alpha',.23,'type','per');
bmu(i,1) = mean(bmeans(:,i));
end
R_bound=bci';
R_mean=bmu;
R_upper=R_bound(:,2);
R_lower=R_bound(:,1);
Hope this helps.
0 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!