title: Predicting and Plotting Survival Curve with the CoxPH
body: <p>I am trying to predict and plot the (estimated) survival curve for a new observation in R. Using the &quot;survival&quot; library and the &quot;lung&quot; data set, I first fit a cox proportional hazards model to the data. Then, I tried to predict and plot the survival curve for a hypothetical new observation (I entered the details for this hypothetical new observation in the &quot;list&quot; command). However, this is not working.</p>
  <p>I have attached my code below:</p>
  <pre><code>#load library
  library(survival)
  data(lung)
  
  #create survival object
  s &lt;- with(lung,Surv(time,status))
  
  #create model
  modelA  &lt;- coxph(s ~ as.factor(sex)+age+ph.ecog+wt.loss+ph.karno,data=lung, model=TRUE)
  summary(modelA)
  
  #plot
  plot(survfit(modelA), ylab=&quot;Probability of Survival&quot;,
       xlab=&quot;Time&quot;, col=c(&quot;red&quot;, &quot;black&quot;, &quot;black&quot;))
  
  #predict for a hypothetical NEW observation (here is where the error is)
  lines(predict(modelA, newdata=list(sex=1, 
                                    age = 56, 
                                    ph.ecog = 1, 
                                    ph.karno = 50,
                                    wt.loss = 11),
                 type=&quot;quantile&quot;,
                 p=seq(.01,.99,by=.01)),
         seq(.99,.01,by=-.01),
         col=&quot;blue&quot;)
  ## Error in match.arg(type) : 
  ##  'arg' should be one of “lp”, “risk”, “expected”, “terms”, “survival”
  </code></pre>
  <p>Does anyone know what I am doing wrong? Thanks</p>