[Ipmpack-users] using a SSlogis model for survival.

jessica metcalf c.jessica.e.metcalf at gmail.com
Mon Apr 1 09:35:08 CEST 2013


Hi Joachim,

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:

setClass("survObjAsym",
representation(fit = "nls"))


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):

makeSurvObjAsym <- function (dataf,Start=c(Asym=0.8,xmid=5,scale=1)){
    dataf <- subset(dataf, is.na(dataf$surv) == FALSE)
    if (length(dataf$offspringNext) > 0)
        dataf <- subset(dataf, !dataf$offspringNext %in% c("sexual",
            "clonal"))
    fit <- nls(surv ~ SSlogis(size, Asym, xmid, scale), start=Start, data =
dataf)
    sva1 <- new("survObjAsym")
    sva1 at fit <- fit
    return(sva1)
}


Third, you need to build a new method that will work with this new class of
object to predict survival:

setMethod("surv",
c("numeric","data.frame","survObjAsym"),
function(size,cov,survObj){
 newd <- data.frame(cbind(cov,size=size),
stringsAsFactors = FALSE)
 u <- as.numeric(predict(survObj at fit,newd,type="response"))

return(u);
})

Now, an example of this working:

dff<-generateData()
sv1 <-makeSurvObjAsym(dff)
surv(1:10,data.frame(11),sv1)

and the rest should follow,

Jess
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/ipmpack-users/attachments/20130401/d30b662b/attachment.html>


More information about the Ipmpack-users mailing list