TABLE OF CONTENTS
initRoutine/makePenalty.2deriv [ Functions ]
NAME
makePenalty.2deriv --- compute a penalty matrix on second derivatives of B-splines
FUNCTION
This function computes a matrix P such that
exp(x) %*% P %*% exp(x)
is the integral of the squared second derivative of a B-spline with a given set of knots and component weights exp(x)
SYNOPSIS
1764 makePenalty.2deriv <- function(ord, knots)
INPUTS
ord order of the B-spline knots set of basis knots
OUTPUTS
P a K x K matrix that penalizes the integrated squared second derivative
SOURCE
1767 { 1768 # compute the number of spline components K 1769 nspline <- sum(knots > attr(knots, "b")[1]) 1770 out <- matrix(0, nspline, nspline) 1771 for(j1 in 1:nspline){ 1772 for(j2 in j1:nspline){ 1773 # compute convolutions of second derivatives for each pair of basis functions 1774 out[j1, j2] <- splinederivint(2, ord, j1, 2, ord, j2, knots) 1775 } 1776 } 1777 # the matrix is symmetric 1778 for(j1 in 2:nspline){ 1779 for(j2 in 1:(j1 - 1)) out[j1, j2] <- out[j2, j1] 1780 } 1781 return(out) 1782 }