TABLE OF CONTENTS
curveUpdate/evalparametric [ Functions ]
NAME
evalparametric --- evaluate the parametric component of a curve
FUNCTION
Evaluate the parametric component of a curve, either at all observations or at a single observation.
SYNOPSIS
1923 evalparametric <- function(curve, i = 0)
INPUTS
curve an RCurve structure i the index of the observation that should be evaluated (0=all)
OUTPUTS
curve the input curve, with x[i] reevaluated at curve$param.par
SOURCE
1926 { 1927 if(!curve$haspar) return(curve) 1928 if(i == 0) ind <- 1:length(curve$x) else ind <- i 1929 name <- curve$name 1930 dist <- curve$param.dist 1931 if(dist == "none") return(curve) 1932 # extract parameters and values at which to evaluate 1933 par <- curve$param.par 1934 x <- curve$x[ind] 1935 if(name == "hazard"){ 1936 if(dist == "exponential"){ 1937 # exponential components are parametrized by their log-baseline 1938 lambda <- exp(par) 1939 y <- rep(lambda, length(x)) 1940 ycum <- x * lambda 1941 } 1942 if(dist == "weibull"){ 1943 # weibull components are parametrized by their log-baseline and log-scale 1944 lambda <- exp(par[1]) 1945 alpha <- exp(par[2]) 1946 y <- alpha * lambda * x^(alpha - 1) 1947 ycum <- lambda * x^alpha 1948 } 1949 if(dist == "lognormal") 1950 stop("lognormal distribution currently not fully supported") 1951 } 1952 if(name == "frailty"){ 1953 ycum <- NULL 1954 if(dist == "gamma"){ 1955 # gamma components are parametrized by minus their log-shape 1956 alpha <- exp(-par) 1957 y <- dgamma(x, shape = alpha, rate = alpha) 1958 } 1959 if(dist == "lognormal"){ 1960 # lognormal components are parametrized by their log-variance 1961 alpha <- exp(par) 1962 y <- exp(-(log(x) + alpha / 2)^2 / (2 * alpha)) / (x * sqrt(2 * pi * alpha)) 1963 } 1964 } 1965 curve$param.y[ind] <- y 1966 curve$param.ycum[ind] <- ycum 1967 if(curve$hasspline) { 1968 # reweight the curve if it has a spline component 1969 curve <- weightcurve(curve, i) 1970 }else{ 1971 curve$y[ind] <- curve$param.y[ind] 1972 curve$ycum[ind] <- curve$param.ycum[ind] 1973 } 1974 return(curve) 1975 }