I've been reading about so-called "k Nearest Neighbor Density Estimators". This short paper
http://scholar.google.com/scholar?cluster=16043802846384639781&hl=en&as_sdt=0,33compares three of these things. Basically, they are scalar functions of a vector --- based on Euclidean distances to other rows --- that are not exactly proper density functions (because they integrate to infinity) but converge pointwise to a genuine density function as the number of observations increases. In particular, the function being pushed in the above paper converges to a gamma density. So, someone could potentially utilize this function if it were implemented in Stan and live with the fact that it is not quite a proper density or utilize a gamma density and live with the fact that it is not quite the right function. My gut says that it wouldn't matter much either way relative to the magnitude of the problem I am contemplating, which is that the datamatrix could have an arbitrary missingness pattern.
If all the variables were continuous but partially missing, then a full Bayesian approach would be pretty straightforward: Make parameters for the missing cells, put priors on them, index-fiddle to put these parameters into the right locations in the datamatrix, use something from that article as your "likelihood", let Stan run until convergence, and get a whole bunch of completed datamatrices to use in a subsequent analysis. Basically, it is just a joint multiple imputation algorithm with relaxed parametric assumptions.
Finding the k nearest neighbors is computationally difficult. But among rows that are fully observed, you only have to calculate the Euclidean distances once. And among rows that are incompletely observed, you can calculate a partial sum of squared differences once based on the columns where both rows are observed once and then you just have to tack on the remaining sum of squared differences for the columns where one or both rows are filled with parameters. And even still, we could do the whole thing in doubles to find the k nearest neighbors and then handle the derivatives manually. In other words, we don't need to mess with the derivatives for the (k + m)th distances because they never enter the "likelihood".
If the datamatrix includes discrete variables with missingness, we are not completely stuck by the fact that Stan can't do discrete parameters yet. Explode discrete variables into a full set of dummy variables and if missing, define an underlying parameter as a simplex of probabilities with some reasonable prior. The contribution to the total sum of squared differences for those columns is just 2.0 times the probability that the discrete variable differs between the two rows. To see this, say you have a variable like education with four levels (less than high school, HS or GED, some college, college degree). Then you might have two fully observed people that were both category two
row i: [...,0,1,0,0,...]
row j: [...,0,1,0,0,...]
in which case the contribution to the sum of squared differences is zero. Or two observed people with different levels of eduction
row i: [...,0,1,0,0,...]
row j: [...,0,0,0,1,...]
in which case the contribution to the sum of squared differences is 2. So, if row j were instead missing, the contribution to the sum of squares would be 2 times the probability that j is not in the HS / GED category. If both i and j were missing, then the contribution to the sum of squares is more complicated to calculate but has the same basic form. When Stan is done, you can draw realizations from a multinomial distribution with the corresponding posterior probability vector as your imputations.
Of course, that assumes it is reasonable to say that the "distance" between i and j is the same and has a weird cardinal value no matter how i and j differ in their education levels. E.g. if i drops out of high school and j graduates from college, they have the same distance as if i graduates from high school and j drops out of college. But at least the contribution to the distance is zero for two people with the same education level, and the fact that you have missing data on discrete variables is a much bigger problem.
I can't think of anything clever to deal with variables that are counts, but it is probably fine to treat them as continuous, impute missing elements with real parameters, and perhaps round the imputed values to the nearest integer once Stan is finished.
Thoughts?
Ben