Skip to content

lm - log(variable) - skip log(0)

5 messages · agent dunham, Liaw, Andy, David Winsemius

#
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
#
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
4263p3324263.html
Notice:  This e-mail message, together with any attachme...{{dropped:11}}
#
Apologies, I'm really new with R, Can you help me with the syntax?

here is my data.frame in which I introduce independent variables:
varind has dimensions(194, 6), in case that's necessary. Then I type:
Error en model.frame.default(formula = log(datpos$IncAltuDom) ~ log(varind), 
: 
  invalid type (list) for variable 'log(varind)'

Thanks again,
#
Apologies, I'm really new with R, Can you help me with the syntax? 

here is my data.frame in which I introduce independent variables:
varind has dimensions(194, 6), in case that's necessary. Then I type:
Error en model.frame.default(formula = log(datpos$IncAltuDom) ~ log(varind), 
: 
  invalid type (list) for variable 'log(varind)' 

Thanks again,user at host.com
#
On Feb 25, 2011, at 7:25 AM, agent dunham wrote:

            
Because varind is now a dataframe, you need to refer to its columns  
when offering candidate independent variables to lm. It is not clear  
which column you wanted to test for positivity and  which use on the  
RHS from varind. You should also get in the habit of:

--- including context in followup questions
--- using the data= argument in model construction

Going back to your original question where the dataframe was named  
"dat"and it was clear what variable you wanted on the RHS:

lmod1.lm <- lm( log(inaltu)~log(indiam), data= dat, subset=(indiam > 0  
& inaltu > 0)  )