Heterogeneity analysis is a way to explore how the results of a model can vary depending on the characteristics of individuals in a population, and demographic analysis estimates the average values of a model over an entire population.
In practice these two analyses naturally complement each other: heterogeneity analysis runs the model on multiple sets of parameters (reflecting differents characteristics found in the target population), and demographic analysis combines the results.
For this example we will use the result from the assessment of a new total hip replacement previously described in vignette("d-non-homogeneous", "heemod")
.
The characteristics of the population are input from a table, with one column per parameter and one row per individual. Those may be for example the characteristics of the indiviuals included in the original trial data.
For this example we will use the characteristics of 100 individuals, with varying sex and age, specified in the data frame tab_indiv
:
tab_indiv
## # A tibble: 100 × 2
## age sex
## <dbl> <int>
## 1 63 1
## 2 63 1
## 3 73 1
## 4 51 1
## 5 63 1
## 6 50 1
## 7 73 0
## 8 56 1
## 9 57 0
## 10 58 0
## # ... with 90 more rows
library(ggplot2)
ggplot(tab_indiv, aes(x = age)) +
geom_histogram(binwidth = 2)
res_mod
, the result we obtained from run_model()
in the Time-varying Markov models vignette, can be passed to update()
to update the model with the new data and perform the heterogeneity analysis.
res_h <- update(res_mod, newdata = tab_indiv)
## No weights specified in update, using equal weights.
## Updating strategy 'standard'...
## Updating strategy 'np1'...
The summary()
method reports summary statistics for cost, effect and ICER, as well as the result from the combined model.
summary(res_h)
## Loading required namespace: Hmisc
## An analysis re-run on 100 parameter sets.
##
## * Unweighted analysis.
##
## * Values distribution:
##
## Min. 1st Qu. Median Mean
## standard - Cost 485.85297365 613.8364635 665.3485485 700.1065556
## standard - Effect 9.32287610 22.7930050 27.3769142 25.5743852
## standard - Cost Diff. - - - -
## standard - Effect Diff. - - - -
## standard - Icer - - - -
## np1 - Cost 603.34263272 637.9508204 652.9595311 662.6411135
## np1 - Effect 9.38064927 23.0848338 27.7656911 25.8392225
## np1 - Cost Diff. -167.83433856 -110.7286273 -12.3890174 -37.4654421
## np1 - Effect Diff. 0.04405769 0.2051119 0.2214442 0.2648373
## np1 - Icer -355.65308588 -316.4394659 -57.5010098 -1.1709435
## 3rd Qu. Max.
## standard - Cost 802.3426777 882.1752204
## standard - Effect 29.0749005 31.1407367
## standard - Cost Diff. - -
## standard - Effect Diff. - -
## standard - Icer - -
## np1 - Cost 691.6140504 714.3408818
## np1 - Effect 29.5008365 31.6126413
## np1 - Cost Diff. 24.1143568 117.4896591
## np1 - Effect Diff. 0.3499204 0.4719046
## np1 - Icer 115.6325465 2666.7229585
##
## * Combined result:
##
## 2 strategies run for 60 cycles.
##
## Initial state counts:
##
## PrimaryTHR = 1000L
## SuccessP = 0L
## RevisionTHR = 0L
## SuccessR = 0L
## Death = 0L
##
## Counting method: 'end'.
##
## Values:
##
## utility cost
## standard 25574.39 700106.6
## np1 25839.22 662641.1
##
## Efficiency frontier:
##
## np1
##
## Differences:
##
## Cost Diff. Effect Diff. ICER Ref.
## np1 -37.46544 0.2648373 -141.4659 standard
The variation of cost or effect can then be plotted.
plot(res_h, result = "effect", binwidth = 5)
plot(res_h, result = "cost", binwidth = 50)
plot(res_h, result = "icer", type = "difference",
binwidth = 500)
plot(res_h, result = "effect", type = "difference",
binwidth = .1)
plot(res_h, result = "cost", type = "difference",
binwidth = 30)
The results from the combined model can be plotted similarly to the results from run_model()
.
plot(res_h, type = "counts")
Weights can be used in the analysis by including an optional column .weights
in the new data to specify the respective weights of each strata in the target population.
tab_indiv_w
## # A tibble: 100 × 3
## age sex .weights
## <dbl> <int> <dbl>
## 1 63 0 0.53983643
## 2 62 0 0.57833147
## 3 65 1 0.17316637
## 4 61 0 0.94031598
## 5 46 0 0.01133057
## 6 62 1 0.69021082
## 7 73 0 0.65562913
## 8 55 0 0.35579861
## 9 62 1 0.29374012
## 10 66 1 0.90436778
## # ... with 90 more rows
res_w <- update(res_mod, newdata = tab_indiv_w)
## Updating strategy 'standard'...
## Updating strategy 'np1'...
res_w
## An analysis re-run on 100 parameter sets.
##
## * Weigths distribution:
##
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.001342 0.253900 0.506700 0.493200 0.759900 0.992800
##
## Total weight: 49.31926
##
## * Values distribution:
##
## Min. 1st Qu. Median Mean
## standard - Cost 530.94590166 605.0062810 622.7847586 678.1247649
## standard - Effect 14.30828698 23.0146204 27.4413633 25.9822442
## standard - Cost Diff. - - - -
## standard - Effect Diff. - - - -
## standard - Icer - - - -
## np1 - Cost 615.48340627 635.5509751 640.3840220 656.4051279
## np1 - Effect 14.43982318 23.3039321 27.7991788 26.2311556
## np1 - Cost Diff. -155.93829747 -108.3891499 18.1782873 -21.7196370
## np1 - Effect Diff. 0.09203743 0.1948185 0.2137537 0.2489113
## np1 - Icer -349.93447295 -313.4504150 82.0897023 52.5296331
## 3rd Qu. Max.
## standard - Cost 802.3426777 871.8854128
## standard - Effect 29.0749005 31.3071020
## standard - Cost Diff. - -
## standard - Effect Diff. - -
## standard - Icer - -
## np1 - Cost 691.6140504 711.4055539
## np1 - Effect 29.5008365 31.5405654
## np1 - Cost Diff. 30.5446941 117.4896591
## np1 - Effect Diff. 0.3499204 0.4556047
## np1 - Icer 156.7853582 2666.7229585
##
## * Combined result:
##
## 2 strategies run for 60 cycles.
##
## Initial state counts:
##
## PrimaryTHR = 1000L
## SuccessP = 0L
## RevisionTHR = 0L
## SuccessR = 0L
## Death = 0L
##
## Counting method: 'end'.
##
## Values:
##
## utility cost
## standard 25982.24 678124.8
## np1 26231.16 656405.1
##
## Efficiency frontier:
##
## np1
##
## Differences:
##
## Cost Diff. Effect Diff. ICER Ref.
## np1 -21.71964 0.2489113 -87.25853 standard
Updating can be significantly sped up by using parallel computing. This can be done in the following way:
use_cluster()
functions (i.e. use_cluster(4)
to use 4 cores).close_cluster()
function.Results may vary depending on the machine, but we found speed gains to be quite limited beyond 4 cores.