1
$\begingroup$

I have a dataset of individuals that participated in several races, but not all individuals did every race. Of every individual I have their average speed. My goal is to have a measure of how difficult the race was (under the assumption that the average speed of all individuals is lower for more difficult races).

My intuition was to build a mixed model where I specify a random intercept for every individual. Then I also added a fixed effect for ‘race’. I hoped that coefficients of the factor ‘race’ would be additive on the random intercept, where negative values would mean on average a more difficult race (slower speed) and positive values an easier race (higher speed).

My current model looks like this (I use the R package lme4):

fit = lmer(Av_speed ~ (1|individual) + race, data = df)

But then I still have a fixed effect when I look at the summary. I also tried to suppress the fixed intercept:

fit = lmer(Av_speed ~ (1|individual) + 0 + race, data = df)

But then I have fixed effects for every race. (The value of the race coefficients looks like the mean speed for that race.)

What am I doing wrong? Is a mixed model the right solution for this problem? What do the random and fixed effects in my model mean?

$\endgroup$
4
$\begingroup$

I think your model is sound. The important question is how you should define how difficult a race is. If you’re happy with defining it as the difference between the average speed of the race and the average speed of an average race, it’s easy. Here’s an R example:

Let’s generate 15 individuals, each with a relative (on an additive scale) speed advantage:

id = 1:15
indspeed = (id-mean(id))/4

This means that, e.g., the fastest individual has an average speed of 1.75 (km/h or whatever) higher than the mean speed for a given race. Similarly, let’s define the mean speeds for five races as 60, 65, 70, 75 and 80:

race = seq(60,80,5)

We can now generate the results for the various races. For each race, we select 7 individuals at random, and simulate their speed, based on the race difficulty (average race speed), individual speed advantage/disadvantage and some randomness.

gen_data = function(raceid) {
  raceind = sample(id, 7)
  speed = race[raceid] + indspeed[raceind] + rnorm(length(raceind), sd=5)
  race_df = data.frame(ind = raceind, race=raceid, speed=speed)
  race_df
}
set.seed(1) # Reproducible random data
dl = lapply(seq_along(race), gen_data)
d = do.call(rbind, dl)
d = transform(d, race = factor(race), ind=factor(ind))

We can now fit a mixed-effects model with race as fixed effects and individuals as random effects:

library(lme4)
fit = lmer(speed ~ race + 0 + (1|ind), data = d)

The fixed effects coefficient estimates are estimates of the mean speed of each race:

> fixef(fit)
race1 race2 race3 race4 race5
 60.4  67.9  69.2  74.9  82.2

To get a measure of their relative difficulties, you can subtract the average speed:

> fixef(fit) - mean(fixef(fit))
 race1  race2  race3  race4  race5
-10.52  -3.07  -1.72   4.03  11.28

You can of course calculate other measures of difficulty, e.g., percentage of the average speed (if that makes sense), or perhaps the square root of the absolute differences.

Note that each time you add a new race, the relative difficulties of the old races will change. The changes may be large if the new race is much more difficult (or easy) than all the previous races.

If you have many races, you might consider fitting race as a random effect too. Then the conditional means of these random effects are estimates of the relative difficulty. This has the advantage of shrinking the estimates towards the global mean, generally giving better estimates. Here’s the R syntax:

fit = lmer(speed ~ (1|race) + (1|ind), data = d)
ranef(fit)$race

Note that you need to include the overall intercept here (implicit in the formula). Also note that you don’t need to subtract the mean from ranef(fit)$race, as random effects are already assumed to have a mean of zero.

$\endgroup$
  • $\begingroup$ Hi, thanks for the answer! I'm still a bit puzzeled about the meaning of a random intercept in this case. Now it seems (your first model) that each race has it's own fixed intercept and that there is an additive effect for each individdual. I would like to go to a situation where I have an intercept for each individual and then an additive effect for each race. This also means if I would have in my dataset only individuals that did only one of the races, my race effect would be 0 since all information is allready in the individual intercept. How do this relate to you model? $\endgroup$ – statastic Apr 20 '15 at 19:29
  • $\begingroup$ @statastic In the first model, there is a random effect (intercept) for each individual, just like you require. I’m not sure I understand what you mean by having ‘only individuals that did only one of the races’ and why this should imply that the race effect is 0. If you have few observations for an individual, that individual’s predicted intercept (i.e., conditional mean) will be heavily shrunken towards the global mean of the individuals. $\endgroup$ – Karl Ove Hufthammer Apr 20 '15 at 19:40
  • $\begingroup$ Well, you have fast individuals and slow individuals. In difficult races all individuals will be slower relative to their own mean. But some races will attract more fast racers (eg championships) in the average speed in the race will be faster because of the faster individuals and not because it's a harder racer. I want to use the fact I have racers that did mulptiple races to compare races. So you have first a racers effect and then I would like to explain the variation in the residuals by race effect. $\endgroup$ – statastic Apr 21 '15 at 2:30
  • $\begingroup$ Maybe a better approuch would be to firstcenter every racers speed according to their own average speed across all the races they did? $\endgroup$ – statastic Apr 21 '15 at 2:32
  • $\begingroup$ @statastic If I have understood you correctly, that’s exactly what the model does. For example, if you add two observations for a new race (race = 6), and set the observed speeds to, e.g., 100, the estimated mean speed of the race will depend on which two individuals participated in the race. If it is the two theoretically worst individuals (individual 1 and 2), the estimated race speed (based on the data set from the simulation) will be 105.3. If it is the two theoretically best individuals (individual 14 and 15), it will be 97.4. For the average individuals (7 and 8), it will be 100.6. $\endgroup$ – Karl Ove Hufthammer Apr 21 '15 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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