r - Error in GLM fitting -
i have working glm , have variables "surface" , "price", these numeric. add them log variant model.
in order did follows;
data$logprice<-log(data$price)
then added model follows;
model <- glm(variablea ~ logprice + variableb +variablec , binomial)
and when added log following error;
error in glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, :
na/nan/inf in 'x'
hope can me explain error, or guide me in how fix it. in advance!
you didn't provide data or runnable code, it's impossible caused error in case. however, have pretty idea.
i can show in general not case:
data(iris) iris$logprice <- log(iris$sepal.length) iris$variablea <- ifelse(iris$species=="setosa",1,0) model <- glm(variablea ~ logprice, binomial, data = iris) summary(model)
call: glm(formula = variablea ~ logprice, family = binomial, data = iris) deviance residuals: min 1q median 3q max -2.28282 -0.29561 -0.06431 0.29645 2.13240 coefficients: estimate std. error z value pr(>|z|) (intercept) 46.767 7.978 5.862 4.58e-09 *** logprice -27.836 4.729 -5.887 3.94e-09 *** --- signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (dispersion parameter binomial family taken 1) null deviance: 190.954 on 149 degrees of freedom residual deviance: 72.421 on 148 degrees of freedom aic: 76.421 number of fisher scoring iterations: 7
however, let's have value 0 cannot survive log transformation without being infinite:
iris$sepal.length[1] <- 0 iris$logprice <- log(iris$sepal.length) iris$variablea <- ifelse(iris$species=="setosa",1,0) model <- glm(variablea ~ logprice, binomial, data = iris)
error in glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, : na/nan/inf in 'x'
why? because:
> log(0)
[1] -inf
one solution (which kind of hack) add tiny bit of jitter, or replace 0 infinitesimally small value. however, if makes statistical , research sense beyond scope of answer.
if have na values can drop or impute those.
Comments
Post a Comment