Reputation: 1
I drew the confidence ellipse for mu1 and mu 2 i used following code based on means and variance inverse I got but the ellipse came out as Y shape:
library(car)
library(SIBER)
ellipse<-function(mu1,mu2)
{
30*1.155461e-05*(1860.500-mu1)^2+ 30*4.11493e-07*(8354.133-mu2)^2
- 60*1.98504e-06*(1860.500-mu1)*(8354.133-mu2)
}
mu1<-seq(1650,2100,50)
mu2<-seq(7000,9500,50)
z <- t(sapply(mu1,ellipse,mu2))
contour(mu1,mu2,z,
levels=6.91,
drawlabels=T,
axes=T,
frame.plot=T,
xlab="mu1 (stf)",
ylab="mu2 (ben strnegth)",
main = "A 95% confidence ellipse for mu = (mu1,mu2)")
points(1860.5,8354.133)
segments(0,8354.133,1860.500,8354.133)
segments(1860.500,0,1860.500,8354.133)
Upvotes: 0
Views: 51
Reputation: 226172
A surprisingly subtle typo. In your function definition,
ellipse<-function(mu1,mu2) {
30*1.155461e-05*(1860.500-mu1)^2+ 30*4.11493e-07*(8354.133-mu2)^2
- 60*1.98504e-06*(1860.500-mu1)*(8354.133-mu2)
}
you broke the line before the minus sign; the first line is a complete R expression, so R computes it (and discards the result since you didn't assign it to a value), and then computes the second line as a second expression and returns it. In other words, your function is only returning the cross-term (60*1.98504e-06 ...
).
Possible solutions:
You may find the ellipse
package or the ellipse
function in the car
package useful ...
Upvotes: 2