Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR addressing Issue #161 #175

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions R/tune.spca.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ tune.spca <- function(X,
## split data to train/test
X.train = X[-test.fold.inds,,drop=FALSE]
X.test = X[test.fold.inds,,drop=FALSE]



# find indices of rows in X.train that contain NAs
rows.NAs.train <- rowSums(is.na(X.train))
rows.NAs.train <- which(rownames(X.train) %in% names(rows.NAs.train[rows.NAs.train!= 0]))

# find indices of rows in X.test that contain NAs
rows.NAs.test <- rowSums(is.na(X.test))
rows.NAs.test <- which(rownames(X.test) %in% names(rows.NAs.test[rows.NAs.test!= 0]))

# if there are rows with NAs, remove them from the appropriate sets
if (length(rows.NAs.train)>0) {X.train <- X.train[-rows.NAs.train,]}
if (length(rows.NAs.test)>0) {
X.test <- X.test[-rows.NAs.test,]
t.comp.actual <- t.comp.actual[-rows.NAs.test]
}

# ---- run sPCA
## train
spca.train = spca(X.train, ncomp = ncomp, keepX = c(keepX.opt, keepX.value), center = center, scale = FALSE)
Expand Down