Re: [R] Fit a 3-Dimensional Line to Data Points

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri, 25 Jul 2008 12:49:43 +0100 (BST)

On Fri, 25 Jul 2008, Richard.Cotton_at_hsl.gov.uk wrote:

>> I am new to R, and was wondering how to do 3D linear
>> regression in R. In other words, I need to Fit a
>> 3-Dimensional Line to Data Points (input).
>>
>> I googled before posting this, and found that it is
>> possible in Matlab and other commercial packages. For
>> example, see the Matlab link:
>> http://www.mathworks.com/products/statistics/demos.html?
>> file=/products/demos/shipping/stats/orthoregdemo.html#10
>>
>> Is there a way to achieve this in R?
>
> Being picky, I think you mean you want to fit a line to 3-dimensional data
> points (since a line is by definition 1-dimensional).
>
> In R, you can find a line of best fit to data with an arbitrary number of
> dimensions using the function 'line'. Type ?line for help, and
> example(line) to see how the function is used.

I only see it discussing 'x-y pairs'. Also 'best fit' is rather nebulous for what is just an algorithm with no well-defined fitting criterion.

> If the problem is a linear regression, use the function 'lm' instead.

The referenced URL is not of linear regression at all, but of orthogonal line fitting. The latter can be done by PCA, in R via prcomp().

There are very many ways 'to achieve this in R', depending on the fitting criterion -- fortunately the original poster asked 'if' not 'how', so we are under no obligation to list them.

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 25 Jul 2008 - 11:57:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 25 Jul 2008 - 12:32:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive