Skip to content
Permalink
bb2670f44d
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
14 lines (13 sloc) 534 Bytes
### Function calculating number of PCs to be kept for batch identification and correction
# threshold for N of PCs: start at PC1 and keep including PCs until drop in explained variance from PCi to PCi+2 < 1%
# if threshold >2, include first 2 PCs (needed for plots)
# include max 10 PCs
pc_cutoff <- function(data){
for(i in 1:nrow(data)) {
if(i > 10) break
else if((data[i,]$var_explained - data[i + 2,]$var_explained) >=1) PC_number <- i
else if(PC_number < 2) PC_number = 2
else break
}
return(PC_number)
}