Help with Inf with log generating in log-linear model

Hello, I am a newbie trying to learn R-studio and faced a problem on the beginning day.
I am trying to generate a log-linear model by using these equations :

model3 <-lm(log(oprc)~log(odmd)+log(ofreq)+log(dist)+log(kgdp)+log(dgdp)+log(poil)+log(trade)
+fra+lon+par+vie+atl+chi+dfw+lax+nyc)

and found out that it says
"Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 'x' NA/NaN/Inf"

Im guessing its because of the 0s in the dataset(odmd & ofreq) since log(0) = -INF
(there's no 0s in other columns, but only in odmd & ofreq)

Can you guys tell me how to work things out without getting the errors?

You might delete the rows where odmd == 0, especially if you think the true number isn't zero and is perhaps an indication of a missing value. There are other "tricks," such as replacing log(odmd) with log(odmd+1), but such tricks do introduce distortions.

Like startz mentioned, you can slightly tweak the data so there are near zero rows. Something like this would work:

ifelse(data == 0, 0.1, data)

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.