title: Pairwise differences between survreg survival curves (survival package) using emmeans
body: <p>I'm using survreg from the 'survival' package to model survival curves. I'm interested in obtaining pairwise differences between levels of factors. I've tried using pairwise_survdiff from the 'survminer' package, but the function won't work with either interactions or with cluster() factors.</p>
  <p>I've used emmeans a lot before with linear models, but I can't figure out how (or exactly what) emmeans is using to compare pairwise differences between curves.</p>
  <p>Here's an example model:</p>
  <pre><code>library(survival) 
  library(emmeans)
  
  lung.model &lt;- survreg(Surv(time, status) ~ factor(sex) + factor(ph.ecog), lung)
  
  </code></pre>
  <p>plot the same model using flexsurv:</p>
  <pre><code>require(flexsurv)
  lung.model  &lt;- flexsurvreg(s ~  factor(sex) + factor(ph.ecog),dist='weibull',data=lung)
  plot(lung.model)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/zsFDh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zsFDh.png" alt="survreg" /></a></p>
  <p>Use emmeans to obtain Tukey's pairwise differences:</p>
  <pre><code>emmeans(lung.model, pairwise ~ factor(sex)|factor(ph.ecog), adjust=&quot;tukey&quot;)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Ul3T7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ul3T7.png" alt="enter image description here" /></a></p>
  <p>and the emmean for each factor level:</p>
  <pre><code>emmeans(lung.model,  ~factor(sex)|factor(ph.ecog)) 
  </code></pre>
  <p><a href="https://i.stack.imgur.com/i8NGD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i8NGD.png" alt="enter image description here" /></a></p>
  <p>How exactly are emmeans calculated for survreg objects? If this was a linear model I'd expect emmeans to report an average value for time on the X axis, but time isn't included as a factor in survreg objects. Is emmeans here reporting median survival times?</p>
  <p>Also, how are the pairwise differences in the tukeys posthoc calculated?</p>
  <p>EDIT</p>
  <p>I'm still not following 100% here. With the following model:</p>
  <pre><code>library(survival) 
  library(emmeans)
  library(flexsurv)
  
  #plot model
  lung.model  &lt;- flexsurvreg(Surv(time, status) ~  factor(ph.ecog),dist='weibull',data=lung)
  plot(lung.model)
  
  #emmeans
  lung.model &lt;- survreg(Surv(time, status) ~ factor(ph.ecog), lung)
  emmeans(lung.model, pairwise ~ph.ecog, adjust=&quot;tukey&quot;, type = &quot;response&quot;)
  </code></pre>
  <p>Is emmeans fitting a single linear function to the model (i.e. an overall fit for ph.ecog) and then working out significant differences for each different level from that overall model fit?</p>
  <p>Is this why the response for each $emmeans corresponds to the same proportion of survival? Apologies for the basic question here, but I can't find anywhere else in the vignettes that explains how this is working for a survreg function!</p>