Find the top rail-trails in each state using mixed effects models

Written by: Josh Rosenberg

Primary Source: Joshua M. Rosenberg, February 22, 2018

Outside of education, one of my interests is cycling, and one of my favorite ways to cycle is on rail-trails, pathways and greenways that are converted from former railroad tracks.

In a side-project (and because the data source can be used for teaching and learning about complex, nested data), I collected information from the TrailLink website. I’ve blogged about this data here and here to find out what the best rail-trails in Michigan are and to find out what the characteristics of the best rail-trails are, respectively.

Using this data, I created a simple Shiny web app (here) to find the top rail-trails (using the reviews from TrailLink) in each state. One neat thing about the app is that it uses predictions from a mixed effects (or multi-level) model.

Rail Trails table

The reason I chose to do this is that using the raw reviews to find the top rail-trails is not as helpful as I first thought, as trails with very few (but very high) reviews–such as one with two “5” (out of 5) reviews–may end up ranked as the top in the state. At the same time, a trail with many (primarily high) reviews–such as one with 30 reviews that average out to almost but not quite “5”–may be ranked lower.

In lme4, the model is a random intercept (for the trail and state) model and would look like this (all of the code is here):

m1 <- lmer(raw_reviews ~ 1 + (1|name) + (1|state), data = d)

The model, which accounts for the multiple (repeated) reviews for each trail and the nesting of trails in each state looks something like this:

\widehat { y } _{ trail,\quad state }\quad =\\ { \beta }_{ 0 }(overall\quad mean\quad review)\quad +\\ { \alpha }_{ 1 }{ (trail\quad effect) }_{ trail }\quad +\\ { \alpha }_{ 2 }{ (state\quad effect) }_{ state }\quad +\\ { \varepsilon }_{ trail,\quad state }

So, the mixed effects model helps to account for both the number and variability in the reviews, giving a bit more weight to trails with a whole lot of high reviews relative to trails with less reviews to go on to (hopefully) predict rankings. In any case, you can check out the app at

The following two tabs change content below.
Joshua M. Rosenberg is a Ph.D. student in the Educational Psychology and Educational Technology program at Michigan State University. In his research, Joshua focuses on how social and cultural factors affect teaching and learning with technologies, in order to better understand and design learning environments that support learning for all students. Joshua currently serves as the associate chair for the Technological Pedagogical Content Knowledge (TPACK) Special Interest Group in the Society for Information Technology and Teacher Education. Joshua was previously a high school science teacher, and holds degrees in education (M.A.) and biology (B.S.).