置信区间MATLAb中的自举数据

时间:2013-10-28 10:13:48

标签: matlab statistics-bootstrap

我也尝试了这个:

plot(x(bootsam(:,100)),y(bootsam(:,100)), 'r*')但我的数据完全相同!我想在95%置信区间内重新采样我的数据。  但似乎这个命令bootstrp不能单独工作,它需要一些功能或其他命令来组合。你能帮我解决一下吗?

我想随机生成一些数据但行为类似于原始数据的函数,我附上了一个图,其中红色和重采样数据的原始数据是蓝色和绿色。 enter image description here

一般来说,我想使用bootstrap为我的最佳拟合参数找到错误。我在这本书中读到: http://books.google.de/books?id=ekyupqnDFzMC&lpg=PA131&vq=bootstrap&hl=de&pg=PA130#v=onepage&q&f=false 其他错误分析方法我很感兴趣。

1 个答案:

答案 0 :(得分:1)

我建议你从这种方式开始,然后根据你的情况进行调整。

% One step at a time.
% Step 1: Suppose you generate a simple linear deterministic trend with
% noise from the standardized Gaussian distribution:
N = 1000;    % number of points
x = [(1:N)', ones(N, 1)];    % x values
b = [0.15, 157]';    % parameters
y = x * b + 10 * randn(N, 1);    % linear trend with noise
% Step 2: Suppose you want to fit y with a linear equation:
[b_hat, bint1] = regress(y, x);    % estimate parameters with linear regression
y_fit = x * b_hat;    % calculate fitted values
resid = y - y_fit;    % calculate residuals
plot(x(:, 1), y, '.')    % plot
hold on
plot(x(:, 1), y_fit, 'r', 'LineWidth', 5)    % fitted values
% Step 3: use bootstrap approach to estimate the confidence interval of
% regression parameters
N_boot = 10000;    % size of bootstrap
b_boot = bootstrp(N_boot, @(bootr)regress(y_fit + bootr, x), resid);    % bootstrap
bint2 = prctile(b_boot, [2.5, 97.5])';    % percentiles 2.5 and 97.5, a 95% confidence interval
% The confidence intervals obtained with regress and bootstrp are
% practically identical:
bint1
bint2
相关问题