improved on statistics

This commit is contained in:
2017-11-24 19:34:16 +01:00
parent 35d1b908f3
commit f362788620
7 changed files with 144 additions and 44 deletions

View File

@@ -1,14 +1,18 @@
n = 1000
x = randn( n, 1 );
y = randn( n, 1 ) + 0.2*x;
r = corr(x,y)
nsamples = 500;
rs = zeros( nsamples, 1 );
for i = 1:nsamples
xs = x(randi(n,n,1));
ys = x(randi(n,n,1));
rs(i) = corr(xs,ys);
n = 200;
corrs = [ 1.0, 0.6, 0.0, -0.9 ];
for k = [1:length(corrs)]
r = corrs(k);
x = randn(n, 1);
y = r*x; % linear dependence of y on x
% add noise to destroy perfect correlations:
y = y + sqrt(1.0-r*r)*randn(n, 1);
% compute correlation coefficient of data:
rho = corr(x, y);
subplot(2, 2, k)
scatter( x, y )
text( -2, 2.5, sprintf('r=%.1f', rho) )
xlabel('x')
ylabel('y')
xlim([-3.0, 3.0])
ylim([-3.0, 3.0])
end
hist( rs, 20 )