Clustering, density estimation, and anomaly detection · Mixture and density models · UCL043 · Model
Latent class analysis
Discover unobserved classes from categorical response patterns. Common uses include survey profiles, symptom patterns, and categorical market segmentation.
In CodeSplash
A CodeSplash method runs this entry in Python and R. Set it up from the method's page.
- Latent class analysis Verified in Python and R
Do it in CodeSplash Run it on your own data, in Python or R.
- Availability
- Runs in CodeSplash
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's run and the reference's record
- CodeSplash's run
- Verified in Python and R through discover.lca. The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Discover unobserved classes from categorical response patterns. Common uses include survey profiles, symptom patterns, and categorical market segmentation.
Question / hypotheses
Which probability model adequately explains the reference distribution and its latent heterogeneity? This entry defines an estimation or optimization objective, not an intrinsic null/alternative hypothesis test.
Architecture / computational structure
A finite categorical-product mixture with conditional independence inside each class.
Assumptions
Local independence can fail when items remain associated within classes; extra classes may then represent residual dependence rather than substantive populations. Rare response patterns can cause boundary estimates and weak identifiability.
Formula / computational definition
, with class weights and class-specific category probabilities . The product across variables expresses local independence conditional on class. EM estimates parameters and posterior class memberships.
Parameters and notation
Learned or fitted quantities: Class weights, category probabilities, and posterior class memberships. User-set hyperparameters/design choices: Select class count, starting values, convergence rules, and treatment of missing responses. Tune these against the stated objective and stability/validation criteria; do not select settings on the final evaluation set.
Fitting, fine-tuning, and adaptation
Refit likelihood or posterior parameters on the new reference population; neural fine-tuning does not apply to this classical model. Warm starts can reduce computation but should be compared with fresh initialization. Recheck predictive fit and regularization after a domain shift.
How to use and calibrate
Use likelihood-based model selection cautiously, multiple starts, posterior uncertainty, and residual item-pair associations. Compare class profiles and stability rather than treating the smallest BIC as a complete substantive argument.
Example application
Identify latent survey response profiles from categorical items. Define the reference population, measurement units, and success criterion before fitting; investigate whether discovered groups or alerts reflect the intended phenomenon.
Interpretation / pitfalls
Watch out
The reported result is conditional on the representation and objective. A stable partition can reflect nuisance structure such as batch, collection site, or missingness. Confirm the interpretation in original variables and an independent sample.
Python and R code examples
R poLCA::poLCA is a native implementation for polytomous responses. Python can fit the categorical mixture with a custom log-sum-exp EM loop or bridge to R. Binary Bernoulli mixtures are a special case, not a separate entry here.
Component: Binary latent-class response-pattern probability. Python: executed successfully; R: not executed (Rscript unavailable). These small fixtures establish the arithmetic operation, not full-method accuracy or reproduction of paper results.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — Binary latent-class response-pattern probability. · needs numpy
import numpy as np
x=np.array([1,0,1]); theta=np.array([[.8,.2,.7],[.3,.6,.4]]); pi=np.array([.5,.5])
w=pi*np.prod(theta**x*(1-theta)**(1-x),axis=1)
result=np.r_[w.sum(),w/w.sum()]
print(result)
Component demo, not a trained model — Binary latent-class response-pattern probability.
x=c(1,0,1); theta=rbind(c(.8,.2,.7),c(.3,.6,.4)); pi=c(.5,.5)
w=pi*apply(sweep(theta,2,x,'^')*sweep(1-theta,2,1-x,'^'),1,prod)
result=c(probability=sum(w),w/sum(w))
print(result)
Sources
- Source 1cran.r-project.org
From the CodeSplash reference, entry UCL043.