Skip to content

Commit

Permalink
matrix coercion for 1-dim PC projections
Browse files Browse the repository at this point in the history
  • Loading branch information
Damon Pham committed Jun 24, 2020
1 parent 0f1582e commit 66c8804
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions R/clever.R
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ clever = function(
} else {
projection$svd <- X.svd
}
projection$svd$u <- projection$svd$u[,chosen_PCs_ordered]
projection$svd$u <- matrix(projection$svd$u[,chosen_PCs_ordered], nrow=T_)
if(PCs_detrend & projection_method!="PCATF"){
projection$svd$u_detrended <- projection$svd$u - apply(projection$svd$u, 2, est_trend)
attributes(projection$svd$u_detrended)$dimnames <- NULL
Expand Down Expand Up @@ -438,13 +438,13 @@ clever = function(
} else {
projection$indices <- projection$indices[1:max_keep]
}
projection$svd$u <- projection$svd$u[,1:max_keep]
projection$svd$u <- matrix(projection$svd$u[,1:max_keep], ncol=T_)
if(PCs_detrend & projection_method!="PCATF"){
projection$svd$u_detrended <- projection$svd$u_detrended[,1:max_keep]
projection$svd$u_detrended <- matrix(projection$svd$u_detrended[,1:max_keep], ncol=T_)
}
projection$svd$d <- projection$svd$d[1:max_keep]
if(solve_directions){
projection$svd$v <- projection$svd$v[,1:max_keep]
projection$svd$v <- matrix(projection$svd$v[,1:max_keep], ncol=T_)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions R/functions_levdist.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ PC.robdist <- function(U){

best <- c(cov.mcd(U)$best)
inMCD <- 1:n %in% best
U_in <- U[best,] # observations that are used for the MCD estimates calculation
U_in <- matrix(U[best,], ncol=Q) # observations that are used for the MCD estimates calculation
xbar_star <- colMeans(U_in) # MCD estimate of mean
U_ins <- scale(U_in, center = TRUE, scale = FALSE) # Damon: replace with U_ins - xbar_star?
nU <- nrow(U_ins)
S_star <- (t(U_ins) %*% U_ins)/(nU-1) # MCD estimate of covariance
mah <- (apply(U,1, function(x) t(x-xbar_star) %*% solve(S_star) %*% (x-xbar_star)))
mah <- (apply(U, 1, function(x) t(x-xbar_star) %*% solve(S_star) %*% (x-xbar_star)))
# Scale left-out observations to follow F-distribution.
Fparam <- fit.F(Q, n, sum(inMCD))
outMCD_scale <- Fparam$c * (Fparam$m - Q + 1) / (Q * Fparam$m)
Expand Down
4 changes: 2 additions & 2 deletions man/PCATF.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/clever.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 66c8804

Please sign in to comment.