[R] DataEllipse versus Ellipse Function in R

John Fox jfox at mcmaster.ca
Sun Sep 15 15:16:31 CEST 2013


Dear Anamika Chaudhuri,

On Sat, 14 Sep 2013 21:04:42 -0400
 Anamika Chaudhuri <canamika at gmail.com> wrote:
> Hi:
> 
> Does Ellipse and dataellipse function in R produce the same ellipse? I
> wanted to see how the radius for the Ellipse function in R calculated. Also
> what is the var-covariance matrix, if any, assumed for the dataellipse
> function? Heres an example of the code where I am generating Multivariate
> normal data and creating ellipse using the 2 functions:
> 
> 
> library(car)
>   library(mvtnorm)
> 
>   mu = c(0,0)
>   sigma = matrix(c(20,0,0,45),nrow=2)
> 
>   z = rmvnorm(10000,mu,sqrt(sigma))
> 
>   dataEllipse(z,levels=.95)
>   car::ellipse(mu, sigma*qchisq(.05,2), col="blue", radius=sqrt(2 *
> qf(.975, 2, 9998)) )
> 
> Any help is appreciated.
> Thanks
> Anamika

As explained in ?ellipse, the ellipse() function draws an ellipse, dataEllipse() draws data ellipses (i.e., estimated concentration ellipses assuming bivariate normality), and confidenceEllipse() draws confidence ellipses. 

The latter two functions call ellipse(), so yes, you can use either ellipse() or dataEllipse() to draw a data ellipse, but you made five mistakes:

(1) In generating the data, you probably intended to use sigma rather than sqrt(sigma) for the covariance matrix. If for some unusual reason you really wanted to take the square roots of each of the elements of sigma, then the "size" matrix supplied to ellipse() should also have used sqrt(sigma) for consistency.

(2)  The "size" doesn't involve a chisq quantile.

(3)  The quantile for the F distribution should be .95, not .975.

(4)  The denominator df are n - 1 not n - 2.

(5)  You used the population means and tried to use the population covariance matrix rather than the sample means and covariance matrix.

Thus, to get the 95% concentration ellipse for your unusually generated data, you could use

ellipse(colMeans(z), cov(z), col="blue", radius=sqrt(2 * qf(.95, 2, 9999)) )

Best,
 John


>
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.

------------------------------------------------
John Fox
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/



More information about the R-help mailing list