Learn R Programming

rosetta (version 0.3.12)

factorAnalysis: Factor analysis or principal component analysis

Description

This is a wrapper for the psych functions psych::pca() and psych::fa() to produce output that it similar to the output produced by jamovi.

Usage

factorAnalysis(
  data,
  nfactors,
  items = names(data),
  rotate = "oblimin",
  covar = FALSE,
  na.rm = TRUE,
  kaiser = 1,
  loadings = TRUE,
  summary = FALSE,
  correlations = FALSE,
  modelFit = FALSE,
  eigenValues = FALSE,
  screePlot = FALSE,
  residuals = FALSE,
  itemLabels = items,
  colorLoadings = FALSE,
  fm = "minres",
  digits = 2,
  headingLevel = 3,
  ...
)

principalComponentAnalysis( data, items, nfactors, rotate = "oblimin", covar = FALSE, na.rm = TRUE, kaiser = 1, loadings = TRUE, summary = FALSE, correlations = FALSE, eigenValues = FALSE, screePlot = FALSE, residuals = FALSE, itemLabels = items, colorLoadings = FALSE, digits = 2, headingLevel = 3, ... )

rosettaDataReduction_partial( x, digits = x$input$digits, headingLevel = x$input$headingLevel, echoPartial = FALSE, partialFile = NULL, quiet = TRUE, ... )

# S3 method for rosettaDataReduction knit_print( x, digits = x$input$digits, headingLevel = x$input$headingLevel, echoPartial = FALSE, partialFile = NULL, quiet = TRUE, ... )

# S3 method for rosettaDataReduction print( x, digits = x$input$digits, headingLevel = x$input$headingLevel, forceKnitrOutput = FALSE, ... )

Value

An object with the object resulting from the call to the psych functions and some extracted information that will be printed.

Arguments

data

The data frame that contains the items.

nfactors

The number of factors to extract, or 'eigen' to extract all factors with an eigen value higher than the number specified in kaiser. In the future, parallel can be specified here to extract the number of factors suggested by parallel analysis.

items

The items to analyse; if not specified, all variables in data will be used.

rotate

Which rotation to use; see psych::fa() for all options. The most common options are 'none' to not rotate at all; 'varimax' for an orthogonal rotation (assuming/imposing that the components or factors are not correlated); or 'oblimin' for an oblique rotation (allowing the components/factors to correlate).

covar

Whether to analyse the correlation matrix (FALSE) or the covariance matrix (TRUE).

na.rm

Whether to first remove all cases with missing values.

kaiser

The minimum eigenvalue when applying the Kaiser criterion (see nfactors).

loadings

Whether to display the component or factor loadings.

summary

Whether to display the factor or component summary.

correlations

Whether to display the correlations between factors of components.

modelFit

Whether to display the model fit Only for EFA).

eigenValues

Whether to display the eigen values.

screePlot

Whether to display the scree plot.

residuals

Whether to display the matrix with residuals.

itemLabels

Optionally, labels to use for the items (optionally, named, with the names corresponding to the items; otherwise, the order of the labels has to match the order of the items)

colorLoadings

Whether, when producing an Rmd partial (i.e. when calling the command while knitting) to colour the cells using kableExtra::kable_styling().

fm

The method to use for the factor analysis: 'fm' for Minimum Residuals; 'ml' for Maximum Likelihood; and 'pa' for Principal Factor.

digits

The number of digits to round to.

headingLevel

The number of hashes to print in front of the headings when printing while knitting

...

Any additional arguments are passed to psych::fa(), psych::pca(), to the default print method by the print method, and to rmdpartials::partial() when knitting an RMarkdown partial.

x

The object to print.

echoPartial

Whether to show the executed code in the R Markdown partial (TRUE) or not (FALSE).

partialFile

This can be used to specify a custom partial file. The file will have object x available.

quiet

Passed on to knitr::knit() whether it should b chatty (FALSE) or quiet (TRUE).

forceKnitrOutput

Force knitr output.

Details

The code in these functions uses parts of the code in jamovi, written by Jonathon Love and Ravi Selker.

Examples

Run this code
### Load example dataset
data("pp15", package="rosetta");

### Get variable names with expected
### effects of a high dose of MDMA
items <-
  grep(
    "highDose_AttBeliefs_",
    names(pp15),
    value=TRUE
  );

### Do a factor analysis
rosetta::factorAnalysis(
  data = pp15,
  items = items,
  nfactors = "eigen",
  scree = TRUE
);

if (FALSE) {
  ### To get more output, show the
  ### output as Rmd Partial in the viewer,
  ### and color/size the factor loadings
  rosetta::rosettaDataReduction_partial(
    rosetta::factorAnalysis(
      data = pp15,
      items = items,
      nfactors = "eigen",
      summary = TRUE,
      correlations = TRUE,
      colorLoadings = TRUE
    )
  );
}

Run the code above in your browser using DataLab