Seeking for advise how to debug the Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in 'x'

Hi everyone,

I have encountered similar issue whereby someone posted before. I had check my data frame all are numeric. Despite i followed the method proposed the result still the same. Appreciate anyone if can assist.

p/s: If I run for normal lm without log, it will be fine. However i need to build a better model as the p-value is more than 0.05

'data.frame': 50 obs. of 4 variables:
RDSpend : num 165349 162598 153442 144372 142107 ...
Administration: num 136898 151378 101146 118672 91392 ...
MarketingSpend: num 471784 443899 407935 383200 366168 ...
Profit : num 192262 191792 191050 182902 166188 ...

model_profit2 <- lm(Profit ~ RDSpend + log(MarketingSpend), data = Startups50)
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
NA/NaN/Inf in 'x'

Startups50$RDSpend <- as.numeric(gsub("\.", "", Startups50$RDSpend))
FIT <- lm(Profit ~ RDSpend + log(MarketingSpend), data = Startups50)
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
NA/NaN/Inf in 'x'

Are any of your MarketingSpend values equal to 0 ? i.e. no spending
if you log that it will become -Inf. and thats a problem.
You could dogde it by pretending that any marketing spend of 0 is really one millionth of a unit of currency, and then log it, so you get a numeric result.

Thanks for the highlighting. I have cross check my data set and it shows 3 cells zero in MarketingSpend. However I'm not very understand how's the way to solve it. Do I need to create near zero dummy for those cell? Can you show an example?

Hope can hear you soon.

library(tidyverse)
model_profit2 <- lm(Profit ~ RDSpend + log(MarketingSpend), 
data = mutate_all(Startups50,~ifelse(.==0,10^-16,.)))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.