I'm struggling to perform a correct and unbiased survival analysis, but I have some doubts.


I observe a population of posts on a blog within a temporal window $[T_{0}, T_{final}]$. Each post is characterized by:

  • a $start$ date: the date in which it has been published on the blog;
  • a $stop$ date: the date in which the last comment on the post has been left;
  • a $event$ date: the date in which the post has been shared on Twitter for the first time.

Basically, the lifetime of each post is defined as the difference between $stop$ and $start$.

Analysis and Related Doubts

My analysis (at least in this first part) aims at quantifying the effect on the lifetime of the post being shared on Twitter. Suppose I have data organized as follows:

id  start event stop shared
 1     0   105  192      1 
 2     0   162  245      1 
 3     0     2   88      1 

that is, in the case of $id = 1$, the post is originally published in $t = 0$, it is shared on Twitter after $105$ weeks, and it stopped being commented after $192$ weeks. Note that I brought back all $start$ time to zero.

Then, I re-organized data as follows:

id  start stop shared event
 1     0  106      0     1
 1   106  194      1     1
 2     0  163      0     1
 2   163  247      1     1
 3     0    3      0     1
 3     3   90      1     1

that is, now for each id I have two rows: the first ($shared = 0$) specifies the $start$ and $stop$ times before the post is shared on Twitter; whereas the second ($shared = 1$) specifies the $start$ and $stop$ times after the post is shared on Twitter.

At this point, I would like to perform a Kaplan-Meier estimate of the survival functions before and after the post is shared on Twitter.

s = with(surv.df, Surv(start, stop, event))
KM = survfit(s ~ shared, data = surv.df)

and then apply a Cox hazard regression to model to quantify the effect on the lifetime of the post being shared on Twitter

sCox = coxph(s ~ as.factor(shared), data=surv.df)

However, I'm not convinced about such a procedure.


  • Do you see any sources of bias in the analysis I have just presented?
  • Is it correct the way I organized data to perform my analysis?
  • Am I actually observing the effect of the post being shared on Twitter?

1 Answer 1


I think I've found a solution to my problem. Instead of using traditional survival analysis and Cox regression models, I used multi-state models. Here two good references:

Multi-state models allow to model complex event histories, by handling censoring and left truncation, and avoiding two common kind of bias: length bias and immortal bias.

Practically, I have three states, $S = {1,2,3}$:

  • $S = 1 \to$ initial state: posts are published on the blog;
  • $S = 2 \to$ shared state: posts are shared on Twitter;
  • $S = 3 \to$ absorbing state: posts did not receive comments in the last month;

Note that $S = 1$ is the initial state, i.e. each post starts in such a state, whereas $S = 3$ is an absorbing state, so that once the post arrives there, it remains there.

A transition matrix specifies the admissible transitions from one state to another:

$$T = \begin{pmatrix} p_{1,1}(t) & p_{1,2}(t) & p_{1,3}(t) \\ p_{2,1}(t) & p_{2,2}(t) & p_{2,3}(t) \\ p_{3,1}(t) & p_{3,2}(t) & p_{3,3}(t) \end{pmatrix}$$

In my case, I specified the following transition matrix:

$$T = \begin{pmatrix} p_{1,1}(t) & p_{1,2}(t) & p_{1,3}(t) \\ 0 & p_{2,2}(t) & p_{2,3}(t) \\ 0 & 0 & p_{3,3}(t) \end{pmatrix}$$

Note that all the probabilities are time-dependent. Such a transition matrix can be estimated by using R and the package msSurv. Once you have estimated the transition matrix, you can analyze the state entry/exit distribution in each state, the distributions of time-varying probabilities for transitions from one state to another, and the probability to be in a given state at a certain instant $t$.

In particular, by comparing the time-varying transition probabilities $p_{1,3}(t)$ and $p_{2,3}(t)$, I can understand if there is a difference between survival times of posts being or not being shared on Twitter.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.