Reorganized the folders and started a common script for the lectures.

This commit is contained in:
2015-10-25 20:24:13 +01:00
parent dd50324683
commit 5791337dea
48 changed files with 1476 additions and 648 deletions

View File

@@ -0,0 +1,24 @@
nsamples = 100;
nresamples = 1000;
% draw a SRS (simple random sample, "Stichprobe") from the population:
x = randn( 1, nsamples );
fprintf('%-30s %-5s %-5s %-5s\n', '', 'mean', 'stdev', 'sem' )
fprintf('%30s %5.2f %5.2f %5.2f\n', 'single SRS', mean( x ), std( x ), std( x )/sqrt(nsamples) )
% bootstrap the mean:
mus = zeros(nresamples,1); % vector for storing the means
for i = 1:nresamples % loop for generating the bootstraps
inx = randi(nsamples, 1, nsamples); % range, 1D-vector, number
xr = x(inx); % resample the original SRS
mus(i) = mean(xr); % compute statistic of the resampled SRS
end
fprintf('%30s %5.2f %5.2f -\n', 'bootstrapped distribution', mean( mus ), std( mus ) )
% many SRS (we can do that with the random number generator, but not in real life!):
musrs = zeros(nresamples,1); % vector for the means of each SRS
for i = 1:nresamples
x = randn( 1, nsamples ); % draw a new SRS
musrs(i) = mean( x ); % compute its mean
end
fprintf('%30s %5.2f %5.2f -\n', 'sampling distribution', mean( musrs ), std( musrs ) )