[R] ploting an ellipse keeps giving errors
Charles Annis, P.E.
Charles.Annis at StatisticalEngineering.com
Wed Oct 27 11:50:45 CEST 2004
I apologize to the original contributor whom I have forgotten, but here is a
function that does what you wish. It is not mine and was contributed some
time ago. I saved it because it is so useful.
##############################
ellipse.fn <- function(loc, cov, confidence = 0.95)
{
A <- cov
detA <- A[1, 1] * A[2, 2] - A[1, 2]^2
dist <- sqrt(qchisq(confidence, 2))
ylimit <- sqrt(A[2, 2]) * dist
y <- seq( - ylimit, ylimit, 0.01 * ylimit)
sqrt.discr <- sqrt(detA/A[2, 2]^2 * (A[2, 2] * dist^2 - y^2))
sqrt.discr[c(1, length(sqrt.discr))] <- 0
b <- loc[1] + A[1, 2]/A[2, 2] * y
x1 <- b - sqrt.discr
x2 <- b + sqrt.discr
y <- loc[2] + y
return(rbind(cbind(x1, y), cbind(rev(x2), rev(y))))
}
### example of ellipse
x <- 60 + 15 * rnorm( 200 )
y <- 50 + .8 * x + 10 * rnorm( 200 )
plot( x, y )
lines( ellipse.fn( c(mean(x),mean(y)), var(cbind(x,y)), .95 ), col=2 )
##############################
I pray that the originator will forgive my posting without attribution.
Charles Annis, P.E.
Charles.Annis at StatisticalEngineering.com
phone: 561-352-9699
eFax: 503-217-5849
http://www.StatisticalEngineering.com
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Sun
Sent: Wednesday, October 27, 2004 5:25 AM
To: Petr Pikal
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] ploting an ellipse keeps giving errors
Thank you. I found there are two ellipses
1.
R2.0
library (car)
2.
R1.9 and R2.0
library (ellipse)
And they are different! I can't run 1.
But the 2. is kind of specialized for t-distribution confidence and so on.
I need to find a general ellipse for an ellipse equation like
(x-x0)^2/a + (y-y0)^2/b =1
. Since I used chi-square percentile not t. I am trying to obtain the large
sample 95% simultaneous confidence ellipse for two population means (say,
weight and height). The input are the two sample means and their
covariances.
Maybe I have to make my own ellipse function.
Sun
----- Original Message -----
From: "Petr Pikal" <petr.pikal at precheza.cz>
To: "Sun" <sun at cae.wisc.edu>
Cc: <r-help at stat.math.ethz.ch>
Sent: Wednesday, October 27, 2004 4:14 AM
Subject: Re: [R] ploting an ellipse keeps giving errors
> Hi
>
> Did you read what ellipse does and how it shall be used?
>
> And what about your system, R and ellipse version?
>
> From your example i got
>
> > ellipse (center = c(0,0), shape = shape1, radius = 1)
> Error in ellipse.default(center = c(0, 0), shape = shape1, radius =
> 1) :
> Argument "x" is missing, with no default
>
> Ellipse is not for drawing arbitrary ellipses but has different usage.
>
> See its help page and an example.
>
> Cheers
> Petr
>
>
>
>
> On 27 Oct 2004 at 3:34, Sun wrote:
>
> >
> > library (ellipse)
> >
> > shape1 = c (1, 0, 0,1)
> > dim(shape1) = c(2,2)
> > ellipse (center = c(0,0), shape = shape1, radius = 1)
> >
> > =============================
> > Error in plot.xy(xy.coords(x, y), type = type, col = col, lty = lty,
> > ...) :
> > plot.new has not been called yet
> >
> >
> > It is really frustrating. Also what do the shape matrix, radius
> > correspond to an ellipse function
> >
> > (x-x0)^2/a + (y-y0)^2/b = 1
> >
> > ? Please advise!
> >
> > Many thanks,
> >
> > Sun
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
>
> Petr Pikal
> petr.pikal at precheza.cz
>
>
>
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list