TABLE OF CONTENTS


initRoutine/fitparametric [ Functions ]

NAME

    fitparametric --- fit a parametric component to a curve

FUNCTION

Given a curve with a parametric component, compute a good set of initial values for the parametric component parameters. The parametric component distributions are parametrized in a way that allows Gaussian priors on the parameters, and this function incorporates that.

See also evalparametric for the parametrization used.

SYNOPSIS

1857 fitparametric <- function(curve, x)

INPUTS

    curve      an RCurve structure with a parametric component
    x          a set of data points used for estimation

OUTPUTS

    curve      updated curve with curve$param.par holding initial values

SOURCE

1860 {
1861     name <- curve$name
1862     dist <- curve$param.dist
1863     if(dist == "none") return(curve)
1864     # frailty curve
1865     if(name == "frailty")
1866     {
1867         # compute the variance of the frailties and set the parameter
1868         # according to the parametrization selected.
1869         Ui <- x
1870         if(dist == "gamma")
1871             par <- log(var(Ui))
1872         if(dist == "lognormal")
1873         {
1874             varu <- var(Ui)
1875             par <- log(log(varu + 1))
1876         }
1877         curve$param.par <- par
1878         curve$x <- Ui
1879     }
1880     # hazard curve
1881     if(name == "hazard")
1882     {
1883         agdata <- x
1884         varnames <- colnames(agdata)[ - (1:4)]
1885         qvarnames <- paste("`", varnames, "`", sep = "")
1886         # use survreg to fit a parametric component to the hazard
1887         # and transform the estimated parameters to the parametrization
1888         fit <- survreg(as.formula(paste("Surv(time, delta)~", 
1889             paste(qvarnames, collapse = " + "))), data = agdata, dist = dist)
1890         if(dist == "exponential"){
1891             par <- log(fit$icoef[1])
1892         }
1893         if(dist == "weibull"){
1894             lambda <- exp(-fit$icoef[1])
1895             gamma <- 1 / exp(fit$icoef[2])
1896             par <- c(log(lambda), log(gamma))
1897         }
1898         if(dist == "lognormal"){
1899             par <- c(fit$icoef[1], fit$icoef[2])
1900         }
1901         names(par) <- NULL
1902         curve$param.par <- par
1903         curve$x <- agdata$time
1904     }
1905     # Evaluate the curve at the parameter values chosen.
1906     curve <- evalparametric(curve)
1907     return(curve)
1908 }