fix: some smaller stuff
This commit is contained in:
parent
25b20984d5
commit
8e95902e79
10
CVE/R/CVE.R
10
CVE/R/CVE.R
|
@ -123,10 +123,10 @@
|
||||||
#' # y = f(B'x) + err
|
#' # y = f(B'x) + err
|
||||||
#' # with f(x1, x2) = x1^2 + 2 * x2 and err ~ N(0, 0.25^2)
|
#' # 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)
|
#' y <- (x %*% b1)^2 + 2 * (x %*% b2) + 0.25 * rnorm(100)
|
||||||
#' # calculate cve with method 'simple' for k unknown in 1, ..., 4
|
#' # calculate cve with method 'mean' for k unknown in 1, ..., 4
|
||||||
#' cve.obj.s <- cve(y ~ x, max.dim = 4) # default method 'simple'
|
#' cve.obj.s <- cve(y ~ x, max.dim = 4) # default method 'mean'
|
||||||
#' # calculate cve with method 'weighed' for k = 2
|
#' # calculate cve with method 'weighed' for k = 2
|
||||||
#' cve.obj.w <- cve(y ~ x, k = 2, method = 'weighted')
|
#' cve.obj.w <- cve(y ~ x, k = 2, method = 'weighted.mean')
|
||||||
#' # estimate dimension from cve.obj.s
|
#' # estimate dimension from cve.obj.s
|
||||||
#' khat <- predict_dim(cve.obj.s)$k
|
#' khat <- predict_dim(cve.obj.s)$k
|
||||||
#' # get cve-estimate for B with dimensions (p, k = khat)
|
#' # get cve-estimate for B with dimensions (p, k = khat)
|
||||||
|
@ -145,13 +145,13 @@
|
||||||
#' # projection matrix on span(B)
|
#' # projection matrix on span(B)
|
||||||
#' # same as B %*% t(B) since B is semi-orthogonal
|
#' # same as B %*% t(B) since B is semi-orthogonal
|
||||||
#' PB <- B %*% solve(t(B) %*% B) %*% t(B)
|
#' PB <- B %*% solve(t(B) %*% B) %*% t(B)
|
||||||
#' # cve estimates for B with simple and weighted method
|
#' # cve estimates for B with mean and weighted method
|
||||||
#' B.s <- coef(cve.obj.s, k = 2)
|
#' B.s <- coef(cve.obj.s, k = 2)
|
||||||
#' B.w <- coef(cve.obj.w, k = 2)
|
#' B.w <- coef(cve.obj.w, k = 2)
|
||||||
#' # same as B.s %*% t(B.s) since B.s is semi-orthogonal (same vor B.w)
|
#' # same as B.s %*% t(B.s) since B.s is semi-orthogonal (same vor B.w)
|
||||||
#' PB.s <- B.s %*% solve(t(B.s) %*% B.s) %*% t(B.s)
|
#' PB.s <- B.s %*% solve(t(B.s) %*% B.s) %*% t(B.s)
|
||||||
#' PB.w <- B.w %*% solve(t(B.w) %*% B.w) %*% t(B.w)
|
#' PB.w <- B.w %*% solve(t(B.w) %*% B.w) %*% t(B.w)
|
||||||
#' # compare estimation accuracy of simple and weighted cve estimate by
|
#' # compare estimation accuracy of mean and weighted cve estimate by
|
||||||
#' # Frobenius norm of difference of projections.
|
#' # Frobenius norm of difference of projections.
|
||||||
#' norm(PB - PB.s, type = 'F')
|
#' norm(PB - PB.s, type = 'F')
|
||||||
#' norm(PB - PB.w, type = 'F')
|
#' norm(PB - PB.w, type = 'F')
|
||||||
|
|
|
@ -26,11 +26,11 @@ directions <- function(object, k, ...) {
|
||||||
#' # y = f(B'x) + err
|
#' # y = f(B'x) + err
|
||||||
#' # with f(x1) = x1 and err ~ N(0, 0.25^2)
|
#' # with f(x1) = x1 and err ~ N(0, 0.25^2)
|
||||||
#' y <- x %*% B + 0.25 * rnorm(100)
|
#' y <- x %*% B + 0.25 * rnorm(100)
|
||||||
#' # calculate cve with method 'simple' for k = 1
|
#' # calculate cve with method 'mean' for k = 1
|
||||||
#' set.seed(21)
|
#' set.seed(21)
|
||||||
#' cve.obj.simple <- cve(y ~ x, k = 1, method = 'simple')
|
#' cve.obj.mean <- cve(y ~ x, k = 1, method = 'mean')
|
||||||
#' # get projected data for k = 1
|
#' # get projected data for k = 1
|
||||||
#' x.proj <- directions(cve.obj.simple, k = 1)
|
#' x.proj <- directions(cve.obj.mean, k = 1)
|
||||||
#' # plot y against projected data
|
#' # plot y against projected data
|
||||||
#' plot(x.proj, y)
|
#' plot(x.proj, y)
|
||||||
#'
|
#'
|
||||||
|
|
|
@ -109,7 +109,7 @@ y <- (x \%*\% b1)^2 + 2 * (x \%*\% b2) + 0.25 * rnorm(100)
|
||||||
# calculate cve with method 'simple' for k unknown in 1, ..., 4
|
# calculate cve with method 'simple' for k unknown in 1, ..., 4
|
||||||
cve.obj.s <- cve(y ~ x, max.dim = 4) # default method 'simple'
|
cve.obj.s <- cve(y ~ x, max.dim = 4) # default method 'simple'
|
||||||
# calculate cve with method 'weighed' for k = 2
|
# calculate cve with method 'weighed' for k = 2
|
||||||
cve.obj.w <- cve(y ~ x, k = 2, method = 'weighted')
|
cve.obj.w <- cve(y ~ x, k = 2, method = 'weighted.mean')
|
||||||
# estimate dimension from cve.obj.s
|
# estimate dimension from cve.obj.s
|
||||||
khat <- predict_dim(cve.obj.s)$k
|
khat <- predict_dim(cve.obj.s)$k
|
||||||
# get cve-estimate for B with dimensions (p, k = khat)
|
# get cve-estimate for B with dimensions (p, k = khat)
|
||||||
|
|
|
@ -35,7 +35,7 @@ x <- matrix(rnorm(500), 100, 5)
|
||||||
y <- x \%*\% B + 0.25 * rnorm(100)
|
y <- x \%*\% B + 0.25 * rnorm(100)
|
||||||
# calculate cve with method 'simple' for k = 1
|
# calculate cve with method 'simple' for k = 1
|
||||||
set.seed(21)
|
set.seed(21)
|
||||||
cve.obj.simple <- cve(y ~ x, k = 1, method = 'simple')
|
cve.obj.simple <- cve(y ~ x, k = 1, method = 'mean')
|
||||||
# get projected data for k = 1
|
# get projected data for k = 1
|
||||||
x.proj <- directions(cve.obj.simple, k = 1)
|
x.proj <- directions(cve.obj.simple, k = 1)
|
||||||
# plot y against projected data
|
# plot y against projected data
|
||||||
|
|
Loading…
Reference in New Issue