I am new to data analysis and now working on a Mixed Effects Logistic Regression Model. Currently, I have the following data frame (model_data):

Road Id Vehicle_id  entry_time           exit_time      
   1        1        2017-01-31 00:00:00  2017-01-31 00:00:00
last_veh_time  vehicle_type     status
300            4 wheel          0 

Likewise, I have the information (nearly a million rows) of all the vehicles entering a place and exiting the same place. Status can be either $1$ or $0$ for all of these. last_veh_time is the last vehicle passed the same place before how much time.

I want to know the probability of a getting status $0$ for a vehicle based on the entry_time and last_veh_time. To do this, I created the model:

model = glmer(status ~last_veh_time + (1 |link ), 
             data=model_data, REML=FALSE)

Is this the right approach? Any help is appreciated.

  • 4
    $\begingroup$ No, it's not. You didn't specify a dependent variable and lmer does not do logistic regression.You need glmer and specify the correct family. $\endgroup$
    – Roland
    Jan 31, 2017 at 9:41

1 Answer 1


There is too little information on your research question and data-structure to really allow good advice, but I'll try.

In this scenario "status" is you "dependent variable", since you suspect that it depends on "entry_time" and "last_veh_time" (your "independent" variables). There is an excellent explanation on terminology here.

Given the minimal information above, I cannot see why you would want to perform a mixed model analysis rather than a standard logistic regression. You only need a mixed effects model when there are repeated measures on a single experimental unit (e.g. if the same vehicleIDs is showing up in several rows) or if there is some other grouping/clustering factor of no interest that makes some vehicles more similar to each other (i.e. cluster together). If this is not the case and you have only one vehicle per line, I think no mixed model is needed.

If you vehicleIDs are showing up repeatedly, your mixed logistic regression might look something like this:

glmer(status ~ entry_time + last_veh_time + vehicle_type + (1 | vehicle_id),
    data = model_data,
    family = binomial)     #The link-function describing the relationship between your  linear model and the binomial distribution of your outcome

PS: Currently "entry_time" is continuous. Depending on your research question you might want to consider whether it makes sense to convert "time" into sub-variables calendar date & daytime or even year & month & day & daytime.

  • $\begingroup$ The reason why I want to perform a mixed model analysis because same vehicleIDs is showing up in several rows,with different entry time and last veh_time.And yeah I have to make my entry time into discrete . Is my approach correct? $\endgroup$
    – Josh
    Feb 2, 2017 at 6:33
  • $\begingroup$ Yes, then a generalized mixed model makes sense. See code example added to the answer above. $\endgroup$
    – mzunhammer
    Feb 2, 2017 at 9:36
  • $\begingroup$ I updated the table because I missed the road_id column.So now the road_id is a independent variable which will be added with the entry_time and other depended variable.Am I correct? $\endgroup$
    – Josh
    Feb 2, 2017 at 11:35
  • $\begingroup$ That depends on what "road_id" stands for and on your aims. Again, your question is not specific enough and there is not enough information to help. Warning: Generalized linear models are quite complicated and hard to employ, even for experienced statisticians. It is unlikely that you will get to a suitable solution to your problem on CrossValidated. You should seek statistical advice from an expert irl and dedicate time on reading a GLM textbook. $\endgroup$
    – mzunhammer
    Feb 2, 2017 at 11:53
  • $\begingroup$ Yes you are right.I am reading about more GLM but as I said I wanted to see how the status behaves according to the change in entry time and road id and last_veh_time for each vehicle id. $\endgroup$
    – Josh
    Feb 2, 2017 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.