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

  1. Why can an observation appear several times in a recampion?
  2. What quantities are used for the range shown?
  3. Why do five observations not become 10,000 independent measures if replicas are increased?

Worked solution

  1. Because the indexes are extracted with reintegration.
  2. The 0,025 and 0,975 quantums of the average re-samped.
  3. The replicas are built by reusing the same original data; they do not add independent observations.

Download the Module 05 scripts (ZIP)

#GNU Octave #GX-TXT #GX-TXT public APIs

Other steps of this project

Leave a Reply

Your email address will not be published. Required fields are marked *