Expanded bootstrap chapter and improved latex header
This commit is contained in:
5
bootstrap/code/bootstrapsem.out
Normal file
5
bootstrap/code/bootstrapsem.out
Normal 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 -
|
||||
38
bootstrap/code/correlationsignificance.m
Normal file
38
bootstrap/code/correlationsignificance.m
Normal 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;
|
||||
4
bootstrap/code/correlationsignificance.out
Normal file
4
bootstrap/code/correlationsignificance.out
Normal 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
|
||||
Reference in New Issue
Block a user