--- title: "Longitudinal Models in missingHE" description: > This tutorial shows few examples of how longitudinal models in missingHE can be specified and customised in different ways according to the specific needs of the user when performing trial-based CEA. output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Longitudinal Models in missingHE} %\VignetteEngine{knitr::rmarkdown} \usepackage[utf8]{inputenc} --- ```{r, echo = FALSE, message = FALSE} knitr::opts_chunk$set(prompt = TRUE, highlight = F, background = '#FFFFFF', collapse = T, comment = "#>") library(missingHE) set.seed(1234) ``` Currently, only **longitudinal selection** models can be fitted using `missingHE`, for which the package provides a series of customisation options to allow a flexible specification of the models in terms of modelling assumptions and prior choices. These can be extremely useful for handling the typical features of trial-based CEA data, such as non-normality, clustering, and type of missingness mechanism. This tutorial shows how it is possible to customise different aspects of longitudinal models using the arguments of each type of function in the package. Throughout, we will use the built-in dataset called `PBS` as a toy example, which is directly available when installing and loading `missingHE` in your `R` workspace. See the vignette called *Introduction to missingHE* for an introductory tutorial of each function in `missingHE` and a general presentation of the data used in trial-based economics evaluations. If you would like to have more information on the package, or would like to point out potential issues in the current version, feel free to contact the maintainer at . Suggestions on how to improve the package are also very welcome. ## Changing the distributional assumptions A general concern when analysing trial-based CEA data is that, in many cases, both effectiveness and costs are characterised by highly skewed distributions, which may cause standard normality modelling assumptions to be difficult to justify, especially for small samples. `missingHE` allows to chose among a range of parametric distributions for modelling both outcome variables, which were selected based on the most common choices in standard practice and the literature. In the context of a trial-based analysis, health economic outcomes are typically collected at baseline and a series of follow-up time points. Traditionally, the analysis is conducted at the aggregate level using cross-sectional effectiveness and cost outcomes obtained by combining the outcomes collected at different times as this considerably simplify the analysis task which does not require a longitudinal model specification. However, such an approach can be justified only when very limited missing outcome values occur throughout the time period of the study. When this is not true, then focussing at the aggregate level may considerably hinder the validity and reliability of the results in terms of either bias or efficiency. To deal with this problem, then a longitudinal model specification is reuiquired which allows to make full use of all observed outcome values collected in the trial while also being able to specify different missingness assumptions based on the different missingness patterns observed across the trial period. Different approaches are available for modelling longitudinal or repeated measurement binary outcomes under different missingness assumptions, such as longitudinal selection models, which are implemented in `missingHE` together with a series of customisation options in terms of model specification. Within the model, the specific type of distributions for the effectiveness or utility ($u$) and cost ($c$) outcome at each time point of the analysis can be selected by setting the arguments `dist_u` and `dist_c` to specific character names. Available choices include: Normal (`"norm"`) and Beta (`"beta"`) distributions for $u$ and Normal (`"norm"`) and Gamma (`"gamma"`) for $c$. Distributions for modelling both discrete and binary effectiveness variables are also available, such as Poisson (`"pois"`) and Bernoulli (`bern`) distributions. The full list of available distributions for each type of outcome can be seen by using the `help` function on each function of the package. In the `PBS` dataset the longitudinal health economic variables are the utilities (from EQ5D-3L questionnaires) and costs (from clinic records) collected at baseline (time = 1) and two follow-up times (6 months, time = 2; and 12 months, time = 3). To have an idea of what the data look like, we can inspect the first entries for each variable at a specific time (e.g. `time` = 1) by typing ```{r pbs_data, eval=TRUE, echo=TRUE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} #first 10 entries of u and c at time 1 head(PBS$u[PBS$time == 1], n = 10) head(PBS$c[PBS$time == 1], n = 10) ``` We can check the empirical histograms of the data at different times, for example $u$ at time $1$ and $2$ by treatment group by typing ```{r hist_u, eval=TRUE, echo=TRUE, comment=NA,warning=FALSE,error=FALSE,message=FALSE, fig.width=15,fig.height=9,out.width='65%',fig.align='center'} par(mfrow=c(2, 2)) hist(PBS$u[PBS$t==1 & PBS$time == 1], main = "Utility at time 1 - Control") hist(PBS$u[PBS$t==2 & PBS$time == 1], main = "Utility at time 1 - Intervention") hist(PBS$u[PBS$t==1 & PBS$time == 2], main = "Utility at time 2 - Control") hist(PBS$u[PBS$t==2 & PBS$time == 2], main = "Utility at time 2 - Intervention") ``` We can also see that the proportion of missing values in $u$ at each time is moderate in both treatment groups. ```{r mv, eval=TRUE, echo=TRUE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} #proportions of missing values in the control group sum(is.na(PBS$u[PBS$t==1 & PBS$time == 1])) / length(PBS$u[PBS$t==1 & PBS$time == 1]) sum(is.na(PBS$u[PBS$t==1 & PBS$time == 2])) / length(PBS$u[PBS$t==1 & PBS$time == 2]) sum(is.na(PBS$u[PBS$t==1 & PBS$time == 3])) / length(PBS$u[PBS$t==1 & PBS$time == 3]) #proportions of missing values in the intervention group sum(is.na(PBS$u[PBS$t==2 & PBS$time == 1])) / length(PBS$u[PBS$t==2 & PBS$time == 1]) sum(is.na(PBS$u[PBS$t==2 & PBS$time == 2])) / length(PBS$u[PBS$t==2 & PBS$time == 2]) sum(is.na(PBS$u[PBS$t==2 & PBS$time == 3])) / length(PBS$u[PBS$t==2 & PBS$time == 3]) ``` As an example, we fit a longitudinal selection model assuming Normal distributions to handle $u$, and we choose Gamma distributions to capture the skewness in the costs. We note that, in case some of individuals have costs that are equal to zero (as in the `PBS` dataset), standard parametric distributions with a positive support are not typically defined at $0$ (e.g. the Gamma distributions), making their implementation impossible. Thus, in these cases, it is necessary to use a trick to modify the boundary values before fitting the model. A common approach is to add a small constant to the cost variables. These can be done by typing ```{r costs_const, eval=TRUE, echo=TRUE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} PBS$c <- PBS$c + 0.01 ``` We note that, although simple, this strategy has the potential drawback that results may be affected by the choice of the constant added and therefore sensitivity analysis to the value used is typically recommended. We are now ready to fit our longitudinal selection model to the `PBS` dataset using the following command ```{r selection1_no, eval=TRUE, echo=FALSE, include=FALSE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} NN.sel=selection_long(data = PBS, model.eff = u ~ 1, model.cost = c ~ u, model.mu = mu ~ gender, model.mc = mc ~ gender, type = "MAR", n.iter = 500, dist_u = "norm", dist_c = "norm", time_dep = "none") ``` ```{r selection1, eval=FALSE, echo=TRUE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} NN.sel=selection_long(data = PBS, model.eff = u ~ 1, model.cost = c ~ u, model.mu = mu ~ gender, model.mc = mc ~ gender, type = "MAR", n.iter = 500, dist_u = "norm", dist_c = "norm", time_dep = "none") ``` The arguments `dist_u = "norm"` and `dist_c = "norm"` specify the distributions assumed for the outcome variables and, in the model of $c$, we also take into account the possible association between the two outcomes at each time by uncluding the utility as a covariate (`u`). According to the type of distributions chosen, `missingHE` automatically models the dependence between covariates and the mean outcome on a specific scale to reduce the chance of incurring into numerical problems due to the constraints of the distributions. For example, for both Poisson and Gamma distributions means are modelled on the log scale, while for Beta and Bernoulli distirbutions they are modelled on the logit scale. To see the modelling scale used by `missingHE` according to the type of distribution selected, use the `help` command on each function of the package. The optional argument `time_dep` allows to specify the type of time dependence structure assumed by the model, here corresponding to no temporal dependence (`"none"`). An alternative choice available in `missingHE` is to set `time_dep = "AR1"`, which assumes an autoregressive of order one time structure. The model assumes MAR conditional on `gender` as auxiliary variable for predicting missingness in both outcomes. We can look at how the model generate imputations for the outcomes by treatment group using the generic function `plot`. For example, we can look at how the missing $u$ at time $3$ are imputed by typing ```{r plot_selection1, eval=TRUE, echo=TRUE, comment=NA,warning=FALSE,error=FALSE,message=FALSE, fig.width=15,fig.height=9,out.width='65%',fig.align='center'} plot(NN.sel, outcome = "effects", time_plot = 3) ``` Summary results of our model from a statistical perspective can be inspected using the command `coef`, which extracts the estimates of the mean regression coefficients for $u$ and $c$ by treatment group and time point. By default, the lower and upper bounds provide the $95\%$ credibile intervals for each estimate (based on the $0.025$ and $0.975$ quantiles of the posterior distribution). For example, we can inspect the coefficients in the utility and cost models at time $2$ by typing ```{r coef_selection1, eval=TRUE, echo=TRUE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} coef(NN.sel, time = 2) ``` The entire posterior distribution for each parameter of the model can also be extracted from the output of the model by typing `NN.sel$model_output`, which returns a list object containing the posterior estimates for each model parameter. An overall summary of the economic analysis based on the model estimates can be obtained using the `summary` command ```{r summary_selection1, eval=TRUE, echo=TRUE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} summary(NN.sel) ``` which shows summary statistics for the mean effectiveness and costs in each treatment group, for the mean differentials and the estimate of the ICER. It is important to clarify how these results are obtained in that they pertain summary statistics for aggregated health economic outcomes (e.g. QALYs and Total costs) which are retrieved by combining the posterior results from the longitudinal model for each type of outcome and time point of the analysis. More specifically, the function `selection_long`, after deriving the posterior results from the model, applies common CEA techniques for computing aggregate variables based on the posterior mean results of the effectiveness and cost variables at each time point of the analysis. These include: Area Under the Curve approach for $u$ and total sum over the follow-up period for $c$. By default, `missingHE` assumes a value of $0.5$ and $1$ for the weights used to respectively calculate the aggregate mean QALYs and Total costs over the time period of the study. When desired, users can provide their own weights as additional argument named `qaly_calc` and `tcost_calc` that can be passed into the function `selection_long` when fitting the model. ## Including random effects terms For each type of model, `missingHE` allows the inclusion of random effects terms to handle clustered data. To be precise, the term *random effects* does not have much meaning within a Bayesian approach since all parameters are in fact random variables. However, this terminology is quite useful to explain the structure of the model. We show how random effects can be added to the model of $u$ and $c$ within a longitudinal selection model fitted to the `PBS` dataset using the function `selection_long`. The clustering variable over which the random effects are specified is the factor variable `site`, representing the centres at which data were collected in the trial. Using the same distributional assumptions of the selection model, we fit the pattern mixture model by typing ```{r sl1_no, eval=TRUE, echo=FALSE, include=FALSE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} PBS$site <- factor(PBS$site) NN.re=selection_long(data = PBS, model.eff = u ~ 1 + (1 | site), model.cost = c ~ u + (1 | site), model.mu = mu ~ gender, model.mc = mc ~ gender, type = "MAR", n.iter = 500, dist_u = "norm", dist_c = "norm", time_dep = "none") ``` ```{r pattern1, eval=FALSE, echo=TRUE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} PBS$site <- factor(PBS$site) NN.re=selection_long(data = PBS, model.eff = u ~ 1 + (1 | site), model.cost = c ~ u + (1 | site), model.mu = mu ~ gender, model.mc = mc ~ gender, type = "MAR", n.iter = 500, dist_u = "norm", dist_c = "norm", time_dep = "none") ``` The function fits a random intercept only model for $u$ and $c$, as indicated by the notation `(1 | site)`and `(1 | site)`. In both models, `site` is the clustering variable over which the random coefficients are estimated. `missingHE` allows the user to choose among different clustering variables for the model of $u$ and $c$ if these are available in the dataset. Random intercept and slope models can be specified using the notation `(1 + gender | site)`, where `gender` is the name of a covariate which should be inlcuded as fixed effects in the corresponding outcome model. Finally, it is also possible to specify random slope only models using the notation `(0 + gender | site)`, where `0` indicates the removal of the random intercept. Coefficient estimates for the random effects at each time can be extracted using the `coef` function and setting the argument `random = TRUE` (if set to `FALSE` then the fixed effects estimates are displayed). ```{r coef_sl1, eval=TRUE, echo=TRUE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} coef(NN.re, time = 3, random = TRUE) ``` For both $u$ and $c$ models, summary statistics for the random coefficient estimates are displayed for each treatment group and each of the clusters in `site`. ## Changing the priors By default, all models in `missingHE` are fitted using vague prior distributions so that posterior results are essentially derived based on the information from the observed data alone. This ensures a rough approximation to results obtained under a frequentist approach based on the same type of models. However, in some cases, it may be reasonable to use more informative priors to ensure a better stability of the posterior estimates by restricting the range over which estimates can be obtained. For example if, based on previous evidence or knowledge, the range over which a specific parameter is likely to vary is known, then priors can be specified so to give less weight to values outside that range when deriving the posterior estimates. However, unless the user is familiar with the choice of informative priors, it is generally recommended not to change the default priors of `missingHE` as the unintended use of informative priors may substantially drive posterior estimates and lead to incorrect results. For each type of model in `missingHE`, priors can be modified using the argument `prior`, which allows to change the hyperprior values for each model parameter. The interpretation of the prior values change according to the type of parameter and model considered. For example, we can fit a longitudinal selection model to the `PBS` dataset using more informative priors on some parameters. Prior values can be modified by first creating a list object which, for example, we call `my.prior`. Within this list, we create a number of elements (vectors of length two) which should be assigned specific names based on the type of parameters which priors we want to change. ```{r prior_sl1, eval=TRUE, echo=TRUE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} my.prior <- list( "alpha0.prior" = c(0 , 0.0000001), "beta0.prior" = c(0, 0.0000001), "gamma0.prior.c"= c(0, 1), "gamma.prior.c" = c(0, 0.01), "sigma.prior.c" = c(0, 100) ) ``` The names above have the following interpretations in terms of the model parameters: * `"alpha0.prior"` is the intercept of the model of $u$. The first and second elements inside the vector for this parameter are the mean and precision (inverse of variance) that should be used for the normal prior given to this parameter by `missingHE`. * `"beta0.prior"` is the intercept of the model of $c$. The first and second elements inside the vector for this parameter are the mean and precision (inverse of variance) that should be used for the normal prior given to this parameter by `missingHE`. * `"gamma0.prior.c"` is the intercept of the model of $mc$. The first and second elements inside the vector for this parameter are the mean and precision (inverse of variance) that should be used for the logistic prior given to this parameter by `missingHE`. * `"gamma.prior.c"` are the regression coefficients (exclusing the intercept) of the model of $mc$. The first and second elements inside the vector for this parameter are the mean and precision (inverse of variance) that should be used for the normal priors given to each coefficient by `missingHE`. * `"sigma.prior.c"` is the standard deviation of the model of $c$. The first and second elements inside the vector for this parameter are the lower and upper bounds that should be used for the uniform prior given to this parameter by `missingHE`. The values shown above are the default values set in `missingHE` for each of these parameters. It is possible to change the priors by providing different values, for example by increasing the precision for some of the coefficient estimates or decreasing the upper bound for standard deviation parameters. Different names should be used to indicate for which parameter the prior should be modified, keeping in mind that the full list of names that can be used varies depending on the type of models and modelling assumptions specified. The full list of parameter names for each type of model can be assessed using the `help`command on each function of `missingHE`. We can now fit the hurdle model using our priors by typing ```{r sl12_no, eval=TRUE, echo=FALSE, include=FALSE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} NN.prior=selection_long(data = PBS, model.eff = u ~ 1 + (1 | site), model.cost = c ~ u + (1 | site), model.mu = mu ~ gender, model.mc = mc ~ gender, type = "MAR", n.iter = 500, dist_u = "norm", dist_c = "norm", time_dep = "none", prior = my.prior) ``` ```{r sl12, eval=FALSE, echo=TRUE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} NN.prior=selection_long(data = PBS, model.eff = u ~ 1 + (1 | site), model.cost = c ~ u + (1 | site), model.mu = mu ~ gender, model.mc = mc ~ gender, type = "MAR", n.iter = 500, dist_u = "norm", dist_c = "norm", time_dep = "none", prior = my.prior) ``` Finally, we can inspect the statistical results from the model at time $3$ by typing ```{r coef_sl12, eval=TRUE, echo=TRUE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} coef(NN.prior, random = FALSE, time = 3) ``` and ```{r summary_sl12, eval=TRUE, echo=TRUE, comment=NA,warning=FALSE,error=FALSE,message=FALSE} coef(NN.prior, random = TRUE, time = 3) ```