Skip to content
Back to formatted view

Raw Message

Message-ID: <4B59EE2A.7040400@stats.uwo.ca>
Date: 2010-01-22T18:27:54Z
From: Duncan Murdoch
Subject: 3d trend line
In-Reply-To: <1264168368134-1100043.post@n4.nabble.com>

On 22/01/2010 8:52 AM, mlcarte3 wrote:
> Which line do you want?  There's more than one choice.  For example, you 
> could regress y and z on x, or you could find the principle axis of the 
> x, y, z point cloud.
>
> Duncan Murdoch
>
>
> Thanks for the response. I need to find the principal axis for the point
> cloud. How can I plot this in R?
>   

This will do it:

# Generate some correlated data
x <- matrix(rnorm(3000)+2:4, ncol=3)
y <- x %*% matrix(c(1,-2,3,2,3,4,3,4,4), 3,3)

# Plot it
library(rgl)
plot3d(y)

# Compute the principle components
pc <- princomp(y)

# Plot a line corresponding to the main one
centre <- pc$center
direction <- pc$loadings[,1]
segments3d(rbind(min(pc$scores[,1])*direction + centre,
                 max(pc$scores[,1])*direction + centre))