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))

______________________________________________
R-help@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.

Reply via email to