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.


  • 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.

  • 1
    $\begingroup$ It's just a starting point, but perhaps check out some of the answers to this question: stats.stackexchange.com/questions/2777/… $\endgroup$ Commented Jul 25, 2011 at 2:28
  • $\begingroup$ 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+... $\endgroup$
    – nzcoops
    Commented Jul 25, 2011 at 5:54
  • $\begingroup$ Check kml package - that seems to provide functionality you need. Paper in JoSS describes it in detail. Also kml3d & kmlShape might be of interest. $\endgroup$
    – user22
    Commented Jan 24, 2019 at 2:00

2 Answers 2


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

## 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:

Mfuzz clustering

  • $\begingroup$ 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. $\endgroup$
    – Andy W
    Commented Jul 25, 2011 at 12:22
  • $\begingroup$ @Andy: Good point. I've included a quick simulation. Everything seems OK, but there might be a more optimal solution. $\endgroup$ Commented Jul 25, 2011 at 13:05
  • $\begingroup$ 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. $\endgroup$
    – nzcoops
    Commented Jul 26, 2011 at 2:48
  • $\begingroup$ @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? $\endgroup$
    – Macro
    Commented May 11, 2012 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


except the data is binary and the trajectories are probability trajectories. The authors use latent class analysis (implemented by using a penalized finite mixture model) to group trajectories. I also know the first author wrote some other papers around 10 years ago with Bengt Muthen (creator of MPLUS) about latent class analysis in similar settings (with trajectories). For example,


sounds very similar to what you're talking about, except the outcome is binary. The continuous case is much simpler, so I'd do a backwards literature search (i.e. look at the papers these papers reference) to find something that matches what you've described more precisely.

To find out more, you can ask the proprietors of MPLUS directly what package you need to use to do what you need. They are generally pretty quick to respond and are very helpful:



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.