Re: [R] using predict.lm() within a function

2011-10-24 Thread Dennis Murphy
Hi Michael: Try this: show.beta <- function(model, x = 'x', x1, x2, label, col="black", ...) { abline(model, col=col, lwd=2) xs <- data.frame(c(x1, x2, x2)) names(xs) <- attr(model$coefficients, 'names')[2] ys <- predict(model, xs) lines(cbind(xs,ys[c(1,1,2)])

[R] using predict.lm() within a function

2011-10-24 Thread Michael Friendly
I've written a simple function to draw a regression line in a plot and annotate the line showing the slope with a label. It works, as I'm using it, when the horizontal variable is 'x', but gives incorrect results otherwise. What's wrong? # simple function to show the slope of a line show.beta