
Marginal Model Goodness of Fit and Information Criteria for Single-Cell Simulators
Source:R/01_metrics_distribution.R
calc_marginal_aic_bic.RdEvaluates gene-wise and aggregate marginal goodness-of-fit (Poisson, Negative Binomial, or Gaussian) for simulated or fitted single-cell count matrices, computing total and mean AIC and BIC across genes (scDesign3; Song et al., 2024).
Usage
calc_marginal_aic_bic(
counts,
fitted_means,
dispersions = NULL,
distribution = c("poisson", "nb", "gaussian"),
n_params_per_gene = NULL
)Arguments
- counts
Matrix or data.frame of observed or simulated counts (genes x cells).
- fitted_means
Matrix or data.frame of model fitted means or expectations (genes x cells).
- dispersions
Optional vector of gene-level dispersion parameters for Negative Binomial model. If NULL, estimated via method-of-moments.
- distribution
Parametric distribution: "poisson", "nb" (Negative Binomial), or "gaussian".
- n_params_per_gene
Number of estimated parameters per gene. If NULL, defaults to 1 for Poisson, 2 for NB, and 2 for Gaussian.
Value
A list containing:
- total_loglik
Sum of marginal log-likelihoods across all genes and cells.
- total_aic
Aggregate AIC across all genes.
- total_bic
Aggregate BIC across all genes.
- mean_gene_aic
Mean AIC per gene.
- mean_gene_bic
Mean BIC per gene.
- gene_loglik
Vector of log-likelihoods per gene.
- gene_aic
Vector of AIC per gene.
- gene_bic
Vector of BIC per gene.
Examples
calc_marginal_aic_bic(stats::rnorm(50), stats::rnorm(50))
#> $total_loglik
#> [1] 37.56364
#>
#> $total_aic
#> [1] 24.87273
#>
#> $total_bic
#> [1] -75.12727
#>
#> $mean_gene_aic
#> [1] 0.4974546
#>
#> $mean_gene_bic
#> [1] -1.502545
#>
#> $gene_loglik
#> [1] 19.4391586 -1.9320021 -3.4099917 1.3698423 10.3553300 12.7520064
#> [7] -34.4251317 -10.2453478 -0.2592849 -17.4280258 -12.7478252 -1.1869938
#> [13] -5.1654507 -10.6309281 2.5749955 11.5110631 -1.0604829 7.7038875
#> [19] 6.7857360 -1.0797968 18.8770535 38.3236450 5.9748665 -0.8771513
#> [25] -4.8072462 -3.8229466 -12.0994475 -1.6269355 -16.0691805 -10.6291873
#> [31] -1.7592546 -19.6763180 -16.6616440 -0.6876524 -13.6640101 26.9435846
#> [37] -0.6022095 -4.6684055 8.8759707 2.3974766 -1.1905040 -1.3381321
#> [43] 17.3315810 -1.4881821 -0.6454088 -0.1961475 13.6547496 51.1289504
#> [49] -5.0550334 -1.3000030
#>
#> $gene_aic
#> [1] -36.8783173 5.8640043 8.8199835 -0.7396846 -18.7106600
#> [6] -23.5040128 70.8502634 22.4906956 2.5185698 36.8560517
#> [11] 27.4956503 4.3739877 12.3309015 23.2618563 -3.1499909
#> [16] -21.0221262 4.1209658 -13.4077749 -11.5714720 4.1595936
#> [21] -35.7541069 -74.6472899 -9.9497330 3.7543027 11.6144924
#> [26] 9.6458932 26.1988951 5.2538710 34.1383611 23.2583746
#> [31] 5.5185091 41.3526360 35.3232880 3.3753049 29.3280202
#> [36] -51.8871693 3.2044190 11.3368110 -15.7519413 -2.7949533
#> [41] 4.3810081 4.6762641 -32.6631621 4.9763642 3.2908177
#> [46] 2.3922949 -25.3094993 -100.2579008 12.1100668 4.6000060
#>
#> $gene_bic
#> [1] -38.8783173 3.8640043 6.8199835 -2.7396846 -20.7106600
#> [6] -25.5040128 68.8502634 20.4906956 0.5185698 34.8560517
#> [11] 25.4956503 2.3739877 10.3309015 21.2618563 -5.1499909
#> [16] -23.0221262 2.1209658 -15.4077749 -13.5714720 2.1595936
#> [21] -37.7541069 -76.6472899 -11.9497330 1.7543027 9.6144924
#> [26] 7.6458932 24.1988951 3.2538710 32.1383611 21.2583746
#> [31] 3.5185091 39.3526360 33.3232880 1.3753049 27.3280202
#> [36] -53.8871693 1.2044190 9.3368110 -17.7519413 -4.7949533
#> [41] 2.3810081 2.6762641 -34.6631621 2.9763642 1.2908177
#> [46] 0.3922949 -27.3094993 -102.2579008 10.1100668 2.6000060
#>