Stata

Ouverture de la base

webuse set "https://raw.githubusercontent.com//mthevenin/analyse_duree/master/bases/"
webuse  "transplantation_m", clear
webuse set

/*
list in 1/10

     +----------------------------------------------------------------------------+
     | id   year   age   died   stime   surgery   transp~t   wait   mois   compet |
     |----------------------------------------------------------------------------|
  1. | 15     68    53      1       1         0          0      0      1        1 |
  2. | 43     70    43      1       2         0          0      0      1        1 |
  3. | 61     71    52      1       2         0          0      0      1        1 |
  4. | 75     72    52      1       2         0          0      0      1        1 |
  5. |  6     68    54      1       3         0          0      0      1        2 |
     |----------------------------------------------------------------------------|
  6. | 42     70    36      1       3         0          0      0      1        1 |
  7. | 54     71    47      1       3         0          0      0      1        1 |
  8. | 38     70    41      1       5         0          1      5      1        1 |
  9. | 85     73    47      1       5         0          0      0      1        1 |
 10. |  2     68    51      1       6         0          0      0      1        1 |
     +----------------------------------------------------------------------------+
*/

Analyse non paramétrique

Méthode actuarielle

Contrairement à la formation, l’estimation sera faite sur des intervalles de 30 jours

ltable stime died, interval(30) graph

/*
                 Beg.                                 Std.
   Interval     Total   Deaths   Lost    Survival    Error     [95% Conf. Int.]
-------------------------------------------------------------------------------
    0    30       103       22      1     0.7854    0.0406     0.6926    0.8531
   30    60        80       14      2     0.6462    0.0475     0.5449    0.7305
   60    90        64       12      0     0.5250    0.0498     0.4232    0.6171
   90   120        52        5      1     0.4741    0.0499     0.3738    0.5677
  120   150        46        1      1     0.4636    0.0499     0.3637    0.5575
  150   180        44        2      0     0.4426    0.0498     0.3435    0.5369
  180   210        42        3      1     0.4106    0.0495     0.3132    0.5053
  210   240        38        1      0     0.3998    0.0494     0.3030    0.4945
  240   270        37        1      1     0.3888    0.0492     0.2928    0.4836
  270   300        35        2      0     0.3666    0.0488     0.2720    0.4614
  300   330        33        1      0     0.3555    0.0486     0.2618    0.4502
  330   360        32        3      1     0.3216    0.0478     0.2308    0.4157
  360   390        28        0      1     0.3216    0.0478     0.2308    0.4157
  390   420        27        0      1     0.3216    0.0478     0.2308    0.4157
  420   450        26        0      2     0.3216    0.0478     0.2308    0.4157
  480   510        24        0      1     0.3216    0.0478     0.2308    0.4157
  510   540        23        0      1     0.3216    0.0478     0.2308    0.4157
  540   570        22        0      1     0.3216    0.0478     0.2308    0.4157
  570   600        21        1      1     0.3059    0.0479     0.2155    0.4010
  600   630        19        0      1     0.3059    0.0479     0.2155    0.4010
  660   690        18        1      1     0.2885    0.0483     0.1982    0.3849
  720   750        16        1      0     0.2704    0.0485     0.1807    0.3681
  840   870        15        1      1     0.2518    0.0486     0.1629    0.3506
  900   930        13        0      1     0.2518    0.0486     0.1629    0.3506
  930   960        12        0      1     0.2518    0.0486     0.1629    0.3506
  960   990        11        1      0     0.2289    0.0493     0.1404    0.3304
  990  1020        10        1      0     0.2060    0.0494     0.1192    0.3093
 1020  1050         9        1      0     0.1831    0.0489     0.0992    0.2873
 1140  1170         8        0      1     0.1831    0.0489     0.0992    0.2873
 1320  1350         7        0      1     0.1831    0.0489     0.0992    0.2873
 1380  1410         6        1      2     0.1465    0.0510     0.0645    0.2602
 1560  1590         3        0      2     0.1465    0.0510     0.0645    0.2602
 1770  1800         1        0      1     0.1465    0.0510     0.0645    0.2602
-------------------------------------------------------------------------------
*/

Récupération des quartiles de la durée

Installation de la commande qlt

net install qlt, from("https://mthevenin.github.io/analyse_duree/ado/qlt/") replace

* help qlt
ltable stime died, interval(30) saving(base, replace)
use base, clear
qlt
Duree pour differents quantiles de la fonction de survie
Definition des bornes Stata-ltable
S(t)=0.90: t=        .
S(t)=0.75: t=    7.623
S(t)=0.50: t=   74.729
S(t)=0.25: t=  849.325
S(t)=0.10: t=        .

Avec la définition des bornes des intervalles de Sas

qlt, sas

/*
Duree pour differents quantiles de la fonction de survie
Definition des bornes Sas-lifetest
S(t)=0.90: t=   13.977
S(t)=0.75: t=   37.623
S(t)=0.50: t=  104.729
S(t)=0.25: t=  906.993
S(t)=0.10: t=        .
*/

Méthode Kaplan-Meier

Mode analyse des durées: stset

Les données doivent être mises en mode analyse de durée (help stset)

qui use "D:\Marc\SMS\FORMATIONS\2017\analyse biographique\A distribuer\transplantation.dta" , clear
stset stime, f(died)

/*
     failure event:  (assumed to fail at time=stime)
obs. time interval:  (0, stime]
 exit on or before:  failure

------------------------------------------------------------------------------
        103  total observations
          0  exclusions
------------------------------------------------------------------------------
        103  observations remaining, representing
        103  failures in single-record/single-failure data
     31,938  total analysis time at risk and under observation
                                                at risk from t =         0
                                     earliest observed entry t =         0
                                          last observed exit t =     1,799

list in 1/10

     +-----------------------------------------------------------------------------------+
     | id   year   age   died   stime   surgery   transp~t   wait   _st   _d    _t   _t0 |
     |-----------------------------------------------------------------------------------|
  1. |  1     67    30      1      50         0          0      0     1    1    50     0 |
  2. |  2     68    51      1       6         0          0      0     1    1     6     0 |
  3. |  3     68    54      1      16         0          1      1     1    1    16     0 |
  4. |  4     68    40      1      39         0          1     36     1    1    39     0 |
  5. |  5     68    20      1      18         0          0      0     1    1    18     0 |
     |-----------------------------------------------------------------------------------|
  6. |  6     68    54      1       3         0          0      0     1    1     3     0 |
  7. |  7     68    50      1     675         0          1     51     1    1   675     0 |
  8. |  8     68    45      1      40         0          0      0     1    1    40     0 |
  9. |  9     68    47      1      85         0          0      0     1    1    85     0 |
 10. | 10     68    42      1      58         0          1     12     1    1    58     0 |
     +-----------------------------------------------------------------------------------+
*/

Estimation de la fonction de survie

sts list

/*
         failure _d:  died
   analysis time _t:  stime

             At                  Survivor      Std.
  Time     Risk   Fail   Lost    Function     Error     [95% Conf. Int.]
------------------------------------------------------------------------
     1      103      1      0      0.9903    0.0097     0.9331    0.9986
     2      102      3      0      0.9612    0.0190     0.8998    0.9852
     3       99      3      0      0.9320    0.0248     0.8627    0.9670
     5       96      2      0      0.9126    0.0278     0.8388    0.9535
     6       94      2      0      0.8932    0.0304     0.8155    0.9394
     8       92      1      0      0.8835    0.0316     0.8040    0.9321
     9       91      1      0      0.8738    0.0327     0.7926    0.9247
    11       90      0      1      0.8738    0.0327     0.7926    0.9247
    12       89      1      0      0.8640    0.0338     0.7811    0.9171
    16       88      3      0      0.8345    0.0367     0.7474    0.8937
    17       85      1      0      0.8247    0.0375     0.7363    0.8857
    18       84      1      0      0.8149    0.0383     0.7253    0.8777
    21       83      2      0      0.7952    0.0399     0.7034    0.8614
    28       81      1      0      0.7854    0.0406     0.6926    0.8531
    30       80      1      0      0.7756    0.0412     0.6819    0.8448
    31       79      0      1      0.7756    0.0412     0.6819    0.8448
    32       78      1      0      0.7657    0.0419     0.6710    0.8363
    35       77      1      0      0.7557    0.0425     0.6603    0.8278
    36       76      1      0      0.7458    0.0431     0.6495    0.8192
    37       75      1      0      0.7358    0.0436     0.6388    0.8106
    39       74      1      1      0.7259    0.0442     0.6282    0.8019
    40       72      2      0      0.7057    0.0452     0.6068    0.7842
    43       70      1      0      0.6956    0.0457     0.5961    0.7752
    45       69      1      0      0.6856    0.0461     0.5855    0.7662
    50       68      1      0      0.6755    0.0465     0.5750    0.7572
    51       67      1      0      0.6654    0.0469     0.5645    0.7481
    53       66      1      0      0.6553    0.0472     0.5541    0.7390
    58       65      1      0      0.6452    0.0476     0.5437    0.7298
    61       64      1      0      0.6352    0.0479     0.5333    0.7206
    66       63      1      0      0.6251    0.0482     0.5230    0.7113
    68       62      2      0      0.6049    0.0487     0.5026    0.6926
    69       60      1      0      0.5948    0.0489     0.4924    0.6832
    72       59      2      0      0.5747    0.0493     0.4722    0.6643
    77       57      1      0      0.5646    0.0494     0.4621    0.6548
    78       56      1      0      0.5545    0.0496     0.4521    0.6453
    80       55      1      0      0.5444    0.0497     0.4422    0.6357
    81       54      1      0      0.5343    0.0498     0.4323    0.6261
    85       53      1      0      0.5243    0.0499     0.4224    0.6164
    90       52      1      0      0.5142    0.0499     0.4125    0.6067
    96       51      1      0      0.5041    0.0499     0.4027    0.5969
   100       50      1      0      0.4940    0.0499     0.3930    0.5872
   102       49      1      0      0.4839    0.0499     0.3833    0.5773
   109       48      0      1      0.4839    0.0499     0.3833    0.5773
   110       47      1      0      0.4736    0.0499     0.3733    0.5673
   131       46      0      1      0.4736    0.0499     0.3733    0.5673
   149       45      1      0      0.4631    0.0499     0.3632    0.5571
   153       44      1      0      0.4526    0.0499     0.3531    0.5468
   165       43      1      0      0.4421    0.0498     0.3430    0.5364
   180       42      0      1      0.4421    0.0498     0.3430    0.5364
   186       41      1      0      0.4313    0.0497     0.3327    0.5258
   188       40      1      0      0.4205    0.0497     0.3225    0.5152
   207       39      1      0      0.4097    0.0495     0.3123    0.5045
   219       38      1      0      0.3989    0.0494     0.3022    0.4938
   263       37      1      0      0.3881    0.0492     0.2921    0.4830
   265       36      0      1      0.3881    0.0492     0.2921    0.4830
   285       35      2      0      0.3660    0.0488     0.2714    0.4608
   308       33      1      0      0.3549    0.0486     0.2612    0.4496
   334       32      1      0      0.3438    0.0483     0.2510    0.4383
   340       31      1      1      0.3327    0.0480     0.2409    0.4270
   342       29      1      0      0.3212    0.0477     0.2305    0.4153
   370       28      0      1      0.3212    0.0477     0.2305    0.4153
   397       27      0      1      0.3212    0.0477     0.2305    0.4153
   427       26      0      1      0.3212    0.0477     0.2305    0.4153
   445       25      0      1      0.3212    0.0477     0.2305    0.4153
   482       24      0      1      0.3212    0.0477     0.2305    0.4153
   515       23      0      1      0.3212    0.0477     0.2305    0.4153
   545       22      0      1      0.3212    0.0477     0.2305    0.4153
   583       21      1      0      0.3059    0.0478     0.2156    0.4008
   596       20      0      1      0.3059    0.0478     0.2156    0.4008
   620       19      0      1      0.3059    0.0478     0.2156    0.4008
   670       18      0      1      0.3059    0.0478     0.2156    0.4008
   675       17      1      0      0.2879    0.0483     0.1976    0.3844
   733       16      1      0      0.2699    0.0485     0.1802    0.3676
   841       15      0      1      0.2699    0.0485     0.1802    0.3676
   852       14      1      0      0.2507    0.0487     0.1616    0.3497
   915       13      0      1      0.2507    0.0487     0.1616    0.3497
   941       12      0      1      0.2507    0.0487     0.1616    0.3497
   979       11      1      0      0.2279    0.0493     0.1394    0.3295
   995       10      1      0      0.2051    0.0494     0.1183    0.3085
  1032        9      1      0      0.1823    0.0489     0.0985    0.2865
  1141        8      0      1      0.1823    0.0489     0.0985    0.2865
  1321        7      0      1      0.1823    0.0489     0.0985    0.2865
  1386        6      1      0      0.1519    0.0493     0.0713    0.2606
  1400        5      0      1      0.1519    0.0493     0.0713    0.2606
  1407        4      0      1      0.1519    0.0493     0.0713    0.2606
  1571        3      0      1      0.1519    0.0493     0.0713    0.2606
  1586        2      0      1      0.1519    0.0493     0.0713    0.2606
  1799        1      0      1      0.1519    0.0493     0.0713    0.2606
------------------------------------------------------------------------
*/
sts graph

Comparaison des fonctions de survie


Tests du log rank

On va comparer les fonctions de survie pour la variable surgery.

sts graph, by(surgery)

Tests du log rank: fonction sts test. On affichera ici plusieurs variantes du test.

local test `" "l" "w" "tw" "p" "'
foreach test2 of local test {
sts test surgery, `test2'
}

/*
Log-rank test for equality of survivor functions

        |   Events         Events
surgery |  observed       expected
--------+-------------------------
0       |        69          60.34
1       |         6          14.66
--------+-------------------------
Total   |        75          75.00

              chi2(1) =       6.59
              Pr>chi2 =     0.0103

         failure _d:  died
   analysis time _t:  stime


Wilcoxon (Breslow) test for equality of survivor functions

        |   Events         Events        Sum of
surgery |  observed       expected        ranks
--------+--------------------------------------
0       |        69          60.34          623
1       |         6          14.66         -623
--------+--------------------------------------
Total   |        75          75.00            0

              chi2(1) =       8.99
              Pr>chi2 =     0.0027

         failure _d:  died
   analysis time _t:  stime


Tarone-Ware test for equality of survivor functions

        |   Events         Events        Sum of
surgery |  observed       expected        ranks
--------+--------------------------------------
0       |        69          60.34    73.105398
1       |         6          14.66   -73.105398
--------+--------------------------------------
Total   |        75          75.00            0

              chi2(1) =       8.46
              Pr>chi2 =     0.0036

         failure _d:  died
   analysis time _t:  stime


Peto-Peto test for equality of survivor functions

        |   Events         Events        Sum of
surgery |  observed       expected        ranks
--------+--------------------------------------
0       |        69          60.34    6.0505875
1       |         6          14.66   -6.0505875
--------+--------------------------------------
Total   |        75          75.00            0

              chi2(1) =       8.66
              Pr>chi2 =     0.0032
*/

Comparaison des rmst

Installation de la commande strmst2:

ssc install strmst2

arm1 = opération
arm0 = pas d’opération

strmst2 surgery


/*
Restricted Mean Survival Time (RMST) by arm
-----------------------------------------------------------
   Group |  Estimate    Std. Err.      [95% Conf. Interval]
---------+-------------------------------------------------
   arm 1 |   734.758     133.478      473.145      996.370
   arm 0 |   310.168      43.160      225.576      394.760
-----------------------------------------------------------

Between-group contrast (arm 1 versus arm 0) 
------------------------------------------------------------------------
           Contrast  |  Estimate       [95% Conf. Interval]     P>|z|
---------------------+--------------------------------------------------
RMST (arm 1 - arm 0) |   424.590      149.641      699.539      0.002
RMST (arm 1 / arm 0) |     2.369        1.513        3.710      0.000
------------------------------------------------------------------------
*/

Risques proportionnels

Modèle de Cox

Estimation du modèle

Avec la correction d’Efron

stcox year age surgery, nolog noshow efron

/*
Cox regression -- Efron method for ties

No. of subjects =          103                  Number of obs    =         103
No. of failures =           75
Time at risk    =        31938
                                                LR chi2(3)       =       17.63
Log likelihood  =   -289.30639                  Prob > chi2      =      0.0005

------------------------------------------------------------------------------
          _t | Haz. Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        year |     0.8872     0.0597    -1.78   0.076       0.7775      1.0124
         age |     1.0300     0.0139     2.19   0.029       1.0031      1.0577
     surgery |     0.3726     0.1625    -2.26   0.024       0.1584      0.8761
------------------------------------------------------------------------------
*/
stcox year age surgery, nolog noshow efron nohr

/*
Cox regression -- Efron method for ties

No. of subjects =          103                  Number of obs    =         103
No. of failures =           75
Time at risk    =        31938
                                                LR chi2(3)       =       17.63
Log likelihood  =   -289.30639                  Prob > chi2      =      0.0005

------------------------------------------------------------------------------
          _t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        year |    -0.1196     0.0673    -1.78   0.076      -0.2516      0.0124
         age |     0.0296     0.0135     2.19   0.029       0.0031      0.0561
     surgery |    -0.9873     0.4363    -2.26   0.024      -1.8424     -0.1323
------------------------------------------------------------------------------
*/

Test de l’hypothèse PH

Test Grambsch-Therneau sur les résidus de Schoenfeld

* f(t)=t - par défaut 


estat phtest, detail


/*
      Test of proportional-hazards assumption

      Time:  Time
      ----------------------------------------------------------------
                  |       rho            chi2       df       Prob>chi2
      ------------+---------------------------------------------------
      year        |      0.10162         0.80        1         0.3720
      age         |      0.12937         1.61        1         0.2043
      surgery     |      0.29664         5.54        1         0.0186
      ------------+---------------------------------------------------
      global test |                      8.76        3         0.0327
      ----------------------------------------------------------------
*/


* f(t)= 1-km - solution par défaut de R
      
estat phtest, detail km

/*
      Test of proportional-hazards assumption

      Time:  Kaplan-Meier
      ----------------------------------------------------------------
                  |       rho            chi2       df       Prob>chi2
      ------------+---------------------------------------------------
      year        |      0.15920         1.96        1         0.1620
      age         |      0.10907         1.15        1         0.2845
      surgery     |      0.25096         3.96        1         0.0465
      ------------+---------------------------------------------------
      global test |                      7.99        3         0.0462
      ----------------------------------------------------------------
*/

Intéraction avec une fonction de la durée

\(f(t)=t\)

stcox year age surgery, nolog noshow efron nohr tvc(surgery) texp(_t)

/*
Cox regression -- Efron method for ties

No. of subjects =          103                  Number of obs    =         103
No. of failures =           75
Time at risk    =        31938
                                                LR chi2(4)       =       21.58
Log likelihood  =   -287.32903                  Prob > chi2      =      0.0002

------------------------------------------------------------------------------
          _t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
main         |
        year |    -0.1231     0.0668    -1.84   0.066      -0.2541      0.0079
         age |     0.0289     0.0134     2.15   0.032       0.0025      0.0552
     surgery |    -1.7547     0.6744    -2.60   0.009      -3.0765     -0.4330
-------------+----------------------------------------------------------------
tvc          |
     surgery |     0.0022     0.0011     2.02   0.043       0.0001      0.0044
------------------------------------------------------------------------------
Note: Variables in tvc equation interacted with _t.
*/

Introduction d’une variable dynamique (binaire)

Transformation de la base en format long aux temps d’évènement

Etape 1

stset stime, f(died) id(id)

/*
                id:  id
     failure event:  died != 0 & died < .
obs. time interval:  (stime[_n-1], stime]
 exit on or before:  failure

------------------------------------------------------------------------------
        103  total observations
          0  exclusions
------------------------------------------------------------------------------
        103  observations remaining, representing
        103  subjects
         75  failures in single-failure-per-subject data
     31,938  total analysis time at risk and under observation
                                                at risk from t =         0
                                     earliest observed entry t =         0
                                          last observed exit t =     1,799

*/

Etape 2

stsplit, at(failure)

stset stime, f(died) id(id)

sort id _t
list in 1/23


/*
                id:  id
     failure event:  died != 0 & died < .
obs. time interval:  (stime[_n-1], stime]
 exit on or before:  failure

------------------------------------------------------------------------------
        105  total observations
          2  ignored because id missing
------------------------------------------------------------------------------
        103  observations remaining, representing
        103  subjects
         75  failures in single-failure-per-subject data
     31,938  total analysis time at risk and under observation
                                                at risk from t =         0
                                     earliest observed entry t =         0
                                          last observed exit t =     1,799

     +--------------------------------------------------------------------------------------------------+
     | id   year   age   died   stime   surgery   transp~t   wait   mois   compet   _st   _d   _t   _t0 |
     |--------------------------------------------------------------------------------------------------|
  1. |  1     67    30      .       1         0          0      0      2        1     1    0    1     0 |
  2. |  1     67    30      .       2         0          0      0      2        1     1    0    2     1 |
  3. |  1     67    30      .       3         0          0      0      2        1     1    0    3     2 |
  4. |  1     67    30      .       5         0          0      0      2        1     1    0    5     3 |
  5. |  1     67    30      .       6         0          0      0      2        1     1    0    6     5 |
     |--------------------------------------------------------------------------------------------------|
  6. |  1     67    30      .       8         0          0      0      2        1     1    0    8     6 |
  7. |  1     67    30      .       9         0          0      0      2        1     1    0    9     8 |
  8. |  1     67    30      .      12         0          0      0      2        1     1    0   12     9 |
  9. |  1     67    30      .      16         0          0      0      2        1     1    0   16    12 |
 10. |  1     67    30      .      17         0          0      0      2        1     1    0   17    16 |
     |--------------------------------------------------------------------------------------------------|
 11. |  1     67    30      .      18         0          0      0      2        1     1    0   18    17 |
 12. |  1     67    30      .      21         0          0      0      2        1     1    0   21    18 |
 13. |  1     67    30      .      28         0          0      0      2        1     1    0   28    21 |
 14. |  1     67    30      .      30         0          0      0      2        1     1    0   30    28 |
 15. |  1     67    30      .      32         0          0      0      2        1     1    0   32    30 |
     |--------------------------------------------------------------------------------------------------|
 16. |  1     67    30      .      35         0          0      0      2        1     1    0   35    32 |
 17. |  1     67    30      .      36         0          0      0      2        1     1    0   36    35 |
 18. |  1     67    30      .      37         0          0      0      2        1     1    0   37    36 |
 19. |  1     67    30      .      39         0          0      0      2        1     1    0   39    37 |
 20. |  1     67    30      .      40         0          0      0      2        1     1    0   40    39 |
     |--------------------------------------------------------------------------------------------------|
 21. |  1     67    30      .      43         0          0      0      2        1     1    0   43    40 |
 22. |  1     67    30      .      45         0          0      0      2        1     1    0   45    43 |
 23. |  1     67    30      1      50         0          0      0      2        1     1    1   50    45 |
     +--------------------------------------------------------------------------------------------------+
*/

Etape 3

gen tvc = transplant==1 & wait<=_t
sort id _t
list id transplant wait tvc _d _t _t0 if id==10  , noobs

/*
  +--------------------------------------------+
  | id   transp~t   wait   tvc   _d   _t   _t0 |
  |--------------------------------------------|
  | 10          1     12     0    0    1     0 |
  | 10          1     12     0    0    2     1 |
  | 10          1     12     0    0    3     2 |
  | 10          1     12     0    0    5     3 |
  | 10          1     12     0    0    6     5 |
  |--------------------------------------------|
  | 10          1     12     0    0    8     6 |
  | 10          1     12     0    0    9     8 |
  | 10          1     12     1    0   12     9 |
  | 10          1     12     1    0   16    12 |
  | 10          1     12     1    0   17    16 |
  |--------------------------------------------|
  | 10          1     12     1    0   18    17 |
  | 10          1     12     1    0   21    18 |
  | 10          1     12     1    0   28    21 |
  | 10          1     12     1    0   30    28 |
  | 10          1     12     1    0   32    30 |
  |--------------------------------------------|
  | 10          1     12     1    0   35    32 |
  | 10          1     12     1    0   36    35 |
  | 10          1     12     1    0   37    36 |
  | 10          1     12     1    0   39    37 |
  | 10          1     12     1    0   40    39 |
  |--------------------------------------------|
  | 10          1     12     1    0   43    40 |
  | 10          1     12     1    0   45    43 |
  | 10          1     12     1    0   50    45 |
  | 10          1     12     1    0   51    50 |
  | 10          1     12     1    0   53    51 |
  |--------------------------------------------|
  | 10          1     12     1    1   58    53 |
  +--------------------------------------------+
*/

Estimation du modèle

stcox year age surgery tvc, nolog noshow efron nohr

Cox regression -- Efron method for ties

No. of subjects =          103                  Number of obs    =       3,573
No. of failures =           75
Time at risk    =        31938
                                                LR chi2(4)       =       17.70
Log likelihood  =   -289.27014                  Prob > chi2      =      0.0014

------------------------------------------------------------------------------
          _t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        year |    -0.1203     0.0673    -1.79   0.074      -0.2523      0.0117
         age |     0.0304     0.0139     2.19   0.029       0.0032      0.0577
     surgery |    -0.9829     0.4366    -2.25   0.024      -1.8385     -0.1273
         tvc |    -0.0822     0.3048    -0.27   0.787      -0.6797      0.5153
------------------------------------------------------------------------------

Modèle à temps discret

Variable de durée = mois

Mise en forme

expand mois
bysort id: gen t=_n
gen e = died
replace e=0 if t<mois

* list in 1/31

/*

     +-------------------------------------------------------------------------------------+
     | id   year   age   died   stime   surgery   transp~t   wait   mois   compet    t   e |
     |-------------------------------------------------------------------------------------|
  1. |  1     67    30      1      50         0          0      0      2        1    1   0 |
  2. |  1     67    30      1      50         0          0      0      2        1    2   1 |
  3. |  2     68    51      1       6         0          0      0      1        1    1   1 |
  4. |  3     68    54      1      16         0          1      1      1        1    1   1 |
  5. |  4     68    40      1      39         0          1     36      2        2    1   0 |
     |-------------------------------------------------------------------------------------|
  6. |  4     68    40      1      39         0          1     36      2        2    2   1 |
  7. |  5     68    20      1      18         0          0      0      1        1    1   1 |
  8. |  6     68    54      1       3         0          0      0      1        2    1   1 |
  9. |  7     68    50      1     675         0          1     51     23        1    1   0 |
 10. |  7     68    50      1     675         0          1     51     23        1    2   0 |
     |-------------------------------------------------------------------------------------|
 11. |  7     68    50      1     675         0          1     51     23        1    3   0 |
 12. |  7     68    50      1     675         0          1     51     23        1    4   0 |
 13. |  7     68    50      1     675         0          1     51     23        1    5   0 |
 14. |  7     68    50      1     675         0          1     51     23        1    6   0 |
 15. |  7     68    50      1     675         0          1     51     23        1    7   0 |
     |-------------------------------------------------------------------------------------|
 16. |  7     68    50      1     675         0          1     51     23        1    8   0 |
 17. |  7     68    50      1     675         0          1     51     23        1    9   0 |
 18. |  7     68    50      1     675         0          1     51     23        1   10   0 |
 19. |  7     68    50      1     675         0          1     51     23        1   11   0 |
 20. |  7     68    50      1     675         0          1     51     23        1   12   0 |
     |-------------------------------------------------------------------------------------|
 21. |  7     68    50      1     675         0          1     51     23        1   13   0 |
 22. |  7     68    50      1     675         0          1     51     23        1   14   0 |
 23. |  7     68    50      1     675         0          1     51     23        1   15   0 |
 24. |  7     68    50      1     675         0          1     51     23        1   16   0 |
 25. |  7     68    50      1     675         0          1     51     23        1   17   0 |
     |-------------------------------------------------------------------------------------|
 26. |  7     68    50      1     675         0          1     51     23        1   18   0 |
 27. |  7     68    50      1     675         0          1     51     23        1   19   0 |
 28. |  7     68    50      1     675         0          1     51     23        1   20   0 |
 29. |  7     68    50      1     675         0          1     51     23        1   21   0 |
 30. |  7     68    50      1     675         0          1     51     23        1   22   0 |
     |-------------------------------------------------------------------------------------|
 31. |  7     68    50      1     675         0          1     51     23        1   23   1 |
     +-------------------------------------------------------------------------------------+

*/

Paramétrisation avec durée continue

Les critères d’information

gen t2=t^2
gen t3=t^3

logit e  t ,  nolog 
estat ic

logit e  t t2 ,  nolog 
estat ic

logit e  t2 t3 ,  nolog 
estat ic



Logistic regression                             Number of obs     =      1,127
                                                LR chi2(1)        =      50.85
                                                Prob > chi2       =     0.0000
Log likelihood = -250.26058                     Pseudo R2         =     0.0922

------------------------------------------------------------------------------
           e |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           t |    -0.1007     0.0185    -5.45   0.000      -0.1370     -0.0645
       _cons |    -1.6436     0.1724    -9.53   0.000      -1.9815     -1.3057
------------------------------------------------------------------------------


Akaike's information criterion and Bayesian information criterion

-----------------------------------------------------------------------------
       Model |          N   ll(null)  ll(model)      df        AIC        BIC
-------------+---------------------------------------------------------------
           . |      1,127  -275.6841  -250.2606       2   504.5212   514.5758
-----------------------------------------------------------------------------
Note: BIC uses N = number of observations. See [R] BIC note.

*****************************************************************************

Logistic regression                             Number of obs     =      1,127
                                                LR chi2(2)        =      65.25
                                                Prob > chi2       =     0.0000
Log likelihood = -243.05761                     Pseudo R2         =     0.1183

------------------------------------------------------------------------------
           e |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           t |    -0.2172     0.0357    -6.08   0.000      -0.2872     -0.1471
          t2 |     0.0034     0.0008     4.50   0.000       0.0019      0.0049
       _cons |    -1.2326     0.1925    -6.40   0.000      -1.6098     -0.8554
------------------------------------------------------------------------------


Akaike's information criterion and Bayesian information criterion

-----------------------------------------------------------------------------
       Model |          N   ll(null)  ll(model)      df        AIC        BIC
-------------+---------------------------------------------------------------
           . |      1,127  -275.6841  -243.0576       3   492.1152   507.1972
-----------------------------------------------------------------------------
Note: BIC uses N = number of observations. See [R] BIC note.

       
*****************************************************************************       

Logistic regression                             Number of obs     =      1,127
                                                LR chi2(3)        =      72.86
                                                Prob > chi2       =     0.0000
Log likelihood = -239.25267                     Pseudo R2         =     0.1321

------------------------------------------------------------------------------
           e |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           t |    -0.4038     0.0819    -4.93   0.000      -0.5643     -0.2434
          t2 |     0.0157     0.0050     3.14   0.002       0.0059      0.0254
          t3 |    -0.0002     0.0001    -2.31   0.021      -0.0003     -0.0000
       _cons |    -0.8250     0.2406    -3.43   0.001      -1.2965     -0.3536
------------------------------------------------------------------------------

Akaike's information criterion and Bayesian information criterion

-----------------------------------------------------------------------------
       Model |          N   ll(null)  ll(model)      df        AIC        BIC
-------------+---------------------------------------------------------------
           . |      1,127  -275.6841  -239.2527       4   486.5053   506.6146
-----------------------------------------------------------------------------
Note: BIC uses N = number of observations. See [R] BIC note.

Estimation du modèle

logit e  t t2 t3 year age surgery, nolog

/*

Logistic regression                             Number of obs     =      1,127
                                                LR chi2(6)        =      90.69
                                                Prob > chi2       =     0.0000
Log likelihood = -230.33671                     Pseudo R2         =     0.1645

------------------------------------------------------------------------------
           e |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           t |    -0.3721     0.0824    -4.52   0.000      -0.5335     -0.2106
          t2 |     0.0142     0.0050     2.83   0.005       0.0044      0.0241
          t3 |    -0.0002     0.0001    -2.11   0.035      -0.0003     -0.0000
        year |    -0.1327     0.0738    -1.80   0.072      -0.2773      0.0119
         age |     0.0333     0.0147     2.27   0.023       0.0046      0.0621
     surgery |    -1.0109     0.4486    -2.25   0.024      -1.8902     -0.1317
       _cons |     7.0827     5.3077     1.33   0.182      -3.3203     17.4856
------------------------------------------------------------------------------
*/

Paramétrisation avec durée discrète

Pour l’exemple seulement, on prendra des intervalles découpés sur les quartiles de la durée

xtile ct4=t, n(4)
bysort id ct4: keep if _n==_N

tab  ct4 e

logit e i.ct4  year age surgery,  nolog

/*

         4 |
 quantiles |           e
      of t |         0          1 |     Total
-----------+----------------------+----------
         1 |        50         53 |       103 
         2 |        35         11 |        46 
         3 |        27          5 |        32 
         4 |        10          6 |        16 
-----------+----------------------+----------
     Total |       122         75 |       197 



Logistic regression                             Number of obs     =        197
                                                LR chi2(6)        =      39.30
                                                Prob > chi2       =     0.0000
Log likelihood = -111.23965                     Pseudo R2         =     0.1501

------------------------------------------------------------------------------
           e |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         ct4 |
          2  |    -1.0334     0.4189    -2.47   0.014      -1.8543     -0.2124
          3  |    -1.6152     0.5449    -2.96   0.003      -2.6831     -0.5473
          4  |    -0.4789     0.5993    -0.80   0.424      -1.6535      0.6957
             |
        year |    -0.2032     0.0932    -2.18   0.029      -0.3859     -0.0206
         age |     0.0469     0.0185     2.53   0.011       0.0106      0.0831
     surgery |    -1.1102     0.5026    -2.21   0.027      -2.0952     -0.1252
       _cons |    12.4467     6.6537     1.87   0.061      -0.5943     25.4877
------------------------------------------------------------------------------
*/

Modèles paramétriques

Commande streg

Modèle AFT

Weibull

Par défaut, le modèle de Weibull est exécuté sous paramétrisation PH. Pour une paramétrisation type AFT, ajouter l’option time.

webuse set "https://raw.githubusercontent.com//mthevenin/analyse_duree/master/bases/"
webuse  "transplantation_m", clear
webuse set

stset stime, f(died)
streg year age surgery , dist(weibull) time nolog noshow
estat ic

/*

Weibull AFT regression

No. of subjects =          103                  Number of obs    =         103
No. of failures =           75
Time at risk    =        31938
                                                LR chi2(3)       =       18.87
Log likelihood  =    -188.6278                  Prob > chi2      =      0.0003

------------------------------------------------------------------------------
          _t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        year |     0.1620     0.1218     1.33   0.184      -0.0768      0.4008
         age |    -0.0615     0.0247    -2.49   0.013      -0.1100     -0.0130
     surgery |     1.9703     0.7794     2.53   0.011       0.4427      3.4980
       _cons |    -3.0220     8.7284    -0.35   0.729     -20.1294     14.0854
-------------+----------------------------------------------------------------
       /ln_p |    -0.5868     0.0927    -6.33   0.000      -0.7685     -0.4051
-------------+----------------------------------------------------------------
           p |     0.5561     0.0516                        0.4637      0.6669
         1/p |     1.7983     0.1667                        1.4995      2.1566
------------------------------------------------------------------------------

Akaike's information criterion and Bayesian information criterion

-----------------------------------------------------------------------------
       Model |          N   ll(null)  ll(model)      df        AIC        BIC
-------------+---------------------------------------------------------------
           . |        103  -198.0632  -188.6278       5   387.2556   400.4292
-----------------------------------------------------------------------------
Note: BIC uses N = number of observations. See [R] BIC note.

*/

Loglogistique

streg year age surgery , dist(loglog) nolog noshow 
estat ic

/*
Loglogistic AFT regression

No. of subjects =          103                  Number of obs    =         103
No. of failures =           75
Time at risk    =        31938
                                                LR chi2(3)       =       21.69
Log likelihood  =   -183.03937                  Prob > chi2      =      0.0001

------------------------------------------------------------------------------
          _t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        year |     0.2408     0.1172     2.05   0.040       0.0110      0.4705
         age |    -0.0427     0.0213    -2.00   0.045      -0.0845     -0.0010
     surgery |     2.2747     0.6913     3.29   0.001       0.9198      3.6296
       _cons |   -10.4034     8.3410    -1.25   0.212     -26.7515      5.9446
-------------+----------------------------------------------------------------
    /lngamma |     0.1805     0.0970     1.86   0.063      -0.0095      0.3706
-------------+----------------------------------------------------------------
       gamma |     1.1979     0.1161                        0.9906      1.4486
------------------------------------------------------------------------------


Akaike's information criterion and Bayesian information criterion

-----------------------------------------------------------------------------
       Model |          N   ll(null)  ll(model)      df        AIC        BIC
-------------+---------------------------------------------------------------
           . |        103  -193.8865  -183.0394       5   376.0787   389.2524
-----------------------------------------------------------------------------
*/

Risques concurrents

Non paramétrique: estimation des IC

Installer les commandes stcompet et stcomlist

ssc install stcompet
ssc install stcomlist

Le risque d’intérêt est compet=1, le risque concurrent est compet=2

stset stime, failure(compet==1)
stcomlist, compet1(2)

/*
            failure:  compet == 1
 competing failures:  compet == 2

    Time       CIF         SE     [95% Conf. Int.]
--------------------------------------------------
       1    0.0097     0.0097     0.0009    0.0477
       2    0.0388     0.0190     0.0127    0.0892
       3    0.0583     0.0231     0.0239    0.1149
       5    0.0777     0.0264     0.0363    0.1395
       6    0.0874     0.0278     0.0429    0.1515
       8    0.0971     0.0292     0.0497    0.1634
       9    0.1068     0.0304     0.0566    0.1751
      12    0.1166     0.0316     0.0638    0.1868
      16    0.1362     0.0338     0.0785    0.2099
      18    0.1461     0.0349     0.0860    0.2212
      21    0.1657     0.0367     0.1014    0.2437
      32    0.1756     0.0376     0.1093    0.2550
      37    0.1856     0.0384     0.1173    0.2662
      40    0.1957     0.0393     0.1254    0.2775
      43    0.2058     0.0400     0.1337    0.2888
      45    0.2158     0.0408     0.1420    0.2999
      50    0.2259     0.0415     0.1503    0.3110
      51    0.2360     0.0422     0.1588    0.3221
      53    0.2461     0.0428     0.1673    0.3330
      58    0.2562     0.0434     0.1759    0.3439
      61    0.2662     0.0440     0.1845    0.3548
      66    0.2763     0.0445     0.1932    0.3656
      69    0.2864     0.0450     0.2020    0.3763
      72    0.3066     0.0459     0.2197    0.3976
      77    0.3167     0.0464     0.2286    0.4082
      78    0.3267     0.0467     0.2376    0.4187
      81    0.3368     0.0471     0.2466    0.4292
      85    0.3469     0.0475     0.2556    0.4396
      90    0.3570     0.0478     0.2648    0.4500
      96    0.3671     0.0481     0.2739    0.4604
     102    0.3771     0.0484     0.2831    0.4707
     110    0.3874     0.0487     0.2925    0.4812
     149    0.3980     0.0489     0.3021    0.4920
     165    0.4085     0.0492     0.3118    0.5027
     186    0.4193     0.0495     0.3217    0.5137
     188    0.4301     0.0497     0.3316    0.5246
     207    0.4408     0.0499     0.3417    0.5354
     219    0.4516     0.0501     0.3517    0.5462
     263    0.4624     0.0502     0.3618    0.5570
     285    0.4846     0.0505     0.3826    0.5791
     308    0.4957     0.0506     0.3931    0.5900
     340    0.5068     0.0507     0.4037    0.6009
     583    0.5221     0.0514     0.4171    0.6168
     675    0.5401     0.0524     0.4322    0.6361
     733    0.5580     0.0532     0.4477    0.6548
     995    0.5808     0.0548     0.4659    0.6795
    1032    0.6036     0.0559     0.4851    0.7031
    1386    0.6340     0.0583     0.5083    0.7357

            failure:  compet == 2
 competing failures:  compet == 1

    Time       CIF         SE     [95% Conf. Int.]
--------------------------------------------------
       3    0.0097     0.0097     0.0009    0.0477
       6    0.0194     0.0136     0.0038    0.0619
      16    0.0292     0.0166     0.0079    0.0761
      17    0.0391     0.0191     0.0128    0.0897
      28    0.0489     0.0213     0.0182    0.1029
      30    0.0587     0.0232     0.0240    0.1157
      35    0.0686     0.0250     0.0302    0.1286
      36    0.0786     0.0267     0.0367    0.1411
      39    0.0885     0.0282     0.0435    0.1534
      40    0.0986     0.0296     0.0504    0.1658
      68    0.1188     0.0322     0.0650    0.1901
      80    0.1288     0.0334     0.0724    0.2020
     100    0.1389     0.0345     0.0800    0.2138
     153    0.1495     0.0356     0.0880    0.2261
     334    0.1605     0.0368     0.0964    0.2392
     342    0.1720     0.0381     0.1052    0.2526
     852    0.1913     0.0417     0.1175    0.2787
     979    0.2141     0.0460     0.1320    0.3094
*/

Modèle cause-specific (Cox)

Attention: non relié aux IC

stcox year age surgery,  nohr

/*
Iteration 0:   log likelihood = -222.40766
Iteration 1:   log likelihood = -214.66912
Iteration 2:   log likelihood = -214.47069
Iteration 3:   log likelihood = -214.46905
Iteration 4:   log likelihood = -214.46905
Refining estimates:
Iteration 0:   log likelihood = -214.46905

Cox regression -- Breslow method for ties

No. of subjects =          103                  Number of obs    =         103
No. of failures =           56
Time at risk    =        31938
                                                LR chi2(3)       =       15.88
Log likelihood  =   -214.46905                  Prob > chi2      =      0.0012

------------------------------------------------------------------------------
          _t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        year |    -0.1033     0.0774    -1.33   0.182      -0.2550      0.0485
         age |     0.0385     0.0163     2.36   0.018       0.0065      0.0704
     surgery |    -1.1099     0.5290    -2.10   0.036      -2.1468     -0.0730
------------------------------------------------------------------------------
*/

Modèle de Fine-Gray

La commande stcrreg est installée avec les commandes de base. Relié directement aux IC, la définition du risque diffère du risque instantané usuel (risque de sous répartition).

stcrreg year age surgery, compete(compet=2) nohr


/*
         failure _d:  compet == 1
   analysis time _t:  stime

Iteration 0:   log pseudolikelihood = -227.92407  
Iteration 1:   log pseudolikelihood = -227.69764  
Iteration 2:   log pseudolikelihood = -227.69531  
Iteration 3:   log pseudolikelihood = -227.69531  

Competing-risks regression                       No. of obs       =        103
                                                 No. of subjects  =        103
Failure event  : compet == 1                     No. failed       =         56
Competing event: compet == 2                     No. competing    =         19
                                                 No. censored     =         28

                                                 Wald chi2(3)     =      11.42
Log pseudolikelihood = -227.69531                Prob > chi2      =     0.0097

------------------------------------------------------------------------------
             |               Robust
          _t |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        year |    -0.0724     0.0716    -1.01   0.312      -0.2128      0.0679
         age |     0.0370     0.0177     2.09   0.037       0.0022      0.0718
     surgery |    -0.8688     0.4510    -1.93   0.054      -1.7528      0.0153
------------------------------------------------------------------------------

       */

Modèle logistique multinomial

Attention: non relié aux IC Pour la variable de durée on utilise la variable mois

expand mois
bysort id: gen t=_n
gen t2=t*t

gen e = compet
replace e=0 if t<mois
mlogit e t t2 year age surgery

/*
Iteration 0:   log likelihood = -318.13171  
Iteration 1:   log likelihood = -285.78811  
Iteration 2:   log likelihood = -275.20206  
Iteration 3:   log likelihood = -275.00574  
Iteration 4:   log likelihood = -275.00542  
Iteration 5:   log likelihood = -275.00542  

Multinomial logistic regression                 Number of obs     =      1,127
                                                LR chi2(10)       =      86.25
                                                Prob > chi2       =     0.0000
Log likelihood = -275.00542                     Pseudo R2         =     0.1356

------------------------------------------------------------------------------
           e |        RRR   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
0            |  (base outcome)
-------------+----------------------------------------------------------------
1            |
           t |     0.8159     0.0338    -4.91   0.000       0.7522      0.8850
          t2 |     1.0032     0.0009     3.53   0.000       1.0014      1.0049
        year |     0.8795     0.0718    -1.57   0.116       0.7494      1.0321
         age |     1.0449     0.0183     2.51   0.012       1.0097      1.0813
     surgery |     0.3175     0.1711    -2.13   0.033       0.1104      0.9129
* Constante non reportée     
-------------+----------------------------------------------------------------
2            |
           t |     0.8168     0.0565    -2.93   0.003       0.7134      0.9353
          t2 |     1.0030     0.0015     1.94   0.052       1.0000      1.0060
        year |     0.8158     0.1127    -1.47   0.141       0.6223      1.0695
         age |     1.0111     0.0248     0.45   0.654       0.9635      1.0610
     surgery |     0.5412     0.4221    -0.79   0.431       0.1173      2.4959
* Constante non reportée      
------------------------------------------------------------------------------

       */