# How NA in a model will impact on predict?

I wrote a script that create a logistic model, for Email opening probability, for each user name.

form<-formula(OpenOrNor~as.factor(TimeSend)
+OpenWithSmartphoneind)
models<- dlply(Data, "User_id",
function(df) {
model<-glm(formula = form,family = binomial("logit"),data = df,control = glm.control(epsilon = 1e-9, maxit = 500))
return(model)})


for some users it return me

Call:  glm(formula = form, family = binomial("logit"), data = df, weights = HistoryWeights,
control = glm.control(epsilon = 0.000000001, maxit = 500))

Coefficients:
(Intercept)            as.factor(TimeSend)2      as.factor(TimeSend)3   as.factor(TimeSend)4
-22.61106                   20.21853                    0.07738                   20.54737
as.factor(TimeSend)5       as.factor(TimeSend)6      as.factor(TimeSend)7   as.factor(TimeSend)9
0.19292                   -0.03624                    0.22013                    0.11837
OpenWithSmartphoneind
NA

Degrees of Freedom: 83 Total (i.e. Null);  76 Residual
Null Deviance:      190.6
Residual Deviance: 166.8    AIC: 182.8


We can see that for OpenWithSmartphoneind their is NA. and this is because their are no Opening With Smartphone at all In this user history.

My question is how it will impact on predict?
And doe's it make different if OpenWithSmartphoneind in the formula will be a factor type or not?

• For the users where OpenWithSmartphoneind is NA throughout, is this because the value of that variable is unknown for those users, or because it always takes a "no" value? If the latter, maybe it's better to transform the NAs to 0s before modeling. If the former, though, this shouldn't affect predict(), because --- thanks to the drop=TRUE default in dlply() --- the models for the relevant users won't be looking for a variable with nothing but missing values. – ulfelder Aug 4 '15 at 13:11
• @ulfelder Because it always takes a "no" value. – user137628 Aug 4 '15 at 13:35
• Okay, and please ignore my previous suggestion for handling that. If you change those NAs to 0s, your models for the individuals with all 0s will have an absurd parameter estimate for that variable. So better to do what you already did, and predict() should work fine. Did you try applying it and have some kind of problem? – ulfelder Aug 4 '15 at 13:40
• Another option would be to use a hierarchical (or multilevel) model with random intercepts for users. See here for some discussion of that. – ulfelder Aug 4 '15 at 13:42
• @ulfelder I don't have problems with predict, thats why i turning to stack. I thought, Maybe i don't have errors but still i get wrong. Thanks for the link, i need it to another model. – user137628 Aug 4 '15 at 14:44