[Returnanalytics-commits] r3772 - pkg/Dowd/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Jul 2 22:43:15 CEST 2015
Author: dacharya
Date: 2015-07-02 22:43:15 +0200 (Thu, 02 Jul 2015)
New Revision: 3772
Modified:
pkg/Dowd/R/PCAVaR.R
Log:
Condition for the special case when number.of.principal.components is 1 was added. Additional unnecessary line was removed.
Modified: pkg/Dowd/R/PCAVaR.R
===================================================================
--- pkg/Dowd/R/PCAVaR.R 2015-07-02 20:42:59 UTC (rev 3771)
+++ pkg/Dowd/R/PCAVaR.R 2015-07-02 20:43:15 UTC (rev 3772)
@@ -39,8 +39,14 @@
# Principal components estimation
a <- svd(return.data) # SVD; provides U and V
- index <- n - number.of.principal.components # Establishes how many zero terms on diagonal of S matrix
S.diag <- sort(a$d, decreasing = TRUE)[1:number.of.principal.components] # Creates diagonal for S matrix
+ # Following condition for the fact that scalar argument to diag returns
+ # identity matrix
+ if (length(S.diag) == 1) {
+ S.diag <- as.matrix(S.diag)
+ } else {
+ S.diag <- diag(S.diag)
+ }
S.diag <- diag(S.diag)
S <- matrix(0, min(m, n), min(m, n))
S[1:number.of.principal.components,1:number.of.principal.components] <- S.diag # Creates S matrix with diagonal S.diag
More information about the Returnanalytics-commits
mailing list