Hello again, First I want to thank all the people who answered my question about line width in graphs. I promise I will learn the 'par' help page by heart for the end of the month ! I now want to trace some ellipses to emphasize groups of data. I found how to trace circles with 'symbols()', but no ellipse. I'm planning on writing my own function based on 'polygon()' and the ellipse equation. Does anybody already have done similar work or have another solution ? Thanks again, -- Ir. Yves Brostaux - Statistics and Computer Science Dpt. Gembloux Agricultural University 8, avenue de la Facult? B-5030 Gembloux (Belgium) T?l : +32 (0)81 62 24 69 E-mail : brostaux.y at fsagx.ac.be Web : http://www.fsagx.ac.be/si/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "Yves" == Yves Brostaux <brostaux.y at fsagx.ac.be> writes:Yves> Hello again, Yves> First I want to thank all the people who answered my Yves> question about line width in graphs. I promise I will Yves> learn the 'par' help page by heart for the end of the Yves> month ! Yves> I now want to trace some ellipses to emphasize groups Yves> of data. I found how to trace circles with Yves> 'symbols()', but no ellipse. I'm planning on writing Yves> my own function based on 'polygon()' and the ellipse Yves> equation. Does anybody already have done similar work Yves> or have another solution ? yes. several. 1) The ellipse package does some. 2) The cluster package (which is recommended, hence should be available everywhere) has an ellipsoidhull() function and a plot method for its results (in the 2D case, i.e when the ellipsoid is an ellipse) 3) A `client' (researcher in another department here) needed something based on geometric parameters rather than covariance matrices. So I ended up doing the following, I hope it helps. Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< ------------------------------------------------------------------- ## Martin's Solution : radially equispaced ("radial gleichm?ssig") : ellipsePoints <- function(a,b, alpha = 0, loc = c(0,0), n = 201) { ## Purpose: ellipse points,radially equispaced, given geometric par.s ## ------------------------------------------------------------------------- ## Arguments: a, b : length of half axes in (x,y) direction ## alpha: angle (in degrees) for rotation ## loc : center of ellipse ## n : number of points ## ------------------------------------------------------------------------- ## Author: Martin Maechler, Date: 19 Mar 2002, 16:26 B <- min(a,b) A <- max(a,b) ## B <= A d2 <- (A-B)*(A+B) #= A^2 - B^2 phi <- 2*pi*seq(0,1, len = n) sp <- sin(phi) cp <- cos(phi) r <- a*b / sqrt(B^2 + d2 * sp^2) xy <- r * cbind(cp, sp) ## xy are the ellipse points for alpha = 0 and loc = (0,0) al <- alpha * pi/180 ca <- cos(al) sa <- sin(al) xy %*% rbind(c(ca, sa), c(-sa, ca)) + cbind(rep(loc[1],n), rep(loc[2],n)) } ## Example: ep <- ellipsePoints(2,5) str(ep) plot(ep, type="n",asp=1) ; polygon(ep, col = 2) ## Movie : rotating ellipse : nTurns <- 4 # #{full 360 deg turns} for(al in 1:(nTurns*360)) { ep <- ellipsePoints(3,6, alpha=al, loc = c(5,2)) plot(ep,type="l",xlim=c(-1,11),ylim=c(-4,8), asp=1, axes = FALSE, xlab="", ylab="") } ## Movie : rotating _filled_ ellipse : for(al in 1:180) { ep <- ellipsePoints(3,6, alpha=al, loc = c(5,2)) plot(ep,type="n",xlim=c(-1,11),ylim=c(-4,8), asp=1, axes = FALSE, xlab="", ylab="") polygon(ep,col=2,border=3,lwd=2.5) } -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Yves,> I now want to trace some ellipses to emphasize groups of data. I found how > to trace circles with 'symbols()', but no ellipse. I'm planning on writing > my own function based on 'polygon()' and the ellipse equation. Does anybody > already have done similar work or have another solution ? >I believe the ellipse library will do this for you. Try> install.packages("ellipse")Otherwise, I have a function which will do something similar. I wrote it ages ago but it still works fine: # begin ellipse ellipse <- function(x,y, width,height=width,theta=2*pi, npoints=100,plot=T) { # x = x coordinate of center # y = y coordinate of center # width = length of major axis # height = length of minor axis # theta = rotation # npoints = number of points to send to polygon # plot = if TRUE, add to current device # = if FALSE, return list of components a <- width/2 b <- height/2 xcoord <- seq(-a,a,length=npoints) ycoord.neg <- sqrt(b^2*(1-(xcoord)^2/a^2)) ycoord.pos <- -sqrt(b^2*(1-(xcoord)^2/a^2)) xx <- c(xcoord,xcoord[npoints:1]) yy <- c(ycoord.neg,ycoord.pos) x.theta <- xx*cos(2*pi-theta)+yy*sin(2*pi-theta)+x y.theta <- yy*cos(2*pi-theta)-xx*sin(2*pi-theta)+y if(plot) invisible(polygon(x.theta,y.theta,density=0)) else invisible(list(coords=data.frame(x=x.theta,y=y.theta), center=c(x,y), theta=theta)) } # end ellipse Regards, Sundar -- Sundar Dorai-Raj, Ph.D. Statistical Methods Engineer PDF Solutions, Inc. Richardson TX (972) 889-3085 x216 (214) 392-7619 cell sundar.dorai-raj at pdf.com -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hello, I have fitted a multivariate linear model using lm() but then I cannot apply any function available for diagnostics, such as lm.influence(), rstudent() etc. I get the following error message when calling any of the above functions. "Error in lm.influence(model1) : non-NA residual length does not match cases used in fitting" I have tried with two different data sets. One of them follows: y [,1] [,2] [1,] 2 4 [2,] 1 -2 [3,] 3 -2 [4,] 0 -1 x [,1] [1,] 1 [2,] 2 [3,] 3 [4,] 4 The command for the fit is simply: lm(y ~ x) which runs properly. Are the diagnostic measures only available for univariate linear models? Thanks Daniel Mastropietro -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "Daniel" == Daniel Mastropietro <mastropi at uwalumni.com> writes:Daniel> I have fitted a multivariate linear model using lm() Daniel> but then I cannot apply any function available for Daniel> diagnostics, such as lm.influence(), rstudent() Daniel> etc. I get the following error message when calling Daniel> any of the above functions. Daniel> "Error in lm.influence(model1) : non-NA residual Daniel> length does not match cases used in fitting" .... Daniel> The command for the fit is simply lm(y ~ x) Daniel> which runs properly. Daniel> Are the diagnostic measures only available for Daniel> univariate linear models? currently, yes. Improvements to the code (and docu) are very welcome! R is an open & volunteer project. Regards, Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._