View source: R/functions_range.R
computeS | R Documentation |
Calculates the smoothing (or "hat") matrix from a design matrix.
computeS(x, inds = 1:nrow(x))
x |
Matrix of spline values, assumed to have full rank. A data frame is coerced into a matrix. |
inds |
Column indices of smoothing matrix to return (corresponding to rows in |
Given a matrix X
of spline values, this computes S=X(X'X)^(-1)X'
. When x
has many rows, this can be quite large. The inds
argument can be used to return a subset of columns from S
.
An N
-by-n
matrix, where n
is the length of inds
and N
is the number of rows in x
.
# Simple design matrix case
X <- cbind(1, rep(c(0, 1), each=4))
S <- computeS(X)
# More complex example
xloc <- runif(n=100, min=0, max=10)
X <- splines::ns(x=xloc, df=4, intercept=TRUE)
S <- computeS(X)
S2 <- computeS(X, inds=1:4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.