# Advice on mixed effect model formula for R's lme4

I'm new to mixed effects modeling and definitely lme4 and would greatly appreciate some advice.

My research question: what factors determine a business' number of online reviews per day?

The data is cross-sectional and the observations are businesses.

Dependent variable : number of online reviews (interested in its ratio = number of reviews per day)

Independent variables are either business-related or location-related as shown in the table below. Except concentration, location factors are not of interest to me and are included as controls.

Here's a sample of 4 rows of the data. There are a few more variables related to the businesses and locations which I’m leaving out for brevity:

Since one of my focal independent variables (concentration of competitors) is at zip code level and these businesses are nested in zip codes (and thus can share concentration values), I've decided to use mixed effect models with zip code as random effect. Also, since the dependent variable is count, I've decided to go with either Poisson or negative binomial regression with the span of online reviews in days as offset. I'm using lme4 in R and my questions mainly revolve around my formula below and if it is sound or not.

Formula: number of online reviews ~ price * concentration + number of services provided + offset(log of time span of online reviews) + (1|zipcode) + (1|price)

One of my main intended theoretical contributions is to highlight how the effects of different factors depend on locational-factors especially concentration. Does my formula (specifically 1|zipcode) accurately reflect that? I will note that the concentration variable has a very limited range (75% if data points are between 0 and 4) so I could not categorize it into numerous categories to use it as a random effect separate from zipcode).

Feel free to address any other concerns you see or even rewrite the formula to clear things up for me.

• Why are you including price as both a fixed and a random effect?
– EdM
Commented Jul 17 at 19:40
• Correct me if I'm wrong but my rationale is that price has a population-wide effect on the number of reviews, regardless of zip code. I've modeled that as a fixed effect. But I also believe that depending on what zip code a business is located in, the effect of price will vary, mostly due to different competitive pressures (operationalized as the "concentration" variable). Commented Jul 17 at 19:46
• Then you would need to invoke a random slope for price as part of the random effect for zipcode, which in your current model only provides a random intercept. See the lmer cheat sheet for different ways to do that, depending on your assumptions, with price as the fixed effect in those examples.
– EdM
Commented Jul 17 at 19:56
• @EdM thanks for sharing the useful link. It took me to some other useful sources, too. So, as I understand now, you were implying (1 + price|zipcode). I have another lingering question if you don't mind: the literature says that locational factors such as average home value or population density affects my dependent variable. Given I am using zipcode as random effect, would it be superfluous or even wrong to include those locational factors as fixed effects? Of course, I do want to have one locational factor of interest to me (concentration) as fixed effect if possible. Commented Jul 18 at 20:55
• The way I think about this is that random effects account for associations with outcome beyond those modeled with the fixed effects. So you should include fixed effects that you think might be associated with outcome (like average price and population density); then the random effects handle unobserved variables associated with zipcode and within-zipcode correlations. Note that (1+price|zipcode) imposes a correlation between the random intercepts and slopes; see this answer for how to remove that restriction if appropriate.
– EdM
Commented Jul 19 at 14:26

The approach to using mixed effects modeling with zipcode as a grouping variable for random intercepts to account for the nested structure of the data is appropriate. However, there are a few important considerations and improvements to your model formulation.

### Points to Consider:

Random Effects:

Using (1|zipcode) is correct as it accounts for the variability in the number of online reviews across different zip codes. Including price as a grouping variable for random intercepts does not seem appropriate since it is also included as a fixed effect and is not a grouping variable in the traditional sense. Instead, you can consider using random slopes for price if you hypothesize that the effect of price on the number of reviews varies across zip codes.

Offset and Dependent Variable:

Using the log of the time span of online reviews as an offset is correct since it adjusts for the differing time spans across businesses, allowing you to model the rate of reviews per day. Interaction Effects:

If you are particularly interested in how the effect of price interacts with concentration, including the interaction term price * concentration is appropriate. This allows you to examine how the effect of price on the number of reviews changes at different levels of concentration.

Count Data:

Since your dependent variable is count data, using Poisson or negative binomial regression is appropriate. Negative binomial regression is preferred if there is overdispersion in the data (ie, the variance is greater than the mean).

Revised Formula:

Based on these points, here is a revised version of your formula:


# Poisson model (or you could use glmer.nb for a negative binomial model if overdispersion is present)
model <- glmer(
number_of_online_reviews ~ price * concentration + number_of_services_provided +
offset(log(time_span_of_online_reviews)) + (1 + price|zipcode),
family = poisson(link = "log"), data = your_data_frame
)


Explanation:

Fixed Effects:

• price * concentration: This includes both main effects and the interaction effect.
• number_of_services_provided: As a control variable.
• offset(log(time_span_of_online_reviews)): Adjusts for differing time spans of review collection.

Random Effects:

• (1 + price|zipcode): Random slopes for price within zip codes to allow the effect of price to vary across zip codes.

This model will help you understand the main effects of your variables of interest, the interaction between price and concentration, and how these effects may vary by location.

If you encounter convergence issues or other model fitting problems, you may need to adjust your model specifications (eg., by removing the random slopes for price) or consider alternative modeling approaches.