2019-11-22 08:32:14 +00:00
|
|
|
#' @export
|
2019-12-20 08:40:46 +00:00
|
|
|
directions <- function(object, k, ...) {
|
2019-11-22 08:32:14 +00:00
|
|
|
UseMethod("directions")
|
|
|
|
}
|
|
|
|
|
|
|
|
#' Computes projected training data \code{X} for given dimension `k`.
|
|
|
|
#'
|
2020-02-26 12:44:53 +00:00
|
|
|
#' Returns \eqn{B'X}. That is, it computes the projection of the \eqn{n x p}
|
|
|
|
#' design matrix \eqn{X} on the column space of \eqn{B} of dimension \eqn{k}.
|
2019-12-16 16:34:35 +00:00
|
|
|
#'
|
2019-12-20 08:40:46 +00:00
|
|
|
#' @param object an object of class \code{"cve"}, usually, a result of a call to
|
|
|
|
#' \code{\link{cve}} or \code{\link{cve.call}}.
|
2019-11-22 08:32:14 +00:00
|
|
|
#' @param k SDR dimension to use for projection.
|
2019-12-20 08:40:46 +00:00
|
|
|
#' @param ... ignored (no additional arguments).
|
2019-11-22 08:32:14 +00:00
|
|
|
#'
|
2019-12-16 16:34:35 +00:00
|
|
|
#' @return the \eqn{n\times k}{n x k} dimensional matrix \eqn{X B} where \eqn{B}
|
|
|
|
#' is the cve-estimate for dimension \eqn{k}.
|
|
|
|
#'
|
2019-12-05 16:35:29 +00:00
|
|
|
#' @examples
|
|
|
|
#' # create B for simulation (k = 1)
|
|
|
|
#' B <- rep(1, 5) / sqrt(5)
|
|
|
|
#' set.seed(21)
|
|
|
|
#' # creat predictor data x ~ N(0, I_p)
|
|
|
|
#' x <- matrix(rnorm(500), 100, 5)
|
|
|
|
#' # simulate response variable
|
|
|
|
#' # y = f(B'x) + err
|
|
|
|
#' # with f(x1) = x1 and err ~ N(0, 0.25^2)
|
|
|
|
#' y <- x %*% B + 0.25 * rnorm(100)
|
2021-02-10 18:05:35 +00:00
|
|
|
#' # calculate cve with method 'mean' for k = 1
|
2019-12-05 16:35:29 +00:00
|
|
|
#' set.seed(21)
|
2021-02-10 18:05:35 +00:00
|
|
|
#' cve.obj.mean <- cve(y ~ x, k = 1, method = 'mean')
|
2019-12-05 16:35:29 +00:00
|
|
|
#' # get projected data for k = 1
|
2021-02-10 18:05:35 +00:00
|
|
|
#' x.proj <- directions(cve.obj.mean, k = 1)
|
2019-12-05 16:35:29 +00:00
|
|
|
#' # plot y against projected data
|
|
|
|
#' plot(x.proj, y)
|
|
|
|
#'
|
2019-12-20 08:40:46 +00:00
|
|
|
#' @seealso \code{\link{cve}}
|
|
|
|
#'
|
2019-11-22 08:32:14 +00:00
|
|
|
#' @method directions cve
|
|
|
|
#' @aliases directions directions.cve
|
|
|
|
#' @export
|
2019-12-20 08:40:46 +00:00
|
|
|
directions.cve <- function(object, k, ...) {
|
|
|
|
if (!(k %in% names(object$res))) {
|
2019-11-22 08:32:14 +00:00
|
|
|
stop("SDR directions for requested dimension `k` not computed.")
|
|
|
|
}
|
2019-12-20 08:40:46 +00:00
|
|
|
return(object$X %*% object$res[[as.character(k)]]$B)
|
2019-11-22 08:32:14 +00:00
|
|
|
}
|