Understanding the mixed_model () function in R Even though I already have some experience working with R I would still consider myself a beginner. For my current research project, I need to run a zero-inflated negative binomial regression with fixed effects. The mixed_model() function seems to be the only way to do this in R. However, I find the manual to the function very challenging and thus I am looking for some help and explanations here in the community.
I want to run a regression with violent_events as the dependent and project_sum as the dependent variable. Additionally, I want to control for gdp, population_size and education. My units of analysis are different districts, which can be identified via the district_id variable. For each district, I have data for the years 2004 to 2010.
My initial attempt looked like this:
gm1 <- mixed_model(violent_events ~ sproject_sum + gdp + population_size + education, 
                   random = year | district_id, data = DF,
                   family = zi.negative.binomial(), zi_fixed = ~ district_id) 

Of course, the code is not working. I would be grateful for suggestions and particularly explanations that let me understand the *mixed_model()+ function better.

The zero-inflated negative binomial model accounts for "extra" zeros in over-dispersed count outcomes. In particular, it has two components, a negative binomial model and a logistic regression for the extra zeros. The syntax you used above translates to the following specific model,
$$\left \{
\begin{array}{rcl}
\log \{E(\texttt{violent_events}_{ij}) \} & = & \beta_0 + \beta_1 \texttt{sproject_sum}_{ij} + \beta_2 \texttt{gdp}_{ij} + \beta_3 \texttt{population_size}_{ij}\\&& + \beta_4 \texttt{education}_{ij} + b_{i0} + b_{i1} \texttt{time}_{ij}\\&&\\
\Pr\{\mbox{extra } \texttt{violent_events}_{ij} = 0\} & = & \gamma_0 + \gamma_1 \texttt{district_id}_{ij}
\end{array} 
\right.$$
Some notes:

*

*The term $E(\texttt{violent_events}_{ij})$ denotes the average of the violent_events variable. When violent_events is zero, then this may be a zero from the negative binomial model or an extra zero with a probability specified by the logistic regression model.

*In the above specification, I do not know if some of the covariates you have are factors with multiple levels (e.g., district_id). In this case, their specification expands to multiple coefficients using treatment contrasts.

*In the output, you get the estimated fixed-effects coefficients $\beta_0, \ldots, \beta_4$, and $\gamma_0, \gamma_1$ reported separately.

*In the syntax, you need to include a ~ before the time variable in the specification of the random argument, i.e., random = ~ time | district_id

*Given that district_id is a grouping variable, you would need to put a random effect for it in the logistic regression part, i.e., zi_random = ~ 1 | district_id, and most probably you do not want to include it as a fixed effect, i.e., zi_fixed = ~ 1. If you do that, then in the equation above, you will have an extra random effect $u_i$ in the logistic regression part, and the random effects $b_{0i}$, $b_{1i}$, and $u_{i}$ will be assumed to be correlated.

