Skip to content

Commit

Permalink
Add Variance_Cumulative (explained variance) to summary of n_factors()
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueMakowski committed Nov 30, 2023
1 parent 90fa9de commit 87a8680
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions R/n_factors.R
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ n_factors <- function(x,
n_Methods = as.numeric(by(out, as.factor(out$n_Factors), function(out) n <- nrow(out)))
)

# Add cumulative percentage of variance explained
fa <- factor_analysis(x, cor=cor, n = max(by_factors$n_Factors)) # Get it from our fa:: wrapper (TODO: that's probably not the most efficient)

Check warning on line 344 in R/n_factors.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/n_factors.R,line=344,col=31,[infix_spaces_linter] Put spaces around all infix operators.

Check warning on line 344 in R/n_factors.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/n_factors.R,line=344,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 145 characters.
varex <- attributes(fa)$summary
# Extract number of factors from EFA output (usually MR1, ML1, etc.)
varex$n_Factors <- as.numeric(gsub("[^\\d]+", "", varex$Component, perl=TRUE))

Check warning on line 347 in R/n_factors.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/n_factors.R,line=347,col=74,[infix_spaces_linter] Put spaces around all infix operators.
by_factors <- merge(by_factors, varex[, c("n_Factors", "Variance_Cumulative")], by = "n_Factors")


attr(out, "summary") <- by_factors
attr(out, "n") <- min(as.numeric(as.character(
by_factors[by_factors$n_Methods == max(by_factors$n_Methods), "n_Factors"]
Expand Down

0 comments on commit 87a8680

Please sign in to comment.