Hi, Suppose I I wish to run lm( y ~ x + z + log(w) ) where w assumes non-negative values. A problem arises when w=0, as log(0) = -Inf, and R doesn't accept that (as it "accepts" NA). Is there a way to tell R to do with -Inf the same it does with NA, i.e, to ignore it? ( Otherwise I have to do something like w[w==0] <- NA which doesn't hurt, but might be a bit incovenient sometimes.) Thanks in advance. Dimitri
you could use: lm( y ~ x + z + log(w), subset = w > 0) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Dimitri Szerman" <dimitrijoe at ipea.gov.br> To: "R-Help" <r-help at stat.math.ethz.ch> Sent: Tuesday, October 25, 2005 4:47 PM Subject: [R] Inf in regressions> Hi, > > Suppose I I wish to run > > lm( y ~ x + z + log(w) ) > > where w assumes non-negative values. A problem arises when w=0, as > log(0) > = -Inf, and R doesn't accept that (as it "accepts" NA). Is there a > way to > tell R to do with -Inf the same it does with NA, i.e, to ignore it? > ( > Otherwise I have to do something like > > w[w==0] <- NA > > which doesn't hurt, but might be a bit incovenient sometimes.) > > Thanks in advance. > > Dimitri > > ______________________________________________ > R-help at 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 >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Actually, R does not accept NA. First, the action is from lm and not from the R base, and second, NAs are in fact deleted and not accepted. Function lm() has a na.action argument which is by default na.omit. You could easily make na_and_inf.omit and use it. You could also use subset=(w > 0). The help pages are your friends here. On Tue, 25 Oct 2005, Dimitri Szerman wrote:> Suppose I I wish to run > > lm( y ~ x + z + log(w) ) > > where w assumes non-negative values. A problem arises when w=0, as log(0) > = -Inf, and R doesn't accept that (as it "accepts" NA). Is there a way to > tell R to do with -Inf the same it does with NA, i.e, to ignore it? ( > Otherwise I have to do something like > > w[w==0] <- NA > > which doesn't hurt, but might be a bit incovenient sometimes.)-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595