Thanks Duncan and David

for opening my eyes :-). It took quite a while but I think I learned a
lot about lm today. I used your advice to produce "added variable
plots" as mentioned here [1], [2]. I would bet someone did it in R
already (may leverage.plot in car) but it was worth doing it myself.

Kind regards,
Karsten.

[1] http://www.minitab.com/support/documentation/answers/AVPlots.pdf
[2] 
http://www.mathworks.com/access/helpdesk/help/toolbox/stats/addedvarplot.html

plotAddedVar.lm <- function(
    linModel,
    termName,
    main="",
    xlab=paste(termName, " | andere"),
    ylab=paste(colnames(linModel$model)[1], " | andere"),
    cex=0.7, ...) {

    oldpar <- par(no.readonly = TRUE); on.exit(par(oldpar))
    par(mar=c(3,4,0.4,0)+0.1, las=1, cex=cex)

    yData = residuals(update(linModel, substitute(. ~ . - x,
list(x=as.name(termName)))))
    xData = residuals(update(linModel, substitute(x ~ . - x,
list(x=as.name(termName)))))

    plot(xData, yData, main=main, xlab="", ylab="")
    mtext(side=2, text=ylab, line=3, las=0, cex=cex)
    mtext(side=1, text=xlab, line=2, las=0, cex=cex)
    abline(h=0)
    abline(a=0, b=coefficients(linModel)[termName], col="blue")
}

plotAddedVar <- function(linModel,...) UseMethod("plotAddedVar")

______________________________________________
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