[R] lm - log(variable) - skip log(0)

Liaw, Andy andy_liaw at merck.com
Fri Feb 25 12:58:48 CET 2011


You need to use "==" instead of "=" for testing equality.  While you're at it, you should check for positive values, not just screening out 0s.  This works for me:

R> mydata = data.frame(x=0:10, y=runif(11))
R> fm = lm(y ~ log(x), mydata, subset=x>0)
 
Andy


> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of agent dunham
> Sent: Friday, February 25, 2011 6:24 AM
> To: r-help at r-project.org
> Subject: [R] lm - log(variable) - skip log(0)
> 
> 
> 
> I want to do a lm regression, some of the variables are going 
> to be affected
> with log, I would like not no take into account the values 
> which imply doing
> log(0) 
> 
> for just one variable I have done the following but it doesn't work: 
> 
> lmod1.lm <- 
> lm(log(dat$inaltu)~log(dat$indiam),subset=(!(dat$indiam %in%
> c(0,1))) 
> 
> and obtain: 
> 
> Error en lm.fit(x, y, offset = offset, singular.ok = 
> singular.ok, ...) : 
>   0 (non-NA) cases 
> 
> lmod1.lm <- 
> lm(log(dat$inaltu)~log(dat$indiam),subset=(!(dat$indiam = 0)),
> na.action=na.exclude) 
> 
> and obtain 
> 
> Error en lm.fit(x, y, offset = offset, singular.ok = 
> singular.ok, ...) : 
>   NA/NaN/Inf en llamada a una función externa (arg 1)
> 
> Thanks, user at host.com
> -- 
> View this message in context: 
> http://r.789695.n4.nabble.com/lm-log-variable-skip-log-0-tp332
4263p3324263.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at 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.
> 
Notice:  This e-mail message, together with any attachme...{{dropped:11}}



More information about the R-help mailing list