fspe: Estimating number of factors with out-of-sample prediction...

View source: R/fspe.R

fspeR Documentation

Estimating number of factors with out-of-sample prediction error

Description

Estimates the number of factors in Exploratory Factor Analysis (EFA) by approximating the out-of-sample prediction errors using a cross-validation scheme.

Usage

fspe(data, maxK, nfold = 10, rep = 1, method = "PE",
     rotate = "oblimin", pbar = TRUE, ...)

Arguments

data

A n x p matrix or data.frame.

maxK

The largest number of factors considered. For example, if maxK = 8, the factors 1, 2, ..., 8 are considered.

nfold

The number of folds in the cross-validation scheme. Defaults to nfold = 10.

rep

The number of repetitions of the cross-validation scheme. The repetiations are aggregated by averaging the prediction errors for each number of factor and subsequently selecting the number of factors that minimizes this average. Defaults to rep = 1.

method

If method = "PE", the factor estimation is based on the prediction error on the variables; If method = "Cov" the error is computed on the covariance matrix. Defaults to method = "PE" since it has performed better in simulations (see Haslbeck & van Bork, 2021 below.)

rotate

The totation being used in the underlying factor analysis models. The options are the same as in the fa() function in the psych package, which is called by fpse. Defaults to rotate = "oblimin".

pbar

If pbar = TRUE, a progress bar is shown.

...

Additional arguments passed to the fa() function in the psych package.

Details

The function returns:

Value

nfactor

An integer indicating the estimated number of factors.

nfactor

A 4-dimensional (for the PE method: variables, candidate models, folds, repetitions) or a 3-dimensional (for the Cov method: candidate models, folds, repetitions) array containing all prediction errors.

Author(s)

Jonas Haslbeck <jonashaslbeck@gmail.com>

References

Haslbeck & van Bork (2021). Estimating the number of factors in Exploratory Factor Analysis using out-of-sample prediction errors. PsyArXiv Preprint: https://psyarxiv.com/qktsd

Examples



data(holzinger19)

fspe_out <- fspe(holzinger19,
                 maxK = 10,
                 nfold = 10,
                 method = "PE")

fspe_out$nfactor # estimated factors = 4

# Plot OoS PE path
plot(fspe_out$PEs, xlab="No. Factors", ylab="OoS PE")



fspe documentation built on March 31, 2023, 5:15 p.m.

Related to fspe in fspe...