|

Visualizing Longitudinal Data

Longitudinal data is data collected repeatedly from the same subjects or objects over a period of time. The data collection times may or may not be fixed. For example, if you collect the fasting blood glucose from two groups of 25 diabetic patients (50 patients in total) every morning for 10 days, you will get a longitudinal dataset with 500 data points. That is 10 data points at fixed time points from each of the 50 patients, assuming there were no missing data.

Let’s assume that the patients in Group 1 are on some kind of intervention to lower their blood glucose and Group 2 are control patients who carried on with their usual lifestyle.

Generating Dummy Longitudinal Data in R

The following R codes will generate the blood glucose dummy data that we just discussed above.

#set seed
set.seed(9876)

#generate dummy data mean=160 sd=5 mg/dl
#50 patients (25 per group) and 10 time points = 500 data points
patientn <- rep(1:50, each = 10)
groupid  <- rep(c("Group 1","Group 2"), each=250)
timedays <- rep(1:10, times = 50)
bloodglc <- rnorm(500,160,5) #mg/dl
tfactor  <- rep(rev(seq(0.91,1,0.01)), times = 50)
cfactor  <- rep(1, times = 500)
longitudinal data
The data looks like this.

Exploring Longitudinal Data

We can use a spaghetti plot to visualize the blood glucose data of all the patients to visually check if there is any difference between the two groups.

Spaghetti plot

Follow this link to see how to create a spaghetti plot in R.

A mean plot can be used to plot the mean profile of the two groups over time:

Follow this link to see how to create a mean profile plot in R

Similar Posts

Leave a comment

2 Comments