Skip to content

Adding axis to an ellipse: "ellipse" package

2 messages · Antoine, Rolf Turner

#
Dear Rolf,

I tryed to follow your advices but the results I am getting seems still
strange to me. See below an example of a matrix:

datamat <- matrix(c(2.2, 0.4, 0.4, 2.8), 2, 2)
plot(ellipse(datamat),type='l')
eigenval <- eigen(datamat)$values
eigenvect <- eigen(datamat)$vectors
eigenscl  <- eigenvect * sqrt(eigenval) * (qchisq(0.95,2))# One solution to
get rescale

v1 <- (eigenvect[,1])*(sqrt(eigenval[1]))*(qchisq(0.95,2))#or directly
rescale the vectors needed
v2 <- (eigenvect[,2])*(sqrt(eigenval[2]))*(qchisq(0.95,2))
#Or
v1 <- eigenscl[1,]
v2 <- eigenscl[2,]
segments(-v1[1],-v1[2],v1[1],v1[2])
segments(-v2[1],-v2[2],v2[1],v2[2])

The vectors don't seem to be scaled properly and I don't see what I am doing
wrong. Any ideas?

Thanks!
Antoine

--
View this message in context: http://r.789695.n4.nabble.com/Adding-axis-to-an-ellipse-ellipse-package-tp3847954p3862491.html
Sent from the R help mailing list archive at Nabble.com.
#
See comments in-line:
On 01/10/11 23:26, Antoine wrote:
This is wrong because you are multiplying the i-th row of ``eigenvect''
     the square root of the i-th eigenvalue.  The *columns* of ``eigenvect''
     are the eigenvectors.  So you need to multiply the j-th column by
     the square root of the j-th eigenvalue.
The foregoing is correct except that you need to take the square
     root of the chi-squared quantile.
Here is correct code:

require(ellipse)
S <- matrix(c(2.2, 0.4, 0.4, 2.8), 2, 2)
# Note the ``asp=1'' which makes orthogonal lines
# look orthogonal:
plot(ellipse(S),type='l',asp=1)
E <- eigen(S)
Val <- E$values
Vec <- E$vectors
v1 <- sqrt(Val[1]*qchisq(0.95,2))*Vec[,1]
v2 <- sqrt(Val[2]*qchisq(0.95,2))*Vec[,2]
segments(-v1[1],-v1[2],v1[1],v1[2])
segments(-v2[1],-v2[2],v2[1],v2[2])

     cheers,

         Rolf Turner