id | diary | large_ensemble | orchestra | na |
---|---|---|---|---|
1 | 1 | 0 | 0 | 11 |
1 | 2 | 1 | 0 | 19 |
1 | 3 | 1 | 0 | 14 |
43 | 1 | 0 | 0 | 19 |
43 | 2 | 0 | 0 | 13 |
43 | 3 | 0 | 0 | 19 |
Prof. Maria Tackett
Nov 30, 2022
Due dates
Exam 02: Mon, Dec 05 (evening) - Thu, Dec 08, 12pm (noon)
Exam 02 review on Mon Dec 05
Click here for lecture recordings - available until Dec 05, 11:59pm
See Week 14 activities
The data musicdata.csv
come from the Sadler and Miller (2010) study of the emotional state of musicians before performances. The dataset contains information collected from 37 undergraduate music majors who completed the Positive Affect Negative Affect Schedule (PANAS), an instrument produces a measure of anxiety (negative affect) and a measure of happiness (positive affect). This analysis will focus on negative affect as a measure of performance anxiety.
The primary variables we’ll use are
na
: negative affect score on PANAS (the response variable)perform_type
: type of performance (Solo, Large Ensemble, Small Ensemble)
large_ensemble
: 1 if large ensemble performance, 0 otherwiseinstrument
: type of instrument (Voice, Orchestral, Piano)
orchestra
: 1 if orchestral instrument, 0 otherwiseid | diary | large_ensemble | orchestra | na |
---|---|---|---|---|
1 | 1 | 0 | 0 | 11 |
1 | 2 | 1 | 0 | 19 |
1 | 3 | 1 | 0 | 14 |
43 | 1 | 0 | 0 | 19 |
43 | 2 | 0 | 0 | 13 |
43 | 3 | 0 | 0 | 19 |
Draw the data structure, and add the Level One and Level Two observational units and variables.
The goal is to understand variability in performance anxiety (na
) based on performance-level and musician-level characteristics. Specifically:
What is the association between performance type (large ensemble or not) and performance anxiety? Does the association differ based on instrument type (orchestral or not)?
We will fit the model in two parts:
1️⃣ Fit a separate model for each musician understand the association between performance type and anxiety (Level One models).
2️⃣ Then fit a system of models to predict the fitted coefficients in the Level One models based on instrument type (Level Two models).
We’ll start with the Level One model to understand the association between performance type and performance anxiety for the ith musician.
naij=ai+bi LargeEnsembleij+ϵi,ϵij∼N(0,σ2)
Why is it more meaningful to use performance type for the Level One model than instrument?
For now, estimate ai and bi using least-squares regression.
Below is partial data for observation #22
id | diary | large_ensemble | orchestra | na |
---|---|---|---|---|
22 | 1 | 0 | 1 | 24 |
22 | 2 | 1 | 1 | 21 |
22 | 3 | 1 | 1 | 14 |
22 | 13 | 1 | 1 | 12 |
22 | 14 | 1 | 1 | 19 |
22 | 15 | 0 | 1 | 25 |
See Part 3: Level One Models to fit the Level One model for all 37 musicians.
Recreated from BMLR Figure 8.9
Now let’s consider if there is an association between the estimated slopes, estimated intercepts, and the type of instrument.
The slope and intercept for the ith musician can be modeled as
ai=α0+α1 Orchestrai+uibi=β0+β1 Orchestrai+vi
Note
The response variable in the Level Two models are not observed outcomes but the (fitted) slope and intercept from each musician
See Part 4: Level Two Models.
Model for intercepts
term | estimate | std.error | statistic | p.value |
---|---|---|---|---|
(Intercept) | 16.283 | 0.671 | 24.249 | 0.000 |
orchestra | 1.411 | 0.991 | 1.424 | 0.163 |
Model for slopes
term | estimate | std.error | statistic | p.value |
---|---|---|---|---|
(Intercept) | -0.771 | 0.851 | -0.906 | 0.373 |
orchestra | -1.406 | 1.203 | -1.168 | 0.253 |
Level One
^naij=ˆai+ˆbi LargeEnsembleij
for each musician.
Level Two
ˆai=16.283+1.411 Orchestraiˆbi=−0.771−1.406 OrchestraiWhat is the predicted average performance anxiety before solos and small ensemble performances for vocalists and keyboardists? For those who play orchestral instruments?
What is the predicted average performance anxiety before large ensemble performances for those who play orchestral instruments?
⚠️ Weighs each musician the same regardless of number of diary entries
⚠️ Drops subjects who have missing values for slope (7 individuals who didn’t play a large ensemble performance)
⚠️ Does not share strength effectively across individuals.
See Part 5: Distribution of R2 values.
Let Yij be the performance anxiety for the ith musician before performance j.
Level One
Yij=ai+bi LargeEnsembleij+ϵij
Level Two
ai=α0+α1 Orchestrai+uibi=β0+β1 Orchestrai+viCoefficients are estimated using likelihood-based methods (instead of least squares) to address the previously mentioned disadvantages
Plug in the equations for ai and bi to get the composite model Yij=(α0+α1 Orchestrai+β0 LargeEnsembleij+β1 Orchestrai:LargeEnsembleij)+(ui+vi LargeEnsembleij+ϵij)
Note
We no longer need to estimate ai and bi directly as we did earlier. They conceptually connect the Level One and Level Two models.
We generally assume that the error terms are normally distributed, e.g. error associated with each performance of a given musician is ϵij∼N(0,σ2)
For the Level Two models, the errors are
We will also estimate ρuv to account for fact that ui (the intercepts) and vi (the slopes) are correlated for the ith musician
Recreated from Figure 8.11
Describe what we learn about the association between the slopes and intercepts based on this plot.
Use a multivariate normal distribution for the Level Two error terms [uivi]∼N([00],[σ2uρuvσuσvρuvσuσvσ2v])
where σ2u and σ2v are the variance of ui’s and vi’s respectively, and σuv=ρuvσuσv is covariance between ui and vi
Recreated from Figure 8.12
Fit multilevel model using tidymodels and the multilevelmod R packages. Display results using the tidy()
function from the broom.mixed package.
library(tidymodels) library(multilevelmod) library(broom.mixed) music_fit <- linear_reg() |> set_engine("lmer") |> fit(na ~ orchestra + large_ensemble + orchestra:large_ensemble + (large_ensemble|id), data = music) tidy(music_fit) |> kable(digits = 3)
library(tidymodels) library(multilevelmod) library(broom.mixed) music_fit <- linear_reg() |> set_engine("lmer") |> fit(na ~ orchestra + large_ensemble + orchestra:large_ensemble + (large_ensemble|id), data = music) tidy(music_fit) |> kable(digits = 3)
library(tidymodels) library(multilevelmod) library(broom.mixed) music_fit <- linear_reg() |> set_engine("lmer") |> fit(na ~ orchestra + large_ensemble + orchestra:large_ensemble + (large_ensemble|id), data = music) tidy(music_fit) |> kable(digits = 3)
library(tidymodels) library(multilevelmod) library(broom.mixed) music_fit <- linear_reg() |> set_engine("lmer") |> fit(na ~ orchestra + large_ensemble + orchestra:large_ensemble + (large_ensemble|id), data = music) tidy(music_fit) |> kable(digits = 3)
library(tidymodels) library(multilevelmod) library(broom.mixed) music_fit <- linear_reg() |> set_engine("lmer") |> fit(na ~ orchestra + large_ensemble + orchestra:large_ensemble + (large_ensemble|id), data = music) tidy(music_fit) |> kable(digits = 3)
library(tidymodels) library(multilevelmod) library(broom.mixed) music_fit <- linear_reg() |> set_engine("lmer") |> fit(na ~ orchestra + large_ensemble + orchestra:large_ensemble + (large_ensemble|id), data = music) tidy(music_fit) |> kable(digits = 3)
library(tidymodels) library(multilevelmod) library(broom.mixed) music_fit <- linear_reg() |> set_engine("lmer") |> fit(na ~ orchestra + large_ensemble + orchestra:large_ensemble + (large_ensemble|id), data = music) tidy(music_fit) |> kable(digits = 3)
effect | group | term | estimate | std.error | statistic |
---|---|---|---|---|---|
fixed | NA | (Intercept) | 15.930 | 0.641 | 24.833 |
fixed | NA | orchestra1 | 1.693 | 0.945 | 1.791 |
fixed | NA | large_ensemble1 | -0.911 | 0.845 | -1.077 |
fixed | NA | orchestra1:large_ensemble1 | -1.424 | 1.099 | -1.295 |
ran_pars | id | sd__(Intercept) | 2.378 | NA | NA |
ran_pars | id | cor__(Intercept).large_ensemble1 | -0.635 | NA | NA |
ran_pars | id | sd__large_ensemble1 | 0.672 | NA | NA |
ran_pars | Residual | sd__Observation | 4.670 | NA | NA |
The content in the slides is from - BMLR: Chapter 7 - Correlated data - BMLR: Chapter 8 - Introduction to Multilevel Models