[R] lm( ) for log10-transformed data

Duncan Murdoch murdoch at stats.uwo.ca
Tue Aug 7 21:56:23 CEST 2007


On 8/7/2007 2:58 PM, Kim Milferstedt wrote:
> Dear help-list,
> 
> I would like to perform a linear regression on the log10 of the two 
> vectors ov.mag.min and res.600nm. The slope and intercept of the 
> regression I use to plot a wider range of ov.mag.min in a double log plot.
> 
> For a linear regression on only tow points, wouldn't I expect the 
> results for two.points.min to match pretty exactly res.600nm? It does 
> not seem to be the case here. I manually calculated the slope and 
> intercept and got values of -0.71 and 1.5 that seem to work alright. 
> What is it that I am missing here?
> 
> Thanks already for your help,
> 
> Kim
> 
> ov.mag.min <- c(50, 1000)
> res.600nm <- c(2.0, 0.231)
> 
> 
> lm.line.min <- lm(      log(ov.mag.min,10)
>                                  ~
>                                  log(res.600nm,10)
>                      )
> 
> intercept.min  <- lm.line.min$coefficients[1]
> slope.min <- lm.line.min$coefficients[2]
> 
> 
> two.points.min <- log(ov.mag.min,10)
> 
> round(res.600nm,2) == 
> round(10^(two.points.min*slope.min+intercept.min),2)
> 
> round(res.600nm,2)
> round(10^(two.points.min*-0.71+1.5),2)

The convention in the lm() function is to express a model as
response ~ predictor.  So you should expect

round(ov.mag.min,2) == round(10^(log(res.600nm, 
10)*slope.min+intercept.min),2)

not the other way around, and this does evaluate to two TRUE values.

Duncan Murdoch



More information about the R-help mailing list