TABLE OF CONTENTS
initRoutine/makepenalty [ Functions ]
NAME
makepenalty --- construct a penalty matrix
FUNCTION
Construct a penalty matrix for use with penalized spline fitting. Options are a penalty on the squared second differences of the spline parameters, or a penalty on the integrated squared second derivative.
SYNOPSIS
1699 makepenalty <- function(curve, usec = TRUE)
INPUTS
curve an RCurve structure usec boolean, whether to use fast C code
OUTPUTS
curve the input curve, with spline.penaltymatrix component updated
SOURCE
1702 { 1703 if(!curve$hasspline) return(curve) 1704 penalty <- curve$spline.penalty 1705 ord <- curve$spline.ord; nknots <- curve$spline.nknots; knots <- curve$spline.knots 1706 # second difference penalty 1707 if(penalty == "2diff") P <- makePenalty.2diff(ord + nknots) 1708 # second derivative penalty 1709 if(penalty == "2deriv" | penalty == "log2deriv") { 1710 if(usec) P <- cmakePenalty.2deriv(ord, knots) 1711 else P <- makePenalty.2deriv(ord, knots) 1712 # adjust for normalized B-splines for frailties 1713 if(curve$spline.norm){ 1714 Bint <- curve$spline.basisint 1715 P <- P / (Bint%*%t(Bint)) 1716 } 1717 } 1718 if(penalty == "none") P <- 0 1719 curve$spline.penaltymatrix <- P 1720 return(curve) 1721 }