{smcl}
{* *! version 1.0.1 12jun2023}{...}
{vieweralsosee "gsem" "help gsem"}{...}
{vieweralsosee "gsem postestimation" "help gsem_postestimation"}{...}
{viewerjumpto "Syntax" "lcaentropy##syntax"}{...}
{viewerjumpto "Examples" "lcaentropy##examples"}{...}
{title:Title}

{p2colset 5 14 20 2}{...}
{p2col :{cmd:lcaentropy} {hline 2} Calculate entropy for models with categorical latent variables}{p_end}
{p2colreset}{...}

{marker syntax}{...}
{title:Syntax}

{p 8 13 2}
{cmd:lcaentropy}
[{cmd:,}
{opt force}]

{marker opts_table}{...}
{synoptset 25 tabbed}{...}
{synopthdr:options}
{synoptline}
{synopt :{opt force}} Forces the calculation of entropy when small values of {it:p} result in missing values of ln({it:p}) by replacing {it:p}*ln({it:p}) with 0 in those cases.{p_end}
{synoptline}

{marker description}{...}
{title:Description}

{pstd}{cmd: lcaentropy} calculates entropy after a model with one or more categorical latent variables (e.g. latent class or latent profile models) is estimated using {help gsem}. Entropy can be described as a measure of certainty of
posterior classification. The measure of entropy implemented by {cmd:lcaentropy} was first described by Ramaswamy, DeSarbo, Reibstein, and Robinson (1993), and is commonly described in the latent class analysis literature (see, for example, Collins and Lanza, 2010). {cmd:lcaentropy} uses the predicted posterior latent class probabilities generated by {cmd:predict} (see {help gsem_predict}).{p_end}

{pstd}When the model contains more than one categorical latent variable, {cmd:lcaentropy} returns entropy calculated across all combinations of the categorical latent variables, as well as entropy for each latent variable separately.{p_end}

{marker options}{...}
{title:Options}

{phang}
{cmd:force} prevents an error when small predicted probabilities result in missing values. Calculating entropy requires the evaluation of {it:p}*ln({it:p}) where it {it:p} is the predicted posterior
 probability of each observation belonging to a given class. When {it:p} < 1e-323, the function {help ln()} returns a missing value. By default {cmd:lcaentropy} returns an error when values of {it:p} are
sufficiently small to result in a missing value from {help ln()}. Using {cmd:force} effectively sets {it:p}*ln({it:p}) to 0 for that observation in the particular class. 

{marker examples}{...}
{title:Examples}

{pstd}Setup{p_end}
{phang2}{cmd:. webuse gsem_lca1}{p_end}
{phang2}{cmd:. gsem (accident play insurance stock <- ), logit lclass(C 2)}{p_end}

{pstd}Calculate entropy{p_end}
{phang2}{cmd:. lcaentropy}{p_end}

 
{marker results}{...}
{title:Stored results}

{pstd}
{cmd:lcaentropy} stores the following in {cmd:r()}:

{synoptset 23 tabbed}{...}
{p2col 5 23 26 2: Scalars}{p_end}
{synopt:{cmd:r(entropy)}}Entropy across all categorical latent variables{p_end}

{synoptset 23 tabbed}{...}
{p2col 5 23 26 2: Matrices}{p_end}
{synopt:{cmd:r(class_entropy)}}Entropy for each class{p_end}


{marker references}{...}
{title:References}

{phang}
Collins, L. M., & Lanza, S. T. (2009). Latent class and latent transition analysis: With applications in the social, behavioral, and health sciences (Vol. 718). John Wiley & Sons.

{phang}
Ramaswamy, V., DeSarbo, W. S., Reibstein, D. J., & Robinson, W. T. (1993). An empirical pooling approach for estimating marketing mix elasticities with PIMS data. Marketing science, 12(1), 103-124.


{title:Author}
	
{pstd}RA Medeiros{break}
RA Medeiros Statistical Consulting{break}
{browse "mailto:ramedeiros@ramstat.com":ramedeiros@ramstat.com}{break}
{p_end}