2
0
Fork 0
CVE/CVE_C/R/coef.R

34 lines
913 B
R
Raw Normal View History

#' Gets estimated SDR basis.
#'
#' Returns the SDR basis matrix for SDR dimension(s).
#' @param object instance of \code{cve} as output from \code{\link{cve}} or
#' \code{\link{cve.call}}
#' @param k the SDR dimension.
#' @param ... ignored.
#'
#' @return dir the matrix of CS or CMS of given dimension
#'
#' @examples
#' x <- matrix(rnorm(400),100,4)
#' y <- x[, 1] + x[, 2] + as.matrix(rnorm(100))
#' dr <- cve(y ~ x, k = 2) # Only for sub-space dim. 2
#' B2 <- coef(dr, 2)
#'
#' @method coef cve
#' @aliases coef.cve
#' @rdname coef.cve
#' @export
coef.cve <- function(object, k, ...) {
if (missing(k)) {
Bs <- list()
for (k in names(object$res)) {
Bs[[k]] <- object$res[[k]]$B
}
return(Bs)
} else if (k %in% names(object$res)) {
return(object$res[[as.character(k)]]$B)
} else {
stop("Requested dimension `k` not computed.")
}
}