psc-vignette

Richard Jackson

2024-12-12

Introduction

The psc.R package implements the methods for applying Personalised Synthetic Controls, which allows for patients receiving some experimental treatment to be compared against a model which predicts their reponse to some control. This is a form of causal inference which differes from other approaches in that

Data are only required on a single treatment - all counterfactual evidence is supplied by a parametric model

Causal inference, in theory at least, is estimated at a patient level - as opposed to estimating average effects over a population

The causal estimand obtained is the Average Treatment Effect of the Treated (ATT) which differs from the Average Treatment Effect (ATE) obtained in other settings and addresses the question of whether treatments are effective in the population of patients who are treated. This estimand then targets efficacy over effectivness.

In its basic form, this method creates a likelihood to compare a cohort of data to a parametric model. See (X) for disucssion on it’s use as a causal inference tool. To use this package, two basic peices of information are required, a dataset and a model against which they can be compared.

In this vignette, we will detail how the psc.r package is constructed and give some examples for it’s application in practice.

Methodology

The pscfit function compares a dataset (‘DC’) against a parametric model. This is done by selecting a likelihood which is identified by the type of CFM that is supplied. At present, two types of model are supported, a flexible parmaeteric survival model of type ‘flexsurvreg’ and a geleneralised linear model of type ‘glm’.

Where the CFM is of type ‘flexsurvreg’ the likeihood supplied is of the form:

\[L(D∣\Lambda,\Gamma_i)=\prod_{i=1}^{n} f(t_i∣\Lambda,\Gamma_i)^{c_i} S(t_i∣\Gamma,\Lambda_i)^{(1−c_i)}\]

Where \(\Gamma\) defines the cumulative baseline hazard function, \(\Lambda\) is the linear predictor and \(t\) and \(c\) are the event time and indicator variables.

Where the CFM is of the type ‘glm’ the likelihood supplied is of the form:

\[L(x∣\Gamma_i) = \prod_{i=1}^{n} b (x∣ \Gamma_i )\exp\{\Gamma_i t(x)− c(\Gamma_i)\}\]

Where \(b(.)\), \(t(.)\) and \(c(.)\) represent the functions of the exponential family. In both cases, \(\Gamma\) is defiend as:

\[ \Gamma_i = \gamma x_i+\beta \]

Where \(\gamma\) are the model coefficients supplied by the CFM and \(\beta\) is the parameter set to measure the difference between the CFM and the DC.

Estimation is performed using a Bayesian MCMC procedure. Prior distributions for \(\Gamma\) (& \(\Lambda\)) are derived directly from the model coefficients (mean and variance covariance matrix) or the CFM. A bespoke MCMC routine is performed to estimate \(\beta\). Please see ‘?mcmc’ for more detials.

For the standard example where the DC contains information from only a single treatment, trt need not be specified. Where comparisons between the CFM and multiple treatments are require, a covariate of treamtne allocations must be specified sperately (using the ‘trt’ option).

Package Structure

The main function for using applying Personal Synthetic Controls is the pscfit() function which has two inputs, a Counter-Factual Model (CFM) and a data cohort (DC). Further arguments include

psc object

The output of the “pscfit()” function is an object of class ‘psc’. This class contains the following attributes

Postestimation functions

basic post estimation functions have been developed to work with the psc object, namely “print()”, “coef()”, “summary()” and “plot()”. For the first three of these these provided basic summaries of the efficacy parameter obtained from the posterior distribution.

Motivating Example

The psc.r package includes as example, a dataset which is derived from patients with advanced Hepatocellular Carcinoma (aHCC) who have all received some experimental treatment. The dataset is simply named ‘data’ and is loaded into the enviroment using the “data()” function

#install.packages("psc")
library(psc)

Included is a list of prognostic covariates:

Also included are the following structures

Lastly the dataset also inlclude a ‘trt’ variable to be used in the estimation of multiple treatment comparisons.

We give esamples of how the ‘pscfit()’ function can be used to comapre data against models with survival outcomes (with a ‘flexsurvreg’ model) along with binary, continuous and count outcomes (with a ‘glm’ model).

Survival Example

For an example with a survival outcome a model must be supplied which is contructed ont he basis of flexible parametric splines. This is contructed using the “flexsurvreg” function within the “flexsurv” package. An example is included within the ‘psc.r’ package names ‘surv.mod’ and is loaded using the ’data()” function:

surv.mod <- psc::surv.mod
surv.mod
#> Call:
#> flexsurvspline(formula = Surv(time, cen) ~ vi/age60 + ecog + 
#>     allmets + logafp + alb + logcreat + logast + aet, data = pros, 
#>     k = 3)
#> 
#> Estimates: 
#>              data mean  est       L95%      U95%      se        exp(est)
#> gamma0             NA   -7.57573  -9.90310  -5.24836   1.18746        NA
#> gamma1             NA    2.23506   1.37951   3.09060   0.43651        NA
#> gamma2             NA   -0.13758  -0.74322   0.46807   0.30901        NA
#> gamma3             NA    0.26981  -0.72101   1.26063   0.50553        NA
#> gamma4             NA   -0.03031  -0.60738   0.54676   0.29443        NA
#> viyes         0.28400    0.32856   0.08489   0.57224   0.12433   1.38897
#> ecog1         0.40400    0.45602   0.23429   0.67776   0.11313   1.57779
#> allmetsyes    0.69400    0.29767   0.03666   0.55869   0.13317   1.34672
#> logafp        5.42436    0.08320   0.05038   0.11602   0.01674   1.08676
#> alb          38.55600   -0.05539  -0.07809  -0.03269   0.01158   0.94612
#> logcreat      4.30929    0.71084   0.26457   1.15712   0.22770   2.03571
#> logast        4.08274    0.35000   0.15915   0.54086   0.09738   1.41907
#> aetHCV        0.21200   -0.52754  -0.86299  -0.19210   0.17115   0.59005
#> aetOther      0.37000   -0.01847  -0.26319   0.22624   0.12486   0.98170
#> vino:age60    0.06400   -0.02312  -0.03479  -0.01144   0.00596   0.97715
#> viyes:age60  -0.37000    0.00716  -0.00790   0.02221   0.00768   1.00718
#>              L95%      U95%    
#> gamma0             NA        NA
#> gamma1             NA        NA
#> gamma2             NA        NA
#> gamma3             NA        NA
#> gamma4             NA        NA
#> viyes         1.08859   1.77223
#> ecog1         1.26401   1.96946
#> allmetsyes    1.03734   1.74838
#> logafp        1.05167   1.12301
#> alb           0.92488   0.96784
#> logcreat      1.30286   3.18076
#> logast        1.17251   1.71748
#> aetHCV        0.42190   0.82523
#> aetOther      0.76860   1.25388
#> vino:age60    0.96581   0.98862
#> viyes:age60   0.99214   1.02246
#> 
#> N = 500,  Events: 360,  Censored: 140
#> Total time at risk: 5357.664
#> Log-likelihood = -1221.857, df = 16
#> AIC = 2475.714

In this example you can see that this is a model constructed with 3 internal knots and hence 5 parameters to describe the baseline cumulative hazard function. There are also prognostic covariates which match with the prognostic covaraites in the data cohort.

To begin it is worth looking at the performance of the model and looking at how the survival of patietns in the data cohort compare

library(survival)
sfit <- survfit(Surv(data$time,data$cen)~1)
plot(sfit)

Comparing the dataset to the model is then performed using

and we can view the attributes of the psc object that is created

attributes(surv.psc)
#> $names
#> [1] "model.type" "DC_clean"   "posterior" 
#> 
#> $class
#> [1] "psc"

For example to view the matrix contianing the draws of the posterior distribution we use

surv.post <- surv.psc$posterior
head(surv.post)
#>      gamma0   gamma1      gamma2     gamma3      gamma4     viyes     ecog1
#> 1 -7.575727 2.235057 -0.13757629  0.2698109 -0.03030718 0.3285628 0.4560236
#> 2 -8.083101 3.108805  0.41214482 -0.5013842  0.28906542 0.4838305 0.3713977
#> 3 -6.194511 2.140238 -0.28739460  0.6719491 -0.37892653 0.2839667 0.4858647
#> 4 -7.539431 2.514414 -0.09007151  0.1423531  0.10571401 0.3612867 0.4690602
#> 5 -6.688673 1.775090 -0.41585269  0.6918287 -0.23798068 0.3831859 0.4926607
#> 6 -6.439526 1.446424 -0.33290728  0.2524421  0.20770347 0.3955534 0.3328143
#>   allmetsyes     logafp         alb  logcreat    logast     aetHCV    aetOther
#> 1  0.2976742 0.08319787 -0.05538982 0.7108430 0.3500019 -0.5275438 -0.01847276
#> 2  0.4204654 0.04677723 -0.04917988 0.7279542 0.2881769 -0.3818822  0.23665087
#> 3  0.2776556 0.11104996 -0.06978485 0.7158020 0.1194431 -0.4543704  0.15804840
#> 4  0.4328648 0.09776478 -0.06216840 0.7499618 0.2408156 -0.6098731 -0.23347437
#> 5  0.4184793 0.09304649 -0.04817961 0.4905665 0.3573751 -0.7049344 -0.26229836
#> 6  0.1940646 0.06560264 -0.06172736 0.4767710 0.5256756 -0.6914386 -0.08859557
#>     vino:age60 viyes:age60      beta      DIC
#> 1 -0.023118234 0.007156047 0.3784481       NA
#> 2 -0.020671657 0.012730200 0.3784481 279.6369
#> 3 -0.019461133 0.012479046 0.3784481 282.3721
#> 4 -0.027814378 0.014678515 0.3784481 279.8192
#> 5 -0.005766094 0.014534143 0.3784481 282.8341
#> 6 -0.017292094 0.018954283 0.3784481 282.1882

Inspection will show that there is a column for each parameter in the original model as well as ‘beta’ and ‘DIC’ vcolumns which give teh posterior estiamtes for \(\beta\) and the Deviance Informaiton Criterion respectively.

We can inspect the poterior distribution using the autocorrelation function, trace and stardard summary statistics:

Autocorrelation

acf(surv.post$beta)

Trace

plot(surv.post$beta,typ="s")

Summary

summary(surv.post$beta)
#>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#> -0.1615  0.2685  0.3696  0.3574  0.4469  0.8630

Standard ‘summary()’ function wil summarise the model fit

summary(surv.psc)
#> Summary: 
#>  
#> 100 observations selected from the data cohort for comparison 
#> CFM of type flexsurvreg identified  
#> linear predictor succesfully obtained with median: 
#>  trt: 3.15
#> Average expected response: 
#>  trt: 9.1
#> Average observed response: 6.366 
#> 
#> Counterfactual Model (CFM): 
#> A model of class 'flexsurvreg' 
#>  Fit with 3 internal knots
#> 
#> Formula: 
#> Surv(time, cen) ~ vi/age60 + ecog + allmets + logafp + alb + 
#>     logcreat + logast + aet
#> <environment: 0x11caca5f8>
#> 
#> Call:
#>  CFM model + beta
#> 
#> Coefficients:
#>       median     2.5%       97.5%      Pr(x<0)    Pr(x>0)  
#> beta    0.36956    0.07735    0.60069    0.00440    0.99560
#> DIC   281.07341  273.70334  292.95175         NA         NA

To visualise the original model and the fit of the data, the plot function has been developed

plot(surv.psc)

GLM

The “pscfit()” object uses class of the model supplied to derive the likelihoiod and estimation procedure that isde required. In this example, the “enrichwith” package is utilised to extract from the model the parameters of the exponential family. Important from the attributes of the GLM are the “family” statements which dictates the form of the likelihood. For each of the binary, continuous and Count data outcomes then, the syntax and the DC remains the same and it is the form of the CFM that dictates the analysis

Binary

Step 1: Load Model

bin.mod <- psc::bin.mod
bin.mod
#> 
#> Call:  glm(formula = event ~ vi/age60 + ecog + allmets + logafp + alb + 
#>     logcreat, family = "binomial", data = pros)
#> 
#> Coefficients:
#> (Intercept)        viyes        ecog1   allmetsyes       logafp          alb  
#>    -1.65694      0.80007      0.38279      0.40733      0.12941     -0.04993  
#>    logcreat   vino:age60  viyes:age60  
#>     0.76346     -0.01901      0.01380  
#> 
#> Degrees of Freedom: 570 Total (i.e. Null);  562 Residual
#>   (17 observations deleted due to missingness)
#> Null Deviance:       683 
#> Residual Deviance: 616   AIC: 634

Step 2: Fit psc object

Step 3: Review summary statistics

summary(psc.bin)
#> Summary: 
#>  
#> 100 observations selected from the data cohort for comparison 
#> CFM of type glm lm identified  
#> linear predictor succesfully obtained with median: 
#>  trt: 1.2
#> Average expected response: 
#>  trt: 0.769
#> Average observed response: 0.48 
#> 
#> Counterfactual Model (CFM): 
#> A model of class 'GLM' 
#>  Family: binomial 
#>  Link: logit 
#> 
#> Formula: 
#> event ~ vi/age60 + ecog + allmets + logafp + alb + logcreat
#> 
#> Call:
#>  CFM model + beta
#> 
#> Coefficients:
#>       median   2.5%     97.5%    Pr(x<0)  Pr(x>0)
#> beta  -1.2000  -1.6780  -0.7027   1.0000   0.0000
#> DIC   56.8259  52.7827  64.9417       NA       NA

Step 4: Plot Output

plot(psc.bin)

Count

Step 1: Load Model

count.mod <- psc::count.mod
count.mod
#> 
#> Call:  glm(formula = count ~ ecog + logafp + alb + logcreat, family = "poisson", 
#>     data = data)
#> 
#> Coefficients:
#> (Intercept)         ecog       logafp          alb     logcreat  
#>    1.414244    -0.170884     0.017803    -0.007255    -0.056183  
#> 
#> Degrees of Freedom: 99 Total (i.e. Null);  95 Residual
#> Null Deviance:       127.2 
#> Residual Deviance: 125.1     AIC: 382.1
#data("count.mod")

Step 2: Fit psc object

Step 3: Review summary statistics

summary(psc.count)
#> Summary: 
#>  
#> 100 observations selected from the data cohort for comparison 
#> CFM of type glm lm identified  
#> linear predictor succesfully obtained with median: 
#>  trt: 0.919
#> Average expected response: 
#>  trt: 2.507
#> Average observed response: 2.49 
#> 
#> Counterfactual Model (CFM): 
#> A model of class 'GLM' 
#>  Family: poisson 
#>  Link: log 
#> 
#> Formula: 
#> count ~ ecog + logafp + alb + logcreat
#> 
#> Call:
#>  CFM model + beta
#> 
#> Coefficients:
#>       median     2.5%       97.5%      Pr(x<0)    Pr(x>0)  
#> beta  -0.005526  -0.203844   0.202975   0.517400   0.482600
#> DIC   14.419682  10.220040  25.768835         NA         NA

Step 4: Plot Output

plot(psc.count)

Continuous

Step 1: Load Model

cont.mod <- psc::cont.mod
cont.mod
#> 
#> Call:  glm(formula = os ~ vi/age60 + ecog + allmets + logafp + alb, 
#>     data = pros)
#> 
#> Coefficients:
#> (Intercept)        viyes        ecog1   allmetsyes       logafp          alb  
#>     2.16581     -2.57037     -2.97107     -2.13909     -0.37175      0.36754  
#>  vino:age60  viyes:age60  
#>     0.09174      0.02106  
#> 
#> Degrees of Freedom: 570 Total (i.e. Null);  563 Residual
#>   (17 observations deleted due to missingness)
#> Null Deviance:       33570 
#> Residual Deviance: 25300     AIC: 3803

Step 2: Fit psc object

Step 3: Review summary statistics

summary(psc.con)
#> Summary: 
#>  
#> 100 observations selected from the data cohort for comparison 
#> CFM of type glm lm identified  
#> linear predictor succesfully obtained with median: 
#>  trt: 10.8
#> Average expected response: 
#>  trt: 10.8
#> Average observed response: 10.743 
#> 
#> Counterfactual Model (CFM): 
#> A model of class 'GLM' 
#>  Family: gaussian 
#>  Link: identity 
#> 
#> Formula: 
#> os ~ vi/age60 + ecog + allmets + logafp + alb
#> 
#> Call:
#>  CFM model + beta
#> 
#> Coefficients:
#>       median      2.5%        97.5%       Pr(x<0)     Pr(x>0)   
#> beta      0.1194     -0.6755      0.9145      0.3438      0.6562
#> DIC   -6797.1911  -6893.5372  -6665.1962          NA          NA

Step 4: Plot Output

plot(psc.con)

Sub group Effects

An attractive feature of Personalised Synthetic Controls is its use in fitting sub-group effects. Whereas other casual inference tools typically make ssumptions about population levels of balance and then further assume that this balance holds at sub-group levels, Personalised Synthetic Controls differ in that they estimate treatment effects at a patient level and then average across populations. To estimate sub-group effects then we need only to restrict estimation over some sub-group of the population. This can be achived by directly slecting the subgroup you wish to evaluate

Using an example where we wnat to see if the treatment effect is consistent by patients with ECOG=0 and ECOG =1

Sub group effects by restricting the population

PSC fit for pateitns with ECOG=0

id1 <- which(data$ecog==0)
sub1 <- pscfit(surv.mod,data,id=id1)
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |                                                                      |   1%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |==                                                                    |   4%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   6%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |=====                                                                 |   8%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |=======                                                               |   9%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |=======                                                               |  11%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |=========                                                             |  14%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |===========                                                           |  15%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  16%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |============                                                          |  18%
  |                                                                            
  |=============                                                         |  18%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |==============                                                        |  19%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |==============                                                        |  21%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |===============                                                       |  22%
  |                                                                            
  |================                                                      |  22%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |================                                                      |  24%
  |                                                                            
  |=================                                                     |  24%
  |                                                                            
  |=================                                                     |  25%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |==================                                                    |  26%
  |                                                                            
  |===================                                                   |  26%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |===================                                                   |  28%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  29%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |=====================                                                 |  31%
  |                                                                            
  |======================                                                |  31%
  |                                                                            
  |======================                                                |  32%
  |                                                                            
  |=======================                                               |  32%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |=======================                                               |  34%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |========================                                              |  35%
  |                                                                            
  |=========================                                             |  35%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |==========================                                            |  36%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |==========================                                            |  38%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |===========================                                           |  39%
  |                                                                            
  |============================                                          |  39%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |============================                                          |  41%
  |                                                                            
  |=============================                                         |  41%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |==============================                                        |  42%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |==============================                                        |  44%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |=================================                                     |  46%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |=================================                                     |  48%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |==================================                                    |  49%
  |                                                                            
  |===================================                                   |  49%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |===================================                                   |  51%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |====================================                                  |  52%
  |                                                                            
  |=====================================                                 |  52%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |=====================================                                 |  54%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |=======================================                               |  55%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |========================================                              |  56%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |========================================                              |  58%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==========================================                            |  59%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |==========================================                            |  61%
  |                                                                            
  |===========================================                           |  61%
  |                                                                            
  |===========================================                           |  62%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |============================================                          |  63%
  |                                                                            
  |============================================                          |  64%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |=============================================                         |  65%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |===============================================                       |  66%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |===============================================                       |  68%
  |                                                                            
  |================================================                      |  68%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |=================================================                     |  71%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |===================================================                   |  72%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |===================================================                   |  74%
  |                                                                            
  |====================================================                  |  74%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |=====================================================                 |  75%
  |                                                                            
  |=====================================================                 |  76%
  |                                                                            
  |======================================================                |  76%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |======================================================                |  78%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |=======================================================               |  79%
  |                                                                            
  |========================================================              |  79%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |========================================================              |  81%
  |                                                                            
  |=========================================================             |  81%
  |                                                                            
  |=========================================================             |  82%
  |                                                                            
  |==========================================================            |  82%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |==========================================================            |  84%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |===========================================================           |  85%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  86%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |==============================================================        |  88%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |===============================================================       |  89%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |===============================================================       |  91%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |=================================================================     |  92%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |=================================================================     |  94%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |===================================================================   |  95%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |====================================================================  |  96%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |====================================================================  |  98%
  |                                                                            
  |===================================================================== |  98%
  |                                                                            
  |===================================================================== |  99%
  |                                                                            
  |======================================================================|  99%
  |                                                                            
  |======================================================================| 100%

PSC fit for pateitns with ECOG=1

id2 <- which(data$ecog==1)
sub2 <- pscfit(surv.mod,data,id=id2)
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |                                                                      |   1%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |==                                                                    |   4%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   6%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |=====                                                                 |   8%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |=======                                                               |   9%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |=======                                                               |  11%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |=========                                                             |  14%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |===========                                                           |  15%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  16%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |============                                                          |  18%
  |                                                                            
  |=============                                                         |  18%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |==============                                                        |  19%
  |                                                                            
  |==============                                                        |  20%
  |                                                                            
  |==============                                                        |  21%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |===============                                                       |  22%
  |                                                                            
  |================                                                      |  22%
  |                                                                            
  |================                                                      |  23%
  |                                                                            
  |================                                                      |  24%
  |                                                                            
  |=================                                                     |  24%
  |                                                                            
  |=================                                                     |  25%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |==================                                                    |  26%
  |                                                                            
  |===================                                                   |  26%
  |                                                                            
  |===================                                                   |  27%
  |                                                                            
  |===================                                                   |  28%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=====================                                                 |  29%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |=====================                                                 |  31%
  |                                                                            
  |======================                                                |  31%
  |                                                                            
  |======================                                                |  32%
  |                                                                            
  |=======================                                               |  32%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |=======================                                               |  34%
  |                                                                            
  |========================                                              |  34%
  |                                                                            
  |========================                                              |  35%
  |                                                                            
  |=========================                                             |  35%
  |                                                                            
  |=========================                                             |  36%
  |                                                                            
  |==========================                                            |  36%
  |                                                                            
  |==========================                                            |  37%
  |                                                                            
  |==========================                                            |  38%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |===========================                                           |  39%
  |                                                                            
  |============================                                          |  39%
  |                                                                            
  |============================                                          |  40%
  |                                                                            
  |============================                                          |  41%
  |                                                                            
  |=============================                                         |  41%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |==============================                                        |  42%
  |                                                                            
  |==============================                                        |  43%
  |                                                                            
  |==============================                                        |  44%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |===============================                                       |  45%
  |                                                                            
  |================================                                      |  45%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |=================================                                     |  46%
  |                                                                            
  |=================================                                     |  47%
  |                                                                            
  |=================================                                     |  48%
  |                                                                            
  |==================================                                    |  48%
  |                                                                            
  |==================================                                    |  49%
  |                                                                            
  |===================================                                   |  49%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |===================================                                   |  51%
  |                                                                            
  |====================================                                  |  51%
  |                                                                            
  |====================================                                  |  52%
  |                                                                            
  |=====================================                                 |  52%
  |                                                                            
  |=====================================                                 |  53%
  |                                                                            
  |=====================================                                 |  54%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |======================================                                |  55%
  |                                                                            
  |=======================================                               |  55%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |========================================                              |  56%
  |                                                                            
  |========================================                              |  57%
  |                                                                            
  |========================================                              |  58%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |=========================================                             |  59%
  |                                                                            
  |==========================================                            |  59%
  |                                                                            
  |==========================================                            |  60%
  |                                                                            
  |==========================================                            |  61%
  |                                                                            
  |===========================================                           |  61%
  |                                                                            
  |===========================================                           |  62%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |============================================                          |  63%
  |                                                                            
  |============================================                          |  64%
  |                                                                            
  |=============================================                         |  64%
  |                                                                            
  |=============================================                         |  65%
  |                                                                            
  |==============================================                        |  65%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |===============================================                       |  66%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |===============================================                       |  68%
  |                                                                            
  |================================================                      |  68%
  |                                                                            
  |================================================                      |  69%
  |                                                                            
  |=================================================                     |  69%
  |                                                                            
  |=================================================                     |  70%
  |                                                                            
  |=================================================                     |  71%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |===================================================                   |  72%
  |                                                                            
  |===================================================                   |  73%
  |                                                                            
  |===================================================                   |  74%
  |                                                                            
  |====================================================                  |  74%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |=====================================================                 |  75%
  |                                                                            
  |=====================================================                 |  76%
  |                                                                            
  |======================================================                |  76%
  |                                                                            
  |======================================================                |  77%
  |                                                                            
  |======================================================                |  78%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |=======================================================               |  79%
  |                                                                            
  |========================================================              |  79%
  |                                                                            
  |========================================================              |  80%
  |                                                                            
  |========================================================              |  81%
  |                                                                            
  |=========================================================             |  81%
  |                                                                            
  |=========================================================             |  82%
  |                                                                            
  |==========================================================            |  82%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |==========================================================            |  84%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |===========================================================           |  85%
  |                                                                            
  |============================================================          |  85%
  |                                                                            
  |============================================================          |  86%
  |                                                                            
  |=============================================================         |  86%
  |                                                                            
  |=============================================================         |  87%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |==============================================================        |  88%
  |                                                                            
  |==============================================================        |  89%
  |                                                                            
  |===============================================================       |  89%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |===============================================================       |  91%
  |                                                                            
  |================================================================      |  91%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |=================================================================     |  92%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |=================================================================     |  94%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |===================================================================   |  95%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |====================================================================  |  96%
  |                                                                            
  |====================================================================  |  97%
  |                                                                            
  |====================================================================  |  98%
  |                                                                            
  |===================================================================== |  98%
  |                                                                            
  |===================================================================== |  99%
  |                                                                            
  |======================================================================|  99%
  |                                                                            
  |======================================================================| 100%

We can then easily compare the model coefficients

summary(sub1)
#> Summary: 
#>  
#> 53 observations selected from the data cohort for comparison 
#> CFM of type flexsurvreg identified  
#> linear predictor succesfully obtained with median: 
#>  trt: 2.84
#> Average expected response: 
#>  trt: 12.605
#> Average observed response: 8.135 
#> 
#> Counterfactual Model (CFM): 
#> A model of class 'flexsurvreg' 
#>  Fit with 3 internal knots
#> 
#> Formula: 
#> Surv(time, cen) ~ vi/age60 + ecog + allmets + logafp + alb + 
#>     logcreat + logast + aet
#> <environment: 0x12be8f900>
#> 
#> Call:
#>  CFM model + beta
#> 
#> Coefficients:
#>       median    2.5%      97.5%     Pr(x<0)   Pr(x>0) 
#> beta    0.2689   -0.0547    0.5780    0.0412    0.9588
#> DIC   150.6212  144.9799  159.8231        NA        NA
cat("\n")
summary(sub2)
#> Summary: 
#>  
#> 47 observations selected from the data cohort for comparison 
#> CFM of type flexsurvreg identified  
#> linear predictor succesfully obtained with median: 
#>  trt: 3.423
#> Average expected response: 
#>  trt: 8.099
#> Average observed response: 5.856 
#> 
#> Counterfactual Model (CFM): 
#> A model of class 'flexsurvreg' 
#>  Fit with 3 internal knots
#> 
#> Formula: 
#> Surv(time, cen) ~ vi/age60 + ecog + allmets + logafp + alb + 
#>     logcreat + logast + aet
#> <environment: 0x11e1413c0>
#> 
#> Call:
#>  CFM model + beta
#> 
#> Coefficients:
#>       median    2.5%      97.5%     Pr(x<0)   Pr(x>0) 
#> beta    0.4196    0.1069    0.7465    0.0072    0.9928
#> DIC   100.8129   95.2221  109.8273        NA        NA

And look at the plots for each outcome

PSC plot for ECOG=0

plot(sub1)

PSC plot for ECOG=1

plot(sub2)

mirror server hosted at Truenetwork, Russian Federation.