Expanded bootstrap chapter and improved latex header

This commit is contained in:
2015-11-01 22:39:06 +01:00
parent 40a5343fa8
commit 5edac6cfd6
15 changed files with 419 additions and 65 deletions

View File

@@ -0,0 +1,5 @@
>> bootstrapsem
mean stdev sem
single SRS -0.13 0.97 0.10
bootstrapped distribution -0.13 0.10 -
sampling distribution -0.00 0.10 -

View File

@@ -0,0 +1,38 @@
% generate correlated data:
n=200;
a=0.2;
x = randn(n, 1);
y = randn(n, 1) + a*x;
% correlation coefficient:
rd = corr(x, y);
fprintf('correlation coefficient of data r = %.2f\n', rd );
% distribution of null hypothesis by permutation:
nperm = 1000;
rs = zeros(nperm,1);
for i=1:nperm
xr=x(randperm(length(x))); % shuffle x
yr=y(randperm(length(y))); % shuffle y
rs(i) = corr(xr, yr);
end
[h,b] = hist(rs, 20 );
h = h/sum(h)/(b(2)-b(1)); % normalization
% significance:
rq = quantile(rs, 0.95);
fprintf('correlation coefficient of null hypothesis at 5%% significance = %.2f\n', rq );
if rd >= rq
fprintf('--> correlation r=%.2f is significant\n', rd);
else
fprintf('--> r=%.2f is not a significant correlation\n', rd);
end
% plot:
bar(b, h, 'facecolor', 'b');
hold on;
bar(b(b>=rq), h(b>=rq), 'facecolor', 'r');
plot( [rd rd], [0 4], 'r', 'linewidth', 2 );
xlabel('Correlation coefficient');
ylabel('Probability density of H0');
hold off;

View File

@@ -0,0 +1,4 @@
>> correlationsignificance
correlation coefficient of data r = 0.23
correlation coefficient of null hypothesis at 5% significance = 0.12
--> correlation r=0.23 is significant