**Learning Objectives**

- Identify and define hierarchical and longitudinal data
- Analyze correlated data using Analysis of Variance
- Define and calculate Intraclass Correlation
- Identify and define random and fixed effects

Textbook sections:

- Vittinghoff sections 7.1 (7.2-7.3 next class)

**Outline**

- Introduction to hierarchical and longitudinal data
- Fecal Fat example
- Correlations within subjects (ICC)
- Random and fixed effects

**Learning Objectives**

- Create and interpret a notched barplot
- Create spaghetti / line plots for grouped data
- Use
`pivot_wider`

to create a wide-format dataframe - Do a manual ICC calculation
- Write a function
- Perform a permutation simulation

**Exercises**

- Read the fecal fat dataset and convert pilltype and subject to factors
- Create a notched boxplot of the data.
- Interpret the notches. What is wrong with the usual interpretation in this example?
- Subtract subject means from the fecal fat data, manually and using residuals of a one-way AOV
- Make line plots for each subject, with and without subject mean centering
- Convert to a wide-format dataset and remove the subject column
- Write a function to calculate subject and residual variance and ICC of this dataset as a vector
- Create a simulated dataset where subjects are randomized for each treatment
- compare ICC for your original and simulated dataset
- Repeat the simulation 999 times, and compare to your original dataset