R Tutorial: Introduction to Longitudinal Data

Brandon LeBeau defines longitudinal data as at least three repeated measurements on multiple units, then walks through a real dataset of rat body weights with 11 time points across 64 days. He explains why standard methods like t-tests don't work for trajectories and shows how to explore the data structure before modeling.
Chapters
Welcome. I am Brandon LeBeau, an assistant professor at the University of Iowa. My research focuses on longitudinal data research, software engineering, and quantitative program evaluation. In this course, we will explore modern ways to model longitudinal data for both continuous and dichotomous outcome variables. Before getting into the modeling approaches, we will first learn what longitudinal data is, what it isn't, and how to explore the data descriptively. First, in this course, we will define longitudinal data as data with at least three measurements on a single unit with multiple units involved. Units are often individuals, but they can also be things like businesses or hospitals. A few examples of longitudinal data include measuring an individual's blood pressure every week for six weeks, math test scores of students in grades three through eight, or whether a student is enrolled in extracurricular activities measured every semester for grades 7 through 12. The repeated measurements could take many forms, including data that are continuous or dichotomous. Dichotomous data take on two values, whereas continuous data can take on a wide range of values. These will be explored in more detail later in the course. Before exploring data, let's discuss what longitudinal data is not. Situations with multiple measurements for a single unit require different methodology. Time series analysis is often used with this type of data, which is common in business settings. If there are only two measurements of the same individual, for example, a pre and post test trajectories over time can't be explored. Other methods can be used, including linear regression like analysis of covariance or ANCOVA or t tests, depending on the purpose. These methods will not be explored in this course. Let's explore the body weight data from the NLME package, which contains the weight of rats measured at different times. The rat variable identifies the individual and the diet variable reflects one of two diets the rats had in the experiment. Researchers were interested in determining any differences between based on the diet for a given rat. First, we should explore the data descriptively to understand the data structure. The count function from DPLYR tells us how many rats are included in the data. The arguments include the data frame followed by the variable you want to count. In this case the RATID variable. The output shows there are 16 rats each with 11 measurements. Second, we should understand when the measurements took place. The count function can achieve this with time as the variable of interest. The output shows that each rat was measured at the same time starting on day one with the last measurement on day 64. This is an example of balanced data where each rat was measured on the same day and each rat has a measurement for each time point. This is not required for longitudinal analysis, but can make the analysis easier. Let's explore the number of rats in each diet condition. The output may take a second to understand. The N column of the output suggests there are 88 rats in diet 1. The data we have been working with is in long format, meaning each rat is in the data multiple times. We need to divide These values by 11:1 for each measurement to get the number of rats in each diet condition. This means eight rats were in diet one and four rats were in diets two and three times.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







