Just define your own panel function.  Here I modified the panel.ellipse
function and called it panel.lm

library(corrgram)
data(baseball)
vars2 <- c("Assists","Atbat","Errors","Hits","Homer","logSal",
                "Putouts","RBI","Runs","Walks","Years")
panel.lm <- function(x, y, ...){
  dfn <- 2
  dfd <- length(x) - 1
  shape <- var(cbind(x, y), na.rm = TRUE)
  keep <- (!is.na(x) & !is.na(y))
  center <- c(mean(x[keep]), mean(y[keep]))
  radius <- sqrt(dfn * qf(0.68, dfn, dfd))
  segments <- 75
  angles <- seq(0, 2 * pi, length = segments)
  unit.circle <- cbind(cos(angles), sin(angles))
  ellipse.pts <- t(center + radius * t(unit.circle %*% chol(shape)))
  ellx <- ellipse.pts[, 1]
  elly <- ellipse.pts[, 2]
  usr <- par()$usr
  minx <- usr[1]
  maxx <- usr[2]
  miny <- usr[3]
  maxy <- usr[4]
  ellx <- ifelse(ellx < minx, minx, ellx)
  ellx <- ifelse(ellx > maxx, maxx, ellx)
  elly <- ifelse(elly < miny, miny, elly)
  elly <- ifelse(elly > maxy, maxy, elly)
  lines(ellx, elly, col = "gray30", ...)
  #ok <- is.finite(x) & is.finite(y)
  #if (any(ok))
  #  lines(stats::lowess(x[ok], y[ok], f = 2/3, iter = 3),
  #        col = "red", ...)
  abline(coef(lm(y~x)), col="red")
}
corrgram(baseball[,vars2], order=TRUE,
         main="Baseball correlation ellipses",
         panel=panel.lm, text.panel=panel.txt, diag.panel=panel.minmax)

Kevin Wright


On Thu, Aug 19, 2010 at 7:07 AM, ashz <a...@walla.co.il> wrote:

>
> Dear all,
>
> I generated a Correlograms and used the panel.ellipse (confidence ellipse
> and smoothed line) option. Is there a way to get instead of the smoothed
> line the linear regression?
>
> Thanks,
> As hz
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Correlograms-and-linear-regression-tp2331071p2331071.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>



-- 
Kevin Wright

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to