Context: Hierarchical regression with some missing data.

Question: How do I use full information maximum likelihood (FIML) estimation to address missing data in R? Is there a package you would recommend, and what are typical steps? Online resources and examples would be very helpful too.

P.S.: I'm a social scientist who recently started using R. Multiple imputation is an option, but I really like how elegantly programs like Mplus handles missing data using FIML. Unfortunately Mplus doesn't seem to compare models in the context of hierarchical regression at the moment (please let me know if you know a way to do that!). I wondered whether there is anything similar in R? Many thanks!

  • 1
    $\begingroup$ Have you considered WinBugs? It handles missing data in a beautifully natural way. $\endgroup$ Feb 28, 2013 at 2:14
  • $\begingroup$ An alternative to WinBUGS is OpenBUGS or STAN. These should be more Mac friendly. $\endgroup$
    – Maxim.K
    Oct 24, 2014 at 9:49
  • $\begingroup$ With regards to your FIML question, I thought I'd share this wonderful SAS paper by Paul Allison statisticalhorizons.com/wp-content/uploads/MissingDataByML.pdf Given the comments made by Paul Allison, one can easily implement the same procedure in R using lme or nlmer. $\endgroup$
    – AsH
    Nov 3, 2014 at 17:18

2 Answers 2


Credit of this answer goes to @Joshua who gave an awesome answer when I posted this question to the R and Statistics community on Google+. I am simply pasting his answer below.

For running regression (without latent variable modeling), please read my notes typed after the quoted text.

Handling missing data with Maximum Likelihood on all available data (so-called FIML) is a very useful technique. However, there are a number of complications that make it challenging to implement in a general way. Consider a simple linear regression model, predicting some continuous outcome from say age, sex, and occupation type. In OLS, you do not worry about the distribution of age, sex, and occupation, only the outcome. Typically for categorical predictors, they are dummy coded (0/1). To use ML, distributional assumptions are required for all variables with missingness. By far the easiest approach is multivariate normal (MVN). This is what for example Mplus will do by default if you do not go out for your way to declare the type of variable (e.g., categorical). In the simple example I gave, you would probably want to assume, normal for age, Bernoulli for sex, and multinomal for job type. The latter is tricky because what you actually have are several binary variables, but you do not want to treat them as Bernoulli. This means you do not want to work with the dummy coded variables, you need to work with the actual categorical variable so the ML estimators can properly use a multinomial, but this in turn means that the dummy coding process needs to be built into the model, not the data. Again complicating life. Further, the joint distribution of continuous and categorical variables is nontrivial to compute (when I run into problems like this in Mplus, it pretty quickly starts to break down and struggle). Finally, you really ideally specify the missing data mechanism. In SEM style, FIML, all variables are essentially conditioned on all others, but this is not necessarily correct. For example, perhaps age is missing as a function not of gender and occupation type, but their interaction. The interaction may not be important for the focal outcome, but if it is important for missingness on age, then it must also be in the model, not necessarily the substantive model of interest but the missing data model.

lavaan will use ML for MVN, but presently I believe the categorical data options are limited (again coming from the SEM field, this is standard). Multiple imputation seems less elegant at first because it makes explicit many hidden assumptions behind FIML (like distributional assumptions for every variable and the predictive model assumed for missingness on every variable). However, it gives you a lot of control and explicitly thinking about the distribution of each variable, and the optimal missing data mechanism for each is valuable.

I am becoming more and more convinced that Bayesian models are the way to handle missing data. The reason is that they are very flexible at including distributions for each variable, allowing many different types of distributions, and can easily incorporate the variability introduced by missing data on predictors, into the overall model estimates (which is the trick with multiple imputation where you then have to somehow combine results). Of course, these methods are not the easiest and can take a lot of training and time to use.

So that doesn't really answer your question, but explains a bit of why completely general frameworks for dealing with missingness are tricky. In my semutils package for the covariance matrices, I use lavaan underneath to use ML. I do that because I assume for a variance covariance matrix that you are using continuous variables anyway so that I assume my users are already assuming MVN for their data.

This means that if all variables with missingness are continuous, lavaan, a structural equation modelling (SEM) package is a nice one to use for FIML in R.

Now going back to my initial question. My intention was to have a magic fix for missingness when running linear regression. All my variables with missing were nice and continuous. So I proceeded to run my analyses in two styles:

  • The usual way with multiple imputation
  • In SEM style with lavaan using FIML.

I was missing a lot of things by doing regression in SEM style. Both styles gave similar coefficients and R squares, but in SEM style I didn't get the significance testing of the regression (the typical F values with df), instead I got fit indices that were not helpful as I had used up all my degrees of freedom. Also when one model had a larger R2 than another, I couldn’t find a way to compare whether the difference was significant. Additionally, doing regression the usual way gives access to a bunch of testing for regression assumptions that are invaluable. For a more detailed answer on this issue see my other question that was nicely answered by @StasK.

So the conclusion seems to be that lavaan is a decent package for FIML in R, yet the use of FIML depends on statistical assumptions and the type of analysis one is conducting. As far as regression (without latent variable modeling) goes, keeping it out of SEM programs and using multiple imputation is probably a wise move.

  • $\begingroup$ Is there any update on this? I need to do exactly this, but I can't seem to get an out-of-the-box option in lme4. Are you aware of a way? $\endgroup$
    – Outsider
    May 16 at 20:00

there is 2 main ways of handling missing data/records. U either delete the entire row of observation that has a missing value, or you find a way to generate this missing value. If u take the first approach, then you might end up losing a lot of data. In the second approach, you have to find a "clever" way to generate this missing data, in such a way that the parameters estimates of the the new data set, is not much different from the paramaters estimates of the observed data set.

This second approach is called Data imputation, and there are several R packages that do that. One of them is called mclust, and the function you need is called imputeData. This function using the EM (expectation maximization) algorithm to estimate the parameters of the unobserved part of the data set, given the observed part. Once the parameters are found, the new data point are generated. The distribution assumption of the missing data, the observed data, and the entire data set is assumed to be Gaussian.

Hope this explanation helps u achieve what you are trying to do

  • $\begingroup$ Thanks. I'm aware of packages for multiple imputation, but would like to see whether there is a relatively simple way to do maximum likelihood estimation. $\endgroup$
    – Sootica
    Feb 28, 2013 at 2:48
  • $\begingroup$ The likelihood function is not defined for when the sample, x, is missing. SO i think you might be searching for something that doesn't exist. $\endgroup$
    – Lalas
    Feb 28, 2013 at 2:54
  • 2
    $\begingroup$ See this paper for an explanation of utilizing maximum likelihood approaches to missing data (Allison, 2012). What the OP describes exists. $\endgroup$
    – Andy W
    Feb 28, 2013 at 12:36
  • 2
    $\begingroup$ And here's something from SAS about it. support.sas.com/documentation/cdl/en/statug/63347/HTML/default/… I've never seen anything in R. $\endgroup$ Mar 30, 2013 at 22:31
  • $\begingroup$ Thanks @JeremyMiles, I just posted what has helped me in answering this question, thought others might find it helpful too. PS. The R book your wrote with Andy Field is awesome!! :D $\endgroup$
    – Sootica
    Mar 31, 2013 at 8:34

Your Answer

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

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