16  Stata

Note
  • Le document a été compilé avec le magique kernel jupyter nbstata programmé par Tim Huegerich. Comparé à l’ancienne solution statamarkdown qui exécutait Stata en mode batch, il n’y a pas photo au niveau du runtime, avec pratiquement aucune latence une fois le noyau chargé (attendre une quinzaine de seconde à la première compilation).
  • Le document n’a pas été compilé en PDF, seule cette version html est disponible.

Ouverture de la base

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

list id year age surgery stime died in 1/10
(prefix now "https://raw.githubusercontent.com//mthevenin/analyse_duree/master/
> bases")
(SAVASTATA created this dataset on 01AUG2019)
(prefix now "https://www.stata-press.com/data/r18")

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

16.1 Analyse non paramétrique

16.1.1 Méthode actuarielle

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

ltable stime died, interval(30) graph ci

                 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://raw.githubusercontent.com/mthevenin/analyse_duree/master/ado/qlt/") replace

* help qlt
qui ltable stime died, interval(30) saving(base, replace)
use base, clear
(SAVASTATA created this dataset on 01AUG2019)
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=        .

16.1.2 Méthode Kaplan-Meier

Mode analyse des durées: stset

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

A minima la commande stset entre la variable de durée en argument principal et la variable de censure/évènement avec failure(nom_var) en option.

stset stime, f(died)

list id stime died _st _d _t _t0 in 1/10

Survival-time data settings

         Failure event: died!=0 & died<.
Observed time interval: (0, stime]
     Exit on or before: failure

--------------------------------------------------------------------------
        103  total observations
          0  exclusions
--------------------------------------------------------------------------
        103  observations remaining, representing
         75  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

     +-----------------------------------------+
     | id   stime   died   _st   _d   _t   _t0 |
     |-----------------------------------------|
  1. | 15       1      1     1    1    1     0 |
  2. | 43       2      1     1    1    2     0 |
  3. | 61       2      1     1    1    2     0 |
  4. | 75       2      1     1    1    2     0 |
  5. |  6       3      1     1    1    3     0 |
     |-----------------------------------------|
  6. | 42       3      1     1    1    3     0 |
  7. | 54       3      1     1    1    3     0 |
  8. | 38       5      1     1    1    5     0 |
  9. | 85       5      1     1    1    5     0 |
 10. |  2       6      1     1    1    6     0 |
     +-----------------------------------------+

Estimation de la fonction de survie

La commande sts list permet d’afficher le tableau des estimations à chaque moment d’évènement

Note

Le tableau des estimateurs n’est reporté que pour le format htl du support

sts list

        Failure _d: died
  Analysis time _t: stime

Kaplan–Meier survivor function

             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
------------------------------------------------------------------------

On récupére les quantiles de la durée avec stci. Par défaut la commande affiche la durée médiane. On peut choisir le quantile avec l’arguement p(valeur) en option

stci

stci, p(75)
stci, p(25)

        Failure _d: died
  Analysis time _t: stime

             | Number of 
             |  subjects         50%      Std. err.    [95% conf. interval]
-------------+-------------------------------------------------------------
       Total |       103         100      38.64425           69        219

        Failure _d: died
  Analysis time _t: stime

             | Number of 
             |  subjects         75%      Std. err.    [95% conf. interval]
-------------+-------------------------------------------------------------
       Total |       103         979      144.4728          340          .

        Failure _d: died
  Analysis time _t: stime

             | Number of 
             |  subjects         25%      Std. err.    [95% conf. interval]
-------------+-------------------------------------------------------------
       Total |       103          36      9.033439           16         51

Pour afficher le graphique des estimateurs KM, on utilise la commande sts graph. On ajoute ici l’affichage des intervalles de confiance avec l’option ci

sts graph, ci

        Failure _d: died
  Analysis time _t: stime

Les commandes sts list, stci et sts graph permettent avec l’option by(nom_variable) d’obtenir des comparaisons entre groupes.

16.1.3 Comparaison des fonctions de survie (KM)

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

Graphique

On ajoute l’option by(surgery) à la commande sts graph

sts graph, by(surgery) ci ci1opts(fc(stc1%40))  ci2opts(fc(stc2%40)) legend(pos(6))

        Failure _d: died
  Analysis time _t: stime

Tests du logrank

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'
}

        Failure _d: died
  Analysis time _t: stime

Equality of survivor functions
Log-rank test

        |  Observed       Expected
surgery |    events         events
--------+-------------------------
      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

Equality of survivor functions
Wilcoxon–Breslow–Gehan test

        |  Observed       Expected       Sum of
surgery |    events         events        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

Equality of survivor functions
Tarone–Ware test

        |  Observed       Expected       Sum of
surgery |    events         events        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

Equality of survivor functions
Peto–Peto–Prentice test

        |  Observed       Expected       Sum of
surgery |    events         events        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
  • Comparaison deux à deux (c’est pas plus mal comme cela). Je conseille de mettre les variables sous forme d’indicatrice.
  • Les labels de la variable ne sont jamais reportés. Ils sont remplacés par les modalités arm0 et arm1.
  • On peut changer la valeurs maximale de la durée avec l’option tau(valeur).

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

strmst2 surgery
 
Number of observations for analysis = 103
 
The truncation time, tau, was not specified. Thus, the default tau (the minimum
>  of the
largest observed event time within each group), 995.000, is used.

Restricted Mean Survival Time (RMST) by arm
-----------------------------------------------------------
   Group |  Estimate    Std. Err.      [95% Conf. Interval]
---------+-------------------------------------------------
   arm 1 |   734.758     104.187      530.554      938.961
   arm 0 |   310.168      42.481      226.907      393.429
-----------------------------------------------------------

Between-group contrast (arm 1 versus arm 0) 
------------------------------------------------------------------------
           Contrast  |  Estimate       [95% Conf. Interval]     P>|z|
---------------------+--------------------------------------------------
RMST (arm 1 - arm 0) |   424.590      204.064      645.115      0.000
RMST (arm 1 / arm 0) |     2.369        1.610        3.486      0.000
------------------------------------------------------------------------

16.2 Modèles à risques proportionnels

16.2.1 Modèle de Cox

16.2.1.1 Estimation du modèle

Commande stcox

Avec la correction d’Efron (conseillé)

HR:

stcox year age surgery, nolog noshow efron

Cox regression with Efron method for ties

No. of subjects =    103                                Number of obs =    103
No. of failures =     75
Time at risk    = 31,938
                                                        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.887      0.060    -1.78   0.076        0.778       1.012
         age |      1.030      0.014     2.19   0.029        1.003       1.058
     surgery |      0.373      0.163    -2.26   0.024        0.158       0.876
------------------------------------------------------------------------------

log(HR):

stcox year age surgery, nolog noshow efron nohr

Cox regression with Efron method for ties

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

------------------------------------------------------------------------------
          _t | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
        year |     -0.120      0.067    -1.78   0.076       -0.252       0.012
         age |      0.030      0.014     2.19   0.029        0.003       0.056
     surgery |     -0.987      0.436    -2.26   0.024       -1.842      -0.132
------------------------------------------------------------------------------

16.2.1.2 Test de l’hypothèse PH

Test Grambsch-Therneau sur les résidus de Schoenfeld

Le test OLS est exécuté avec la commande estat phtest. Je conseille d’ajouté l’option detail pour récupéré les test à un degré de liberté, le test omnibus n’étant pas fiable.

Par défaut \(f(t)=t\).

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

estat phtest, detail


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

Test of proportional-hazards assumption

Time function: Analysis 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
--------------------------------------------------------

Test of proportional-hazards assumption

Time function: 1 - Kaplan–Meier estimate
--------------------------------------------------------
             |        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

Avec \(f(t)=t\)

L’intéraction s’ajoute directement en option en indiquant la ou les variables concernées (une seule de préférence) avec l’option tvc(nom_variable) et la transformation de la durée (variable t) avec l’option texp(expression). Ici on a choisi \(ft(t)\) soit l’expression dans l’option texp(_t)

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


Cox regression with Efron method for ties

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

------------------------------------------------------------------------------
          _t | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
main         |
        year |     -0.123      0.067    -1.84   0.066       -0.254       0.008
         age |      0.029      0.013     2.15   0.032        0.003       0.055
     surgery |     -1.755      0.674    -2.60   0.009       -3.077      -0.433
-------------+----------------------------------------------------------------
tvc          |
     surgery |      0.002      0.001     2.02   0.043        0.000       0.004
------------------------------------------------------------------------------
Note: Variables in tvc equation interacted with _t.

16.2.1.3 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)

Survival-time data settings

           ID variable: id
         Failure event: died!=0 & died<.
Observed 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)
(62 failure times)
(3,470 observations (episodes) created)

Survival-time data settings

           ID variable: id
         Failure event: died!=0 & died<.
Observed time interval: (stime[_n-1], stime]
     Exit on or before: failure

--------------------------------------------------------------------------
      3,573  total observations
          0  exclusions
--------------------------------------------------------------------------
      3,573  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 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 with Efron method for ties

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

------------------------------------------------------------------------------
          _t | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
        year |     -0.120      0.067    -1.79   0.074       -0.252       0.012
         age |      0.030      0.014     2.19   0.029        0.003       0.058
     surgery |     -0.983      0.437    -2.25   0.024       -1.839      -0.127
         tvc |     -0.082      0.305    -0.27   0.787       -0.680       0.515
------------------------------------------------------------------------------

16.2.2 Modèle à durée discrète

Variable de durée = mois

16.2.2.1 Mise en forme de la base

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

list id year age surgery mois t e  in 1/31
(1,024 observations created)
(399 real changes made)

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

16.2.2.2 Paramétrisation avec durée quantitative

Les critères d’information

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

qui logit e  t ,  nolog 
estat ic

qui logit e  t t2 ,  nolog 
estat ic

qui logit e  t2 t3 ,  nolog 
estat ic

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] IC note.

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] IC note.

Akaike's information criterion and Bayesian information criterion

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

Estimation du modèle

qui sum year
qui gen year2 = year - `r(mean)'
qui sum age
qui gen age2 = age - `r(mean)'


logit e t t2 t3 year2 age2 surgery, nolog or

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 | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
           t |      0.689      0.057    -4.52   0.000        0.587       0.810
          t2 |      1.014      0.005     2.83   0.005        1.004       1.024
          t3 |      1.000      0.000    -2.11   0.035        1.000       1.000
       year2 |      0.876      0.065    -1.80   0.072        0.758       1.012
        age2 |      1.034      0.015     2.27   0.023        1.005       1.064
     surgery |      0.364      0.163    -2.25   0.024        0.151       0.877
       _cons |      0.440      0.110    -3.29   0.001        0.270       0.718
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.

16.2.2.3 Paramétrisation avec durée discrète

Pour l’exemple seulement, on procède à un regroupement 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
(930 observations deleted)

         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 
logit e i.ct4  year age surgery,  nolog or

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

------------------------------------------------------------------------------
           e | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
         ct4 |
          1  |      1.000  (base)
          2  |      0.356      0.149    -2.47   0.014        0.157       0.809
          3  |      0.199      0.108    -2.96   0.003        0.068       0.578
          4  |      0.619      0.371    -0.80   0.424        0.191       2.005
             |
        year |      0.816      0.076    -2.18   0.029        0.680       0.980
         age |      1.048      0.019     2.53   0.011        1.011       1.087
     surgery |      0.330      0.166    -2.21   0.027        0.123       0.882
       _cons |   2.54e+05   1.69e+06     1.87   0.061        0.552    1.17e+11
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.

16.3 Modèles paramétriques

Juste un exemple pour le modèle de weibull

Commande streg

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.

PH: défaut

*qui stset stime, f(died) // penser à mettre la base en mode analyse de durée

streg year age surgery , dist(weibull) nolog noheader

        Failure _d: died
  Analysis time _t: stime

------------------------------------------------------------------------------
          _t | Haz. ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
        year |      0.914      0.061    -1.36   0.175        0.802       1.041
         age |      1.035      0.014     2.47   0.014        1.007       1.063
     surgery |      0.334      0.145    -2.52   0.012        0.143       0.783
       _cons |      5.368     25.895     0.35   0.728        0.000   68506.303
-------------+----------------------------------------------------------------
       /ln_p |     -0.587      0.093    -6.33   0.000       -0.769      -0.405
-------------+----------------------------------------------------------------
           p |      0.556      0.052                         0.464       0.667
         1/p |      1.798      0.167                         1.499       2.157
------------------------------------------------------------------------------
Note: _cons estimates baseline hazard.

AFT

streg year age surgery , dist(weibull) time nolog noheader

        Failure _d: died
  Analysis time _t: stime

------------------------------------------------------------------------------
          _t | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
        year |      0.162      0.122     1.33   0.184       -0.077       0.401
         age |     -0.062      0.025    -2.49   0.013       -0.110      -0.013
     surgery |      1.970      0.779     2.53   0.011        0.443       3.498
       _cons |     -3.022      8.728    -0.35   0.729      -20.129      14.085
-------------+----------------------------------------------------------------
       /ln_p |     -0.587      0.093    -6.33   0.000       -0.769      -0.405
-------------+----------------------------------------------------------------
           p |      0.556      0.052                         0.464       0.667
         1/p |      1.798      0.167                         1.499       2.157
------------------------------------------------------------------------------

16.4 Risques concurrents

16.4.1 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. La commande externe stcompet permet d’estimer les CIF mais ne propose pas d’output des estimateurs 1. On utilise alors la commande stcomlist en précisant le ou les risques concurrent (ici compet=2)

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

Survival-time data settings

         Failure event: compet==1
Observed time interval: (0, stime]
     Exit on or before: failure

--------------------------------------------------------------------------
        103  total observations
          0  exclusions
--------------------------------------------------------------------------
        103  observations remaining, representing
         56  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

            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

16.4.2 Modèle multinomial à durée discrète

Rappel: Le modèle de Cox cause-specific s’excute facilement. Il suffit de passer la ou les causes concurrente en censure à droite. De même le modèle Fine-Gray (critiqué) est estimable avec la commande usine stcrreg

Attention le modèle modèle multinomial n’est pas directement relié aux CIF. Il permet néanmoins d’estimer des probabilités conditionnelles qui tiennent pleinement compte de concurrence entre les différentes issues. Pour la variable de durée on utilise la variable mois

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

qui sum year
qui gen year2 = year - `r(mean)'
qui sum age
qui gen age2 = age - `r(mean)'

gen e = compet
replace e=0 if t<mois
mlogit e t t2 year2 age2 surgery, rrr noheader
(399 real changes made)

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  
------------------------------------------------------------------------------
           e |        RRR   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
0            |  (base outcome)
-------------+----------------------------------------------------------------
1            |
           t |      0.816      0.034    -4.91   0.000        0.752       0.885
          t2 |      1.003      0.001     3.53   0.000        1.001       1.005
       year2 |      0.879      0.072    -1.57   0.116        0.749       1.032
        age2 |      1.045      0.018     2.51   0.012        1.010       1.081
     surgery |      0.318      0.171    -2.13   0.033        0.110       0.913
       _cons |      0.222      0.052    -6.49   0.000        0.141       0.350
-------------+----------------------------------------------------------------
2            |
           t |      0.817      0.056    -2.93   0.003        0.713       0.935
          t2 |      1.003      0.002     1.94   0.052        1.000       1.006
       year2 |      0.816      0.113    -1.47   0.141        0.622       1.070
        age2 |      1.011      0.025     0.45   0.654        0.964       1.061
     surgery |      0.541      0.422    -0.79   0.431        0.117       2.496
       _cons |      0.078      0.029    -6.94   0.000        0.038       0.160
------------------------------------------------------------------------------
Note: _cons estimates baseline relative risk for each outcome.

  1. on doit cependant l’installer pour utiliser la commande suivante↩︎