[R] nlme errors ?

Ramon Diaz-Uriarte rdiazuri at students.wisc.edu
Wed Jul 5 18:09:52 CEST 2000


Just in case these plotting functions are of help to anybody, here they go. I
wrote them a while ago, and use them routinely as diagnostics for linear mixed
effects models (most of them follow ideas in ch. 4 of Pinheiro & Bates's
"Mixed-effects models in S and S-Plus").  I know they are not very well
written and there is a lot of room for improvement (in fact, I never intended
for them to be seen by anybody but me, and thus being sloppy didn't
have to embarrass me...); for instance, the data set needs to be attached for
the plots to work, some of them don't work if you have missing values, and 
the par settings are changed; these are all easy to fix (but I am lazy...).

Ramón

***************

lme.plot1 <- function(fit, resid="p",...){
### resids by fitted, qqnorm of resids, observed by fitted
  xx <- attributes(terms.formula(fit$call[[2]]))$variables[[2]]
  par(ask = TRUE)
  plot( resid(fit,type = resid) ~ fitted(fit), xlab="Fitted values", las=1)
  qqnorm(resid(fit,type = resid), las=1)
  plot( eval(xx) ~ fitted(fit), ylab = deparse(xx), xlab = "Fitted values", las = 1)
  qqnorm( ranef(fit, level = length(attributes(ranef(fit))$grpNames)), main = "Random effects")
  par(ask = FALSE)

}


lme.plot2 <- function(fit, resid="p", jit.am = 0){
###to plot residuals vs. levels of predictors
  zz <- attributes(terms.formula(fit$call[[2]]))$variables
  ## print("there are a bunch of plots, keep pressing")
  ## print(c("to see all; total number of plots are ",(length(zz) - 2) ))
  par(ask = TRUE)
  par(las = 1)
  for (i in 1:(length(zz) - 2)) {
    plot( resid(fit,type = resid) ~ jitter(as.numeric(eval(zz[[i + 2]])), amount=jit.am), xlab = deparse(zz[[i + 2]]))
    abline(h = 0, lty = 2)
  }
  par(ask = FALSE)
}


lme.plot3 <- function(fit, resid = "p",...){
### to plot residuals vs. fitted for each level of the predictors with coplot
  zz <- attributes(terms.formula(fit$call[[2]]))$variables
  par(ask = TRUE)
  par(las = 1)
  for (i in 1:(length(zz) - 2)) coplot(resid(fit,type = resid) ~ fitted(fit)|eval(zz[[i+2]]), xlab=deparse(zz[[i + 2]]), ...)
  par(ask = FALSE)
}

*******************


-- 
Ramón Díaz-Uriarte
Dept. Zoology and Statistics
University of Wisconsin-Madison
Madison, WI 53706-1381

email: rdiazuri at students.wisc.edu
(NOTE: starting 15-July-2000 new email:
ramon-diaz at teleline.es)
phone: 608-238-8041
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list