From maechler at stat.math.ethz.ch  Wed May 31 22:00:18 2017
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Wed, 31 May 2017 22:00:18 +0200
Subject: [Rd] stats::line() does not produce correct Tukey line when n
 mod 6 is 2 or 3
In-Reply-To: <001b1eec-e582-3d29-2b65-107957f57cf3@insa-toulouse.fr>
References: <CAN7_cLjefc605D1ATS__MOV4gN7fKDBo5Nx_CNB_B9cDbAxc6w@mail.gmail.com>
 <ffc3e473-622d-796f-a06a-6e1f92f8ab5f@gmail.com>
 <CAN7_cLjmQFtZf9z-qJKdWRCaRY2uxfP8k5=QJsptz3U+TtP8oA@mail.gmail.com>
 <CAN7_cLjbz6S8u79jtx52XgfD1LcpO8CePYUhrunYqrzXHMMN8A@mail.gmail.com>
 <024A7E7D-45F8-4C95-A9BD-DBEB1D085BFA@gmail.com>
 <94b65a5b-da9e-ec5c-e428-7c5dbf175ec1@insa-toulouse.fr>
 <8c167bbb-130d-3798-a9e8-24c4377db313@insa-toulouse.fr>
 <d10ebb8c-0c49-5b0e-5b3c-b06073bfe447@insa-toulouse.fr>
 <22829.8246.695545.320438@stat.math.ethz.ch>
 <396781eb-1712-aa54-96f2-a6c4df0284f4@insa-toulouse.fr>
 <22829.41724.818300.640880@stat.math.ethz.ch>
 <c9af2c00-3653-29f8-7c6a-5a08d6de498e@insa-toulouse.fr>
 <CAO1zAVb8faubH7FrBfsx8c04xsZce2p2Ei9NaBELrfn2Q8JMEA@mail.gmail.com>
 <055b3d48-5f94-d087-74b8-b511e6c45baf@insa-toulouse.fr>
 <CAO1zAVa3=dA_atBNxj9kAX_Rh=5pCMiLK7BAuwq9hhY6KACQag@mail.gmail.com>
 <8fc861d2-1f45-f171-b135-000a668f73b7@insa-toulouse.fr>
 <001b1eec-e582-3d29-2b65-107957f57cf3@insa-toulouse.fr>
Message-ID: <22831.8402.627874.808222@stat.math.ethz.ch>

>>>>> Serguei Sokol <sokol at insa-toulouse.fr>
>>>>>     on Wed, 31 May 2017 18:46:34 +0200 writes:

    > Le 31/05/2017 ? 17:30, Serguei Sokol a ?crit :
    >> 
    >> More thorough reading revealed that I have overlooked this phrase in the
    >> line's doc: "left and right /thirds/ of the data" (emphasis is mine).
    > Oops. I have read the first ref returned by google and it happened to be
    > tibco's doc, not the R's one. The layout is very similar hence my mistake.
    > The latter does not mention "thirds" but ...
    > Anyway, here is a new line's patch which still gives a result slightly different
    > form MMline(). The slope is the same but not the intercept.
    > What are the exact terms for intercept calculation that should be implemented?

    > Serguei.

Sorry Serguei,   I have new version of line.c  since yesterday,
and will not be disturbed anymore.

Note that I *did* give the litterature, and it seems most
discussants don't have paper books in physical libraries anymore;
In this case, interestingly, you need one of those I think -
almost everything I found online did not have the exact details.

Peter Dalgaard definitely was right that Tukey did not use
quantiles at all, and notably did *not* define the three groups
via   {i;  x_i <= x_L}  and {i; x_i >= X_R}  which (as I think
you noticed) may make the groups quite unbalanced in case of duplicated x's.

But then, for now I had decided to fix the bug (namely computing
the x-medians wrongly as you diagnosed correctly(!) -- but your
first 2 patches only fixed partly) *and* go at least one step in
the direction of Tukey's original, namely by allowing iteration via a new 'iter' argument.

I have also updated the help page to document what  line()  has
been computing all these years {apart from the bug which
typically shows for non-equidistant x[]}.

We could also consider to eventually add a new   'method = <string>'
argument to line()  one version of which would continue to
compute the current solution, another would compute the one
corresponding to Velleman & Hoaglin (1981)'s  FORTRAN
implementation (which had to be corrected for some infinite-loop
cases!)... not in the close future though


Given all this discussions here, I think I should commit what I
currently have  ASAP.

Martin

    > x[DELETED ATTACHMENT line.c.patch2, plain text]



[Rd] stats::line() does not produce correct Tukey line when n mod 6 is 2 or 3
Martin Maechler