<div dir="ltr"><div>Hi Joachim, </div><div><br></div><div>For other list users; Joachim's question is how to define a method of survival using SSlogis. Here is a worked through example. First, you need to define the new class: </div>
<div><br></div><div>setClass("survObjAsym",</div><div><span class="" style="white-space:pre"> </span>representation(fit = "nls"))</div><div><br></div><div><br></div><div>Second, you need to define a make function (this is slightly edited from the version you supplied - it seems that "start" needs to be a named vector for nls to handle it - and I've also simplified the function because you don't need a lot of the checks that are necessary for complex polynomials, etc): </div>
<div> </div><div>makeSurvObjAsym <- function (dataf,Start=c(Asym=0.8,xmid=5,scale=1)){</div><div> dataf <- subset(dataf, <a href="http://is.na">is.na</a>(dataf$surv) == FALSE)</div><div> if (length(dataf$offspringNext) > 0)</div>
<div> dataf <- subset(dataf, !dataf$offspringNext %in% c("sexual",</div><div> "clonal"))</div><div> fit <- nls(surv ~ SSlogis(size, Asym, xmid, scale), start=Start, data = dataf)</div>
<div> sva1 <- new("survObjAsym")</div><div> sva1@fit <- fit</div><div> return(sva1)</div><div>}</div><div> </div><div> </div><div>Third, you need to build a new method that will work with this new class of object to predict survival: </div>
<div><br></div><div>setMethod("surv", </div><div><span class="" style="white-space:pre"> </span>c("numeric","data.frame","survObjAsym"),</div><div><span class="" style="white-space:pre"> </span>function(size,cov,survObj){</div>
<div><span class="" style="white-space:pre"> </span></div><div><span class="" style="white-space:pre"> </span>newd <- data.frame(cbind(cov,size=size),</div><div><span class="" style="white-space:pre"> </span>stringsAsFactors = FALSE)</div>
<div><span class="" style="white-space:pre"> </span></div><div><span class="" style="white-space:pre"> </span>u <- as.numeric(predict(survObj@fit,newd,type="response"))</div><div><br></div><div><span class="" style="white-space:pre"> </span>return(u);</div>
<div><span class="" style="white-space:pre"> </span>})</div><div><br></div><div>Now, an example of this working: </div><div><br></div><div>dff<-generateData()</div><div>sv1 <-makeSurvObjAsym(dff)</div><div>surv(1:10,data.frame(11),sv1)</div>
<div><br></div><div>and the rest should follow, </div><div><br></div><div>Jess<br></div></div>