Advanced Octave A28 — Bootstrap and intervals
Advanced GNU Octave with GX-TXT · Module 05
The bootstrap repeats the observations available to study the variability of a statistic. The procedure does not create new measures: its conclusions depend on the sample and how it is sampled.
Objectives and prerequisites
After the introductory course statistics and the Monte Carlo A27 simulation, we build a percentage range for an average. The [9,8; 10,1; 10,0; 10,2; 9,9] sample is synthetic and without physical units assigned. The test uses GX-TXT dev112-P011-bis and GNU Octave 9.4.0.
Resamping with reinsertion
Import bootstrap_media.m, register it and run it in the Runner.
The 42 fixed code generates 2,000 samples of the same size as the original and calculates the average of each. The indexes are extracted with reintegration: a single observation can appear several times in one sample and another may not appear.
rng(42,'twister');
replicates = 2000;
means = zeros(replicates,1);
for k = 1:replicates
indices = randi(numel(x),1,numel(x));
means(k) = mean(x(indices));
endfor
interval = gxtxt_api_call('NUMERIC_API_v1','quantiles',{means,[0.025,0.975]});
The public API calculates 2.5% and 97.5% of the averages resamped. The result also declares the convention used for quantums, useful when comparing different implementations.
In the test the original average is 10,0 and the percentage range obtained is about [9,88; 10,12]. This range describes the method applied to the synthetic sample and its hypotheses: with only five observations can be unstable and should not be presented as a universal cover guarantee.
Choose what to resamp
The resamping of individual observations is only suitable when the hypotheses of the problem allow it. For data affixed, repeated measurements, time series or related groups it is necessary to preserve the relevant structure; resamping each number independently can destroy it. Document seed, generator, number of replicas, statistics and method of intervals.
The bootstrap does not automatically correlate acquisition bias or non-representative sample. More replicas reduce the numerical variability of the procedure, but do not add experimental information to the original set.
Exercise
- Why can an observation appear several times in a recampion?
- What quantities are used for the range shown?
- Why do five observations not become 10,000 independent measures if replicas are increased?
Worked solution
- Because the indexes are extracted with reintegration.
- The
0,025and0,975quantums of the average re-samped. - The replicas are built by reusing the same original data; they do not add independent observations.
Other steps of this project
- Advanced Octave A75 — Dynamical systems in phase space
- Advanced Octave A81 — Geography of the waves and a 3D surface
- Advanced Octave A82 — Age, sex and demographic inequalities
- Advanced Octave A83 — All-cause mortality, certified COVID deaths and surveillance
- Advanced Octave A84 — A reproducible public account
- Advanced Octave A73 — Optimization landscapes and 3D trajectories