[R] Fit a 3-Dimensional Line to Data Points
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Jul 25 13:49:43 CEST 2008
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
More information about the R-help
mailing list