The release of megenreg

Extended multivariate generalised linear and non-linear mixed effects models

I’ve just released the first development version of megenreg, a program I’ve been working on in some way or another for almost a year. This program is awesome. I can say that because this is my blog, but I actually do think it’s pretty awesome. Why? Because it can do things that I haven’t even realised yet. Let me tell you about it.

I’ve developed various programs, such as stjm for joint modelling longitudinal and survival data, stmixed for analysing clustered survival data with two levels, and stgenreg for analysis of survival data. Each time I decide to work on an extension, it involves re-learning an old program, and extending it in some way, or starting a whole new one. So I thought, why not develop a program than encompasses everything. Why not develop a program that can handle an arbitrary number of outcomes of any type, any number of levels, any number of random effects at each level, flexible ways to link and share parameters between outcome models, and most importantly, an easy way to extend it by allowing the syncing of user-written functions with the main engine of the program. Why not make my life easier…

megenreg can do all of the above, and more. The functionality of megenreg that I’m most pleased about is the ability to define a user-written function of the log-likelihood for an outcome model, which through the use of simple utility functions, can still utilise the standard complex linear predictor of an megenreg model, and link and share parameters between other outcomes. This functionality means it is extremely simple to develop a new model, and I mean extremely easy. The user-written function is written in Mata, Stata’s matrix programming language, which gives you complete freedom to write as simple or complex a function as you like, as long as you return the observation level log-likelihood contribution for your outcome model. What this also means is that it is easy to implement other researcher’s recently published models (example here), which may or may not come with a usable implementation (see my thoughts on that in this blog post).

Think of it like BUGS, but in a likelihood framework. Let’s say you wrote a likelihood function for a bespoke non-linear model. Well, you can immediately use it on its own with the complex linear predictor, with just fixed effects, then you can have any number of levels and random effects, then you can have time-dependent effects, then you can turn it into a joint model with any of the inbuilt distributions, or another one you wrote yourself…there’s at least 6 papers you can write just on that list, with methodological extensions only taking the time it took to type the syntax…seconds!

I actually debated with myself about whether to even release megenreg as a stand alone, documented package. What I could’ve done was keep it to myself, written 40+ commands which call megenreg deep down in the source code, and subsequently written 40 odd methods papers over the rest of my career. Well, where’s the fun in that.

The methodological preprint describing the model framework can be downloaded here. Tutorials on some of the many uses of megenreg can be found on the software page, with more being added regularly. I’m also getting it ported into R (with a lot of help from some colleagues and my post-doc Emma Martin), something I have not done before with any of my other packages. I think it’s too awesome not to.

You can install it in Stata by typing:

net install megenreg, from(

with more details and examples here.

I hope you find it useful.


comments powered by Disqus