2
0
Fork 0
CVE/CVE_C/man/coef.cve.Rd

55 lines
1.5 KiB
R

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/coef.R
\name{coef.cve}
\alias{coef.cve}
\title{Gets estimated SDR basis.}
\usage{
\method{coef}{cve}(object, k, ...)
}
\arguments{
\item{object}{instance of \code{cve} as output from \code{\link{cve}} or
\code{\link{cve.call}}}
\item{k}{the SDR dimension.}
\item{...}{ignored.}
}
\value{
dir the matrix of CS or CMS of given dimension
}
\description{
Returns the SDR basis matrix for SDR dimension(s).
}
\examples{
# set dimensions for simulation model
p <- 8 # sample dimension
k <- 2 # real dimension of SDR subspace
n <- 200 # samplesize
# create B for simulation
b1 <- rep(1 / sqrt(p), p)
b2 <- (-1)^seq(1, p) / sqrt(p)
B <- cbind(b1, b2)
set.seed(21)
# creat predictor data x ~ N(0, I_p)
x <- matrix(rnorm(n * p), n, p)
# simulate response variable
# y = f(B'x) + err
# with f(x1, x2) = x1^2 + 2 * x2 and err ~ N(0, 0.25^2)
y <- (x \%*\% b1)^2 + 2 * (x \%*\% b2) + 0.25 * rnorm(100)
# calculate cve for k = 1, ..., 5
cve.obj <- cve(y ~ x, max.dim = 5)
# get cve-estimate for B with dimensions (p, k = 2)
B2 <- coef(cve.obj, k = 2)
# Projection matrix on span(B)
# equivalent to `B \%*\% t(B)` since B is semi-orthonormal
PB <- B \%*\% solve(t(B) \%*\% B) \%*\% t(B)
# Projection matrix on span(B2)
# equivalent to `B2 \%*\% t(B2)` since B2 is semi-orthonormal
PB2 <- B2 \%*\% solve(t(B2) \%*\% B2) \%*\% t(B2)
# compare estimation accuracy by Frobenius norm of difference of projections
norm(PB - PB2, type = 'F')
}