Learn R Programming

DCCA (version 0.1.1)

Pm: Projection Matrix P

Description

Creates the \(m+1\) by \(m+1\) projection matrix defined by \(P = D(D'D)^{-1}D'\) where \(D\) is the design matrix associated to a polynomial regression of degree nu + 1.

Usage

Pm(m = 2, nu = 0)

Arguments

nu

the degree of the polinomial fit.

m

a positive integer satisfying \(m >= nu\) indicating the size of the window for the polinomial fit.

Value

an \(m+1\) by \(m+1\) matrix.

Details

To perform matrix inversion, the code makes use of the routine DGETRI in LAPACK, which applies an LU decomposition approach to obtain the inverse matrix. See the LAPACK documentation available at http://www.netlib.org/lapack.

Examples

Run this code
# NOT RUN {
P = Pm(m = 5, nu = 0)
P

n = 10
t = 1:n
D = cbind(rep(1,n),t,t^2)

# Calculating in R
PR = D%*%solve(t(D)%*%D)%*%t(D)
# Using the provided function
P = Pm(m = n-1, nu = 1)

# Difference:
sum(abs(P-PR))

# }

Run the code above in your browser using DataLab