Skip to contents
library(hyperion.tables)
library(hyperion)
#> 
#> 
#> ── pharos configuration ────────────────────────────────────────────────────────
#>  pharos.toml found: /data/user-homes/tariq/projects/prism-pkgdocs-build/installed-pkgs/2026-03-02/hyperion.tables_0.3.0/vignettes/pharos.toml
#> ── hyperion options ────────────────────────────────────────────────────────────
#>  hyperion.significant_number_display : 4
#> ── hyperion nonmem object options ──────────────────────────────────────────────
#>  hyperion.nonmem_model.show_included_columns : FALSE
#>  hyperion.nonmem_summary.rse_threshold : 50
#>  hyperion.nonmem_summary.shrinkage_threshold : 30

library(gt)
library(flextable)

model_dir <- system.file("extdata", "models", "onecmt", package = "hyperion.tables")
model_run <- "run003"

Model Comparison

spec <- TableSpec() |>
  set_spec_transforms(omega = "cv") |>
  set_spec_sections(
    kind == "THETA" ~ "Structural model parameters",
    kind == "OMEGA" & diagonal ~ "Interindividual variance parameters",
    kind == "OMEGA" & !diagonal ~ "Interindividual covariance parameters",
    kind == "SIGMA" ~ "Residual variance",
    TRUE ~ "Other"
  ) |>
  set_spec_sigfig(3) |>
  drop_spec_columns("variability", "shrinkage", "rse") |>
  set_spec_pvalue(scientific = FALSE)

child_mod <- read_model(file.path(model_dir, paste0(model_run, ".mod")))
child_sum <- summary(child_mod)
child_info <- get_model_parameter_info(child_mod)

parent_mod <- read_model(file.path(model_dir, "run002.mod"))
mod_sum <- summary(parent_mod)
info <- get_model_parameter_info(parent_mod)

get_parameters(parent_mod) |>
  apply_table_spec(spec, info) |>
  add_summary_info(mod_sum) |>
  compare_with(
    get_parameters(child_mod) |>
      apply_table_spec(spec, child_info) |>
      add_summary_info(child_sum),
    labels = c("run002", "run003")
  ) |>
  make_comparison_table()
#> LRT suppressed for run002 vs run003: no lineage attached
#>  Both OFVs and matching observation counts are present, but LRT conditions are not met.
Model Parameters
Parameter
run002
run003
Symbol Unit Estimate 95% CI Symbol Unit Estimate 95% CI % Change
Structural model parameters
TVCL θ1\theta_{1} L/hr 1.25 [0.994, 1.50] θ1\theta_{1} L/hr 1.33 [1.11, 1.54] 6.31
TVV θ2\theta_{2} L 40.8 [34.9, 46.8] θ2\theta_{2} L 40.2 [34.6, 45.7] -1.68
TVKA θ3\theta_{3} 1/hr 1.24 [1.02, 1.47] θ3\theta_{3} 1/hr 1.21 [0.997, 1.43] -2.59
Interindividual variance parameters
OM1 TVCL Ω(1,1)\Omega_{(1,1)} 0.130 [0.0125, 0.248] Ω(1,1)\Omega_{(1,1)} 0.122 [0.0236, 0.221] -6.19
OM2 TVV Ω(2,2)\Omega_{(2,2)} 0.136 [0.0585, 0.214] Ω(2,2)\Omega_{(2,2)} 0.124 [0.0519, 0.196] -9.14
OM3 TVKA Ω(3,3)\Omega_{(3,3)} 0.114 [-0.00602, 0.235] Ω(3,3)\Omega_{(3,3)} 0.122 [0.0121, 0.233] 7.00
Interindividual covariance parameters
OM1,2 TVCL, TVV Ω(2,1)\Omega_{(2,1)} 0.0745 [0.0131, 0.136]
Residual variance
SIG1 Σ(1,1)\Sigma_{(1,1)} 0.0372 [0.0145, 0.0600] Σ(1,1)\Sigma_{(1,1)} 0.0375 [0.0257, 0.0494] 0.820
SIG2 Σ(2,2)\Sigma_{(2,2)} 0.00661 [-0.0481, 0.0613] Σ(2,2)\Sigma_{(2,2)} 0.00527 [-0.0128, 0.0233] -20.2
Condition Number: 29.6 (run002), 6.17 (run003)
No. of Observations: 210 (run002), 210 (run003)
OFV: -103.468 (run002), -109.826 (run003)
95% CI: Estimate±z0.025SE\mathrm{Estimate} \pm z_{0.025} \cdot \mathrm{SE}
% Change: EstimatemodelEstimaterefEstimateref100\frac{\mathrm{Estimate}_{\mathrm{model}} - \mathrm{Estimate}_{\mathrm{ref}}}{\mathrm{Estimate}_{\mathrm{ref}}} \cdot 100
Abbreviations:
CI = confidence intervals; RSE = relative standard error; SE = standard error;
OFV = Objective Function Value

Multiple Comparison Table

spec <- TableSpec() |>
  set_spec_transforms(omega = "cv") |>
  set_spec_sections(
    kind == "THETA" ~ "Structural model parameters",
    kind == "OMEGA" & diagonal ~ "Interindividual variance parameters",
    kind == "OMEGA" & !diagonal ~ "Interindividual covariance parameters",
    kind == "SIGMA" ~ "Residual error",
    TRUE ~ "Other"
  ) |>
  set_spec_sigfig(3) |>
  set_spec_columns("symbol", "estimate", "ci", "rse", "pct_change") |>
  set_spec_hide_empty(FALSE)

mod1 <- read_model(file.path(model_dir, "run002.mod"))
mod_sum1 <- summary(mod1)
info1 <- get_model_parameter_info(mod1)

mod2 <- read_model(file.path(model_dir, "run003.mod"))
mod_sum2 <- summary(mod2)
info2 <- get_model_parameter_info(mod2)

mod3 <- read_model(file.path(model_dir, "run003b1.mod"))
mod_sum3 <- summary(mod3)
info3 <- get_model_parameter_info(mod3)

comp <- get_parameters(mod1) |>
  apply_table_spec(spec, info1) |>
  add_summary_info(mod_sum1) |>
  compare_with(
    get_parameters(mod2) |>
      apply_table_spec(spec, info2) |>
      add_summary_info(mod_sum2),
    labels = c("run002", "run003")
  ) |>
  compare_with(
    get_parameters(mod3) |>
      apply_table_spec(spec, info3) |>
      add_summary_info(mod_sum3),
    labels = c("run003b1")
  )

comp |>
  make_comparison_table()
#> LRT suppressed for run002 vs run003: no lineage attached
#>  Both OFVs and matching observation counts are present, but LRT conditions are not met.
#> LRT suppressed for run003 vs run003b1: no lineage attached
#>  Both OFVs and matching observation counts are present, but LRT conditions are not met.
Model Parameters
Parameter
run002
run003
run003b1
Symbol Estimate 95% CI RSE (%) Symbol Estimate 95% CI RSE (%) % Change vs run002 Symbol Estimate 95% CI RSE (%) % Change vs run003
Structural model parameters
TVCL θ1\theta_{1} 1.25 [0.994, 1.50] 10.3 θ1\theta_{1} 1.33 [1.11, 1.54] 8.41 6.31 θ1\theta_{1} 1.25 -5.67
TVV θ2\theta_{2} 40.8 [34.9, 46.8] 7.41 θ2\theta_{2} 40.2 [34.6, 45.7] 7.07 -1.68 θ3\theta_{3} 40.3 0.296
TVKA θ3\theta_{3} 1.24 [1.02, 1.47] 9.12 θ3\theta_{3} 1.21 [0.997, 1.43] 9.06 -2.59 θ4\theta_{4} 1.22 0.490
WT-on-CL θ2\theta_{2} 0.545
Interindividual variance parameters
OM1 TVCL Ω(1,1)\Omega_{(1,1)} 0.130 [0.0125, 0.248] 46.1 Ω(1,1)\Omega_{(1,1)} 0.122 [0.0236, 0.221] 41.2 -6.19 Ω(1,1)\Omega_{(1,1)} 0.123 0.756
OM2 TVV Ω(2,2)\Omega_{(2,2)} 0.136 [0.0585, 0.214] 29.1 Ω(2,2)\Omega_{(2,2)} 0.124 [0.0519, 0.196] 29.7 -9.14 Ω(2,2)\Omega_{(2,2)} 0.125 0.587
OM3 TVKA Ω(3,3)\Omega_{(3,3)} 0.114 [-0.00602, 0.235] 53.7 Ω(3,3)\Omega_{(3,3)} 0.122 [0.0121, 0.233] 46.0 7.00 Ω(3,3)\Omega_{(3,3)} 0.124 1.20
Interindividual covariance parameters
OM1,2 TVCL, TVV Ω(2,1)\Omega_{(2,1)} 0.0745 [0.0131, 0.136] 42.0 Ω(2,1)\Omega_{(2,1)} 0.0722 -3.17
Residual error
SIG1 Σ(1,1)\Sigma_{(1,1)} 0.0372 [0.0145, 0.0600] 31.2 Σ(1,1)\Sigma_{(1,1)} 0.0375 [0.0257, 0.0494] 16.1 0.820 Σ(1,1)\Sigma_{(1,1)} 0.0374 -0.496
SIG2 Σ(2,2)\Sigma_{(2,2)} 0.00661 [-0.0481, 0.0613] 423 Σ(2,2)\Sigma_{(2,2)} 0.00527 [-0.0128, 0.0233] 175 -20.2 Σ(2,2)\Sigma_{(2,2)} 0.00589 11.8
Condition Number: 29.6 (run002), 6.17 (run003)
No. of Observations: 210 (run002), 210 (run003)
OFV: -103.468 (run002), -109.826 (run003)
Condition Number: 6.17 (run003), N/A (run003b1)
No. of Observations: 210 (run003), 210 (run003b1)
OFV: -109.826 (run003), -108.889 (run003b1)
95% CI: Estimate±z0.025SE\mathrm{Estimate} \pm z_{0.025} \cdot \mathrm{SE}
% Change: EstimatemodelEstimaterefEstimateref100\frac{\mathrm{Estimate}_{\mathrm{model}} - \mathrm{Estimate}_{\mathrm{ref}}}{\mathrm{Estimate}_{\mathrm{ref}}} \cdot 100
Abbreviations:
CI = confidence intervals; RSE = relative standard error; SE = standard error;
OFV = Objective Function Value

Structural model comparison

spec <- TableSpec() |>
  set_spec_transforms(omega = "cv") |>
  set_spec_sections(
    kind == "THETA" ~ "Structural model parameters",
    kind == "OMEGA" & diagonal ~ "Interindividual variance parameters",
    kind == "OMEGA" & !diagonal ~ "Interindividual covariance parameters",
    kind == "SIGMA" ~ "Residual error",
    TRUE ~ "Other"
  ) |>
  set_spec_sigfig(3) |>
  set_spec_columns("symbol", "fixed", "estimate") |>
  set_spec_title("Structural Model Parameter Comparison")

mod1 <- read_model(file.path(model_dir, "run001.mod"))
mod_sum1 <- summary(mod1)
info1 <- get_model_parameter_info(mod1)

mod2 <- read_model(file.path(model_dir, "run002.mod"))
mod_sum2 <- summary(mod2)
info2 <- get_model_parameter_info(mod2)

mod3 <- read_model(file.path(model_dir, "run003.mod"))
mod_sum3 <- summary(mod3)
info3 <- get_model_parameter_info(mod3)

mod4 <- read_model(file.path(model_dir, "run003b1.mod"))
mod_sum4 <- summary(mod4)
info4 <- get_model_parameter_info(mod4)

comp <- get_parameters(mod1) |>
  apply_table_spec(spec, info1) |>
  add_summary_info(mod_sum1) |>
  compare_with(
    get_parameters(mod2) |>
      apply_table_spec(spec, info2) |>
      add_summary_info(mod_sum2),
    labels = c("run001", "run002")
   ) |>
  compare_with(
    get_parameters(mod3) |>
      apply_table_spec(spec, info3) |>
      add_summary_info(mod_sum3),
    labels = c("run003")
  ) |>
  compare_with(
    get_parameters(mod4) |>
      apply_table_spec(spec, info4) |>
      add_summary_info(mod_sum4),
    labels = c("run004")
  )
comp |>
  make_comparison_table()
#> LRT suppressed for run001 vs run002: no lineage attached
#>  Both OFVs and matching observation counts are present, but LRT conditions are not met.
#> LRT suppressed for run002 vs run003: no lineage attached
#>  Both OFVs and matching observation counts are present, but LRT conditions are not met.
#> LRT suppressed for run003 vs run004: no lineage attached
#>  Both OFVs and matching observation counts are present, but LRT conditions are not met.
Structural Model Parameter Comparison
Parameter
run001
run002
run003
run004
Symbol Fixed Estimate Symbol Fixed Estimate Symbol Fixed Estimate Symbol Fixed Estimate
Structural model parameters
TVCL θ1\theta_{1} 1.24 θ1\theta_{1} 1.25 θ1\theta_{1} 1.33 θ1\theta_{1} 1.25
TVV θ2\theta_{2} 40.9 θ2\theta_{2} 40.8 θ2\theta_{2} 40.2 θ3\theta_{3} 40.3
TVKA θ3\theta_{3} 1.24 θ3\theta_{3} 1.24 θ3\theta_{3} 1.21 θ4\theta_{4} 1.22
WT-on-CL θ2\theta_{2} 0.545
Interindividual variance parameters
OM1 TVCL Ω(1,1)\Omega_{(1,1)} 0.131 Ω(1,1)\Omega_{(1,1)} 0.130 Ω(1,1)\Omega_{(1,1)} 0.122 Ω(1,1)\Omega_{(1,1)} 0.123
OM2 TVV Ω(2,2)\Omega_{(2,2)} 0.136 Ω(2,2)\Omega_{(2,2)} 0.136 Ω(2,2)\Omega_{(2,2)} 0.124 Ω(2,2)\Omega_{(2,2)} 0.125
OM3 TVKA Ω(3,3)\Omega_{(3,3)} Fixed 0.100 Ω(3,3)\Omega_{(3,3)} 0.114 Ω(3,3)\Omega_{(3,3)} 0.122 Ω(3,3)\Omega_{(3,3)} 0.124
Interindividual covariance parameters
OM1,2 TVCL, TVV Ω(2,1)\Omega_{(2,1)} 0.0745 Ω(2,1)\Omega_{(2,1)} 0.0722
Residual error
Proportional Σ(1,1)\Sigma_{(1,1)} 0.0364
Additive Σ(2,2)\Sigma_{(2,2)} Fixed 0.0100
SIG1 Σ(1,1)\Sigma_{(1,1)} 0.0372 Σ(1,1)\Sigma_{(1,1)} 0.0375 Σ(1,1)\Sigma_{(1,1)} 0.0374
SIG2 Σ(2,2)\Sigma_{(2,2)} 0.00661 Σ(2,2)\Sigma_{(2,2)} 0.00527 Σ(2,2)\Sigma_{(2,2)} 0.00589
Condition Number: 1.98 (run001), 29.6 (run002)
No. of Observations: 210 (run001), 210 (run002)
OFV: -103.299 (run001), -103.468 (run002)
Condition Number: 29.6 (run002), 6.17 (run003)
No. of Observations: 210 (run002), 210 (run003)
OFV: -103.468 (run002), -109.826 (run003)
Condition Number: 6.17 (run003), N/A (run004)
No. of Observations: 210 (run003), 210 (run004)
OFV: -109.826 (run003), -108.889 (run004)
% Change: EstimatemodelEstimaterefEstimateref100\frac{\mathrm{Estimate}_{\mathrm{model}} - \mathrm{Estimate}_{\mathrm{ref}}}{\mathrm{Estimate}_{\mathrm{ref}}} \cdot 100
Abbreviations:
OFV = Objective Function Value