Short answer & R Formula
I believe the R code you're looking for is something along the lines of the following, from the lme4
package.
myModel <- lmer(y ~ incentive + (1 | treatGroup/player), data = df)
Basically you're saying that there's a random effect for each player, who is nested inside of a treatment group with a random effect. In addition, there is a fixed effect for incentive
.
Longer answer / explanation
First of all, I personally find the terms "fixed effect" and "random effect" to be confusing and used somewhat inconsistently. Andrew Gelman (Prof. at Columbia) has a great blog post on the topic.
Model formulation
So in lieu of using those terms, I'll try to write out the (basic) formulation based on what I understand from your question. In particular, it sounds like we have:
- 16 players (indexed by $i$)
- 30 observations per player (indexed by $j$)
- 4 possible groups (indexed by $k$)
- A binary "incentive" treatment $M$, where $m_{i(k)} = 1$ if the $i$-th player receives the incentive
Let $Y_{ij(k)}$ be the $j$-th observation for the $i$-th player, who is placed into the $k$-th group.
With these in mind, our regression model is as follows:
$$Y_{ij(k)} \sim N(\mu_{i(k)}, \sigma^2)$$
$$\mu_{i(k)} = \alpha_i + \alpha_k + \beta \cdot m_{i(k)}$$
Explanation of terms / quick notes
We have a few relevant terms:
- $\alpha_i$: The 'baseline' for this player
- $\alpha_k$: the effect of being in the $k$-th group
- $\beta$: The impact of the
incentive
treatement
Some quick notes:
Using (1 | treatGroup / player)
describes a nesting between levels (e.g., each player is in only one treatment group).
To your point in the comments, 30 observations for each player are assumed to be drawn from a common distribution - Our goal is to estimate the impact of (a) incentives and (b) treatment group on the mean of that distribution.
This answer assumes no interaction between the incentive and the treatment group.
Additional reading
I used this to refresh my memory on lmer
syntax since I'm more accustomed to using rstan
(link).
Skimming this tutorial (I haven't read the whole thing), it looks like a good resource, with an intuitive overview for the beginner!
Also see this CV post on lmer
formula syntax
If you really want to get into this stuff, then Gelman & Hill (2006) is an excellent book.