TABLE OF CONTENTS
initRoutine/makePenalty.2diff [ Functions ]
NAME
makePenalty.2diff --- compute a penalty matrix on second differences
FUNCTION
This computes a matrix P such that
x %*% P %*% x
is the sum of squared second differences of x.
SYNOPSIS
1736 makePenalty.2diff <- function(K){
INPUTS
K the desired size of the matrix
OUTPUTS
P a K x K matrix that generates squared second differences.
SOURCE
1739 D <- matrix(0, K - 2, K) 1740 for(i in 1:(K - 2)){ 1741 D[i, i] <- 1 1742 D[i, i + 1] <- -2 1743 D[i, i + 2] <- 1 1744 } 1745 P <- t(D)%*%D 1746 return(P) 1747 }