Solved – log-log regression in r

logarithmrregression

I want to do a log-log regression in R.
I managed to do a simple linear and log-linear regression by using this code:

lm <- lm(Price ~ ., data=data_price2)
lm2 <- lm(log(Price) ~ ., data=data_price2)

Now, I want to do a log-log regression, but I can't find out how to add the independent variables in the logarithmic form. Some of these independent variables are dummy variables.
If I add them individually after the '~' in the equation, R gives me this error:

lm4 <- lm(log(Price) ~ log(nbrCores)+ log(nbrSims) + log(CameraBack), data = data_price2)

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, …) :
NA/NaN/Inf in 'x'

I have about 140 independent variables, so I prefer not to add them manually.

Can anyone help me with this?

Best Answer

You have to take care if you pass zero to a log function. Avoid this procedure.

You can use a map function and use log to only variable with factors >0.

However you don't need to apply log to all variable of the function. You only need to apply log to the target.