Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mathematical equation of parametric survival model from stpm2

    Hi all,

    I have constructed a flexible parametric survival model using stpm2 on Stata 13.1 on the scale (hazard), with a df of 3. I've obtained the coefficients of my covariate (pi_linear) , _rcs [1 to 3] and the constant term as shown below.

    Click image for larger version

Name:	RP model.png
Views:	2
Size:	33.9 KB
ID:	1345984

    I wish to now predict survival probabilities at various time points using this model on an external platform. Therefore I wish to represent this parametric survival model mathematically for estimating log cumulative hazard at various time points. I am having trouble writing out the equation for the spline basis functions. I have read chapter 5 of the Textbook by Royston and Lambert on Flexible Parametric Survival Analysis Using Stata: Beyond the Cox Model, which provides a general equation (in page 110) using ln t, z1 and z2 but I am confused about how to obtain z1 and z2 for computing my log cumulative hazard at a specific time point. From page 110 :

    generate lnH = _b[_cons] + _rcs1 * _b[_rcs1] + _rcs2 * _b[_rcs2] + _rcs3 * _b[rcs3]

    Specifically I would like to ask where can I obtain the estimates for _b[rcs1], _b[_rcs2] and _b[_rcs3] for the above model in order to write out the log cumulative hazard function for the model above.

    Any leads are most appreciated!

    Thank you very much.

    Manee
    Attached Files

  • #2
    Hi,

    Below is an example where I run through how to do out of sample prediction. By default the splines are orthogonalised and it is easier to use the noorthog option. Otherwise you will have to save the projection matrix and do some matrix manipulation. The key is to save the knot positions as you will need these when generating the spline variables. I use rcsgen to generate the spline variables, but if using an external platform you will need to calculate the spline variables using the standard formula for restricted cubic splines.

    The code below gives the predicted survival at 1 to 5 years using the stpm2 predict command and then an out of sample prediction.
    Code:
    clear
    webuse brcancer
    stset rectime, f(censrec=1) scale(365.25)
    
    stpm2, scale(hazard) df(3) noorthog
    
    //store knots locations
    local bhknots `e(ln_bhknots)'
    di "`bhknots'"
    //store coefficients
    local gamma0 = _b[_cons]
    forvalues i = 1/3 {
     local gamma`i' = _b[_rcs`i']
    }
    range temptime 1 5 5
    predict surv, s timevar(temptime)
    list temptime surv in 1/5
    
    clear
    //
    set obs 5
    gen time = _n
    gen lntime = ln(time)
    
    // generate splines
    rcsgen lntime, gen(rcs) knots(`bhknots')
    
    gen logCH = `gamma0' + `gamma1'*rcs1 +  `gamma2'*rcs2 + `gamma3'*rcs3
    gen surv = exp(-exp(logCH))
    list time surv

    Comment


    • #3
      Dear Prof Lambert,

      Thank you very much for your reply. This is most helpful.

      If I could kindly squeeze in one last question - am I right to say that if I intend to incoporate the effect of covariates, I should add the log hazard ratios of the covariates to the equation for logCH?

      Thanks again for your kind assistance.

      Best wishes and kind regards,
      Manee



      Comment


      • #4
        Manee,

        Yes - for a proportional hazards model you just add the log hazard ratio multiplied by the relevant covariate value to the linear predictor.

        Paul

        Comment


        • #5
          Dear Prof Lambert,

          Thank you very much once again.

          Best regards,
          Manee

          Comment

          Working...
          X