6

I didn't find a function to calculate the orthogonal regression (TLS - Total Least Squares).

Is there a package with this kind of function?

Update: I mean calculate the distance of each point symmetrically and not asymmetrically as lm() does.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Bleak
  • 159
  • 1
  • 2
  • 6
  • 1
    It would be fair to provide links to your earlier questions on stats.SE, e.g. [How princomp() works?](http://stats.stackexchange.com/questions/13152/how-princomp-works), as you already got some clues there. – chl Jul 29 '11 at 13:48

4 Answers4

5

You might want to consider the Deming() function in package MethComp [function info]. The package also contains a detailed derivation of the theory behind Deming regression.

The following search of the R Archives also provide plenty of options:

Your multiple questions on CrossValidated, here and R-Help imply that you need to do a bit more work to describe exactly what you want to do, as the terms "Total least squares" and "orthogonal regression" carry some degree of ambiguity about the actual technique wanted.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
3

I got the following solution from this url:

https://www.inkling.com/read/r-cookbook-paul-teetor-1st/chapter-13/recipe-13-5

   r <- prcomp( ~ x + y )
   slope <- r$rotation[2,1] / r$rotation[1,1]
   intercept <- r$center[2] - slope*r$center[1]

Basically you performa PCA that will fit a line between x and y minimizing the orthogonal residuals. Then you can retrieve the intercept and slope for the first component.

Valentin Ruano
  • 2,726
  • 19
  • 29
3

Two answers:

  1. gx.rma in the rgr package appears to do this.
  2. Brian Ripley has given a succinct answer on this thread. Basically, you're looking for PCA, and he suggests princomp. I do, too.
Iterator
  • 20,250
  • 12
  • 75
  • 111
  • 1
    I think the applicability of Ripley's response depends on what @Dail means by total least squares and orthogonal regression. Ripley does qualify his response... – Gavin Simpson Jul 29 '11 at 13:31
  • @Gavin, true. What Ripley also implied is the asker didn't have a firm grasp of either TLS or PCA. It was an open question whether it was the right (or wrong) solution to the wrong (or right) problem/question. – Iterator Jul 29 '11 at 13:56
-1

For anyone coming across this question again, there exists a dedicated package 'onls' by now for that purpose. It is similar handled as the nls package (which implements ordinary least square algorithms)

dschingchris
  • 139
  • 1
  • 10
  • Hi, this answer would not be helpful if the supplied link ever were to go defunct. Would you consider using an [edit] to provide the relevant details to the question, along with the link as a reference? – gravity Jul 18 '19 at 13:37