Re: [R] abline() or predict.lm() when log="x"

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Sat 21 Jan 2006 - 08:29:34 EST

Richard Chandler <rchandler@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@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat Jan 21 08:41:14 2006

This archive was generated by hypermail 2.1.8 : Sat 21 Jan 2006 - 10:24:39 EST