Advanced Octave A25 — Robust estimation and unusual observations
Advanced GNU Octave with GX-TXT · Module 05
A value very distant from others can strongly influence an average. Mediana and absolute median deviation, or MAD, offer complementary information, but do not automatically decide whether an observation is wrong.
Objectives and data
We repeat the descriptive statistics of the introductory course and compare two small synthetic samples with NUMERIC_API_v1/statistics and mad. The test uses GX-TXT dev112-P011-bis and GNU Octave 9.4.0. The values are didactic numbers without assigned physical units, not measures.
The first sample is [9,8; 10,1; 10,0; 10,2; 9,9]; in the second we replace the last value with 30,0. It is a deliberate change to study the sensitivity of statistics.
Compare media, median and MAD
Import stime_robuste.m, record it in the Session and start it in the Runner.
For each sample the script calls:
stats = gxtxt_api_call('NUMERIC_API_v1','statistics',{x});
robust = gxtxt_api_call('NUMERIC_API_v1','mad',{x});
The first service returns, among other fields, median, and variance; the second returns the MAD and the scale convention used. The raw MAD is the median of the absolute wastes from the sample median. A rescaled version should be distinguished from the crude one, checking the scale field.
In the test the first sample has average 10,0 and median 10,0. In the second half it becomes 14,02, the median 10,1 and the raw MAD 0,1. The great value moves the average a lot, while the effect on the median is more contained in this example. The figure also shows scale = raw : we must not present that value as a standard deviation without any additional assumptions and appropriate conversions.
Interpreting an abnormal value
A distant value may result from a mistake, from a rare real condition or from a process change. Before excluding verification of origin, instrument, unity, context and criteria established. Keep the original data and document every choice; compare, when useful, results with and without observation, explaining both.
Robustness does not mean absolute immunity or superiority in every situation. With five comments, the information is limited and we cannot deduce a general distribution from the summary alone.
Exercise
- What statistics change most in the example: median or median?
- What does the
scale = rawfield mean associated with the MAD? - Is it correct to delete the value 30 just because it is distant from others?
Worked solution
- The average: switches from
10,0to14,02. - That is reported the absolute crude median deviation, without the scale factor of other conventions.
- No. It serves a motivation based on quality, context and method, documenting the decision.
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