# How to find groupings (trajectories) among longitudinal data?

### Context

I want to set the scene before somewhat expanding on the question.

I have longitudinal data, measurements taken on subjects approximately every 3 months, primary outcome is numeric (as in continuous to 1dp) in the range 5 to 14 with the bulk (of all data points) being between 7 and 10. If I do a spaghetti plot (with age on the x axis and a line for each person) it's a mess obviously as I have >1500 subjects, but there is a clear tread towards higher values with increased age (and this is known).

The broader question: What we would like to do is to firstly be able to identify trending groups (those that start high and stay high, those that start low and stay low, those that start low and increase to high etc) and then we can look at individual factors that are associated with 'trend group' membership.

My question here is specifically pertaining to the first portion, the grouping by trend.

### Question

• How can we group individual longitudinal trajectories?
• What software would be suitable for implementing this?

I have looked at Proc Traj in SAS and M-Plus suggested by a colleague, which I'm looking into, but would like to know what others thoughts are on this.

• It's just a starting point, but perhaps check out some of the answers to this question: stats.stackexchange.com/questions/2777/… Jul 25 '11 at 2:28
• Thanks Jeromy, the kml option is interesting, I like the idea given it's in R, but am not sure I can use their framework with my data, given the subjects come in a different ages for their visits as opposed to 'visit 1' 'visit 2' etc and some have 10 visits while others have 50+... Jul 25 '11 at 5:54
• Check kml package - that seems to provide functionality you need. Paper in JoSS describes it in detail. Also kml3d & kmlShape might be of interest. Jan 24 '19 at 2:00

I've used the Mfuzz in R for clustering time-course microarray data sets. Mfuzz uses "soft-clustering". Basically, individuals can appear in more than one group.

As @Andy points out in the comment, the original paper uses CTN data. However, I suspect that it should work OK for your discrete data. Especially since you are just exploring the data set. Here's a quick example in R:

##It's a bioconductor package
library(Mfuzz)
library(Biobase)

## Simulate some data
## 6 time points and 90 individuals
tps = 6;cases = 90
d = rpois(tps*cases, 1)  ##Poisson distribution with mean 1
m = matrix(d, ncol=tps, nrow=cases)

##First 30 individuals have increasing trends
m[1:30,] = t(apply(m[1:30,], 1, cumsum))

##Next 30 have decreasing trends
##A bit hacky, sorry
m[31:60,] = t(apply(t(apply(m[31:60,], 1, cumsum)), 1, rev))

##Last 30 individuals have random numbers from a Po(1)

##Create an expressionSet object
tmp_expr = new('ExpressionSet', exprs=m)

##Specify c=3 clusters
cl = mfuzz(tmp_expr, c=3, m=1.25)
mfuzz.plot(tmp_expr,cl=cl, mfrow=c(2, 2))


Gives the following plot:

• Thanks for the reference, I had not come across this before. Would this clustering algorithm be appropriate with low count distributed data as the OP had mentioned (or dichotomous data)? The reference paper (Futschik & Carlisle 2005) used data the was transformed to be continuous. Jul 25 '11 at 12:22
• @Andy: Good point. I've included a quick simulation. Everything seems OK, but there might be a more optimal solution. Jul 25 '11 at 13:05
• Thanks @csgillespie, will look to give this a try. By the way, my data is continuous not discrete, not sure if the question wasn't clear enough or if that was a typo in your answer? Have to rollback my R to install Mfuzz, let the fun begin. Jul 26 '11 at 2:48
• @csgillespie - this is very cool. I'm playing around with it right now on some real data. Do you happen to know whether there is a way to have it estimate the number of groups? May 11 '12 at 19:27

I'd expect there is an MPLUS package to do what you need. There is a paper in Psychometrika about almost exactly this subject