Checks for perfect or quasi-perfect separation between latent classes, which can cause estimation problems.
Value
List with components:
- has_separation
Logical; is separation detected?
- separation_type
"none", "quasi", or "perfect"
- pct_extreme
Percentage of individuals with extreme probabilities
- class_sizes
Weighted and unweighted class sizes
- entropy
Classification entropy
- recommendation
Text recommendation
Details
Perfect separation occurs when latent classes are completely distinguished by observed variables, leading to: - Entropy approaching 1.0 - All posterior probabilities near 0 or 1 - Unstable parameter estimates - Inflated standard errors
This function checks for: 1. **Perfect separation**: All individuals assigned to classes with prob > 0.999 2. **Quasi-perfect separation**: Most individuals have extreme probabilities 3. **Empty classes**: Classes with very few assigned members
Examples
# \donttest{
# Simulate data
set.seed(456)
sim_data <- simulate_gmm_survey(
n_individuals = 300,
n_times = 4,
n_classes = 3,
design = "stratified_cluster",
n_strata = 3,
n_clusters = 30,
seed = 456
)
fit <- gmm_survey(
data = sim_data,
id = "id", time = "time", outcome = "outcome",
n_classes = 3, starts = 20
)
#> Validating inputs...
#> Preparing data...
#> N = 300 individuals
#> T = 4 time points
#> Time scores: 0, 1, 2, 3
#>
#> Running 20 random starts with 3 classes...
#>
#> Selecting best solution...
#> Best logLik: -2841.8219
#> Replicated 1 times
#> 20/20 starts converged
#> Warning: Best log-likelihood not replicated. Consider increasing 'starts'.
#>
#> Computing survey-adjusted standard errors...
#> Computing fit indices...
#>
#> Completed in 5.9 seconds
sep_check <- diagnose_separation(fit)
print(sep_check)
#> $has_separation
#> [1] FALSE
#>
#> $separation_type
#> [1] "none"
#>
#> $pct_extreme
#> [1] 0
#>
#> $min_posterior_prob
#> [1] 0.3541663
#>
#> $max_posterior_prob
#> [1] 0.987502
#>
#> $class_sizes
#> $class_sizes$unweighted
#> class_assignment
#> 1 3
#> 54 246
#>
#> $class_sizes$weighted
#> class_assignment
#> 1 3
#> 54 246
#>
#> $class_sizes$proportion
#> class_assignment
#> 1 3
#> 0.18 0.82
#>
#>
#> $entropy
#> [1] 0.6108606
#>
#> $entropy_relative
#> [1] 0.6108606
#>
#> $recommendation
#> [1] "No separation issues detected."
#>
#> attr(,"class")
#> [1] "separation_diagnostics"
# }