[R] abline() or predict.lm() when log="x"
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Fri Jan 20 22:29:34 CET 2006
Richard Chandler <rchandler at forwild.umass.edu> writes:
> Hello,
>
> I'm trying to plot a fitted lm() line on a plot when the one
> explanatory variable is log transformed and log="x". I get different
> lines using abline and predict.lm().
>
> #Example
> x <- 1:100
> y <- rnorm(100)
> plot(y ~ x, log="x")
> abline(lm(y ~ log(x)))
> lines(x, predict(lm(y ~ log(x))), lwd=2)
>
> I'm sure I'm missing something but could someone tell me which line is
> correct? Thanks.
Base 10 is what you're missing.
The latter form is agnostic with respect to base, the former is not
(since the fitted values are the same, but regression coefficients
differ). So you need to know to use abline(lm(y ~ log10(x))).
You don't really notice which kind of log is being used until you look
at par(usr) for a plot with logged axes.
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list