How do I use the model generated by the R package poLCA to classify new data as belonging to one of the classes? For example, in the election example from the documentation, if I create a new set of answers to the questions, how can I use the poLCA model to tell me what class (cluster) it's most likely to be in?

There doesn't appear to be a function to do this, though the model has a df within it that lists the probabilities of class membership for each value of each manifest variable. I'm tasked with converting some sql code that takes a second dataset and classifies the patients there as members of the clusters created from a first. Superficially this is a programming question. It seems like a function to do this would be a reasonable addition to the package. More deeply, if indeed there isn't such a function, it would become a question about how to use the table of probabilities to classify new data.

If readers aren't familiar with the R package poLCA, it's an LCA package that works with discrete/categorized data.

(full disclosure: I asked on cross-validated and a shorter version of this question was put on hold.)
Using carcinoma data available in the poLCA package and a 4 latent classes solution:

 library poLCA
 data(carcinoma)
 f &lt;- cbind(A, B, C, D, E, F, G) ~ 1
 lc4 &lt;- poLCA(f, carcinoma, nclass = 4)


The following line give the classification in terms of predicted probabilities

 lc4$predclass


They could be usefully binded to the original data for further visualizations or analyses

 carcinoma.predclass &lt;- cbind(carcinoma, "Predicted LC" = lc4$predclass)
 head(carcinoma.predclass)


You could have a new data frame with the same columns/variables used in the previous analysis.

new.data &lt;- data.frame(A=c(1,2,1), B=c(2,2,1), C=c(1,2,1), D=c(1,1,1), E=c(1,2,1), F=c(2,2,1), G=c(1,2,1))

  A B C D E F G
1 1 2 1 1 1 2 1
2 2 2 2 1 2 2 2
3 1 1 1 1 1 1 1


A simple method can be link the observed data patterns in the new data frame with the estimated latent class probabilities in the previous data. In fact, the first pattern has missing prediction because it wasn't in the training data.

left_join(new.data, unique(carcinoma.predclass))

Joining, by = c("A", "B", "C", "D", "E", "F", "G")
  A B C D E F G Predicted LC
1 1 2 1 1 1 2 1           NA
2 2 2 2 1 2 2 2            1
3 1 1 1 1 1 1 1            4


The best method is to use the posterior of poLCA. From the parameters estimated by the latent class model, this function calculates the probability that a specified pattern belongs to each latent class. This function can calculate posterior class membership probabilities for new data, observed or not in the training data.

new.lc4.posterior &lt;- poLCA.posterior(lc4, new.data)


And bind the predicted Latent Classes (the classes which the highest posterior probability) to the new data.

cbind(new.data, "Predicted LC" = apply(new.lc4.posterior,1, FUN=which.max))

  A B C D E F G Predicted LC
1 1 2 1 1 1 2 1            2
2 2 2 2 1 2 2 2            1
3 1 1 1 1 1 1 1            4