I'm working on a prediction model for a continuous variable (amount of medicine injected) .I use R for modeling.My project flow is to multiply the prediction of a glm (logistic regression) model that is used to predict 0/1 if a medicine was injected at all with an lm (linear regression) model that is used predict amount of medicine injected - this model works rather good In R .My problem is that when I move this model to MSSQL I get different values for the prediction (i.e. for a random row the value in the R is 400 and in SQL the value for the same row is 640.The model in SQL is made by attaching the models coefficiants from the glm model to produce the glm prediction values and then multiplying it with the lm model prediction values. I don't understand why there is a difference if I use the same coefficients?
Here is the code for the lm and glm models in r:
d7_lm<-lm(Ttl_Inject~UserSource+IsNewIndividual+IsCross,data=train)
d7_glm<-glm(Is_Injected~UserSource+IsNewIndividual+IsCross,data=train)
Here is a part of the r code for the prediction:
demo$d7_lm_pred<-predict(d7_lm,newdata=demo,type='response')
demo$d7_glm_pred_response<-ifelse(predict(d7_glm,newdata=demo,type='response')>0.5,1,0)
demo$glm01_lm_response<-demo$d7_lm_pred*demo$d7_glm_pred_response # this is used for a container of the prediction model's values.
Here is a part of the SQL code :
select TOP 1000*, InjectionAmount_pred= (-2.213e -1.180e+00*(case when User='IAF' then 1 else 0 end)-1.665e+00*(case when UserSource='Viral' then 1 else 0 end)
+IsNewIndividual * 1.167e+00+IsCross )
* IIF((1 / (1 + EXP(-(-1.346e-03+1.140e-02*(case when UserSource='IAF' then 1 else 0 end) -2.975e-03*(case when UserSource='Viral' then 1 else 0 end)
-IsNewIndividual * 1.503e-04 +IsCross ))))>0.5,1,0)
.Machine$double.eps
). See the following: stackoverflow.com/questions/2287616/controlling-digits-in-r $\endgroup$ – AdamO Jul 31 '14 at 15:58