fa

package
v0.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

fa/GPArotation_GPFoblq.go

fa/GPArotation_GPForth.go

fa/GPArotation_vgQ_bentler.go

fa/GPArotation_vgQ_geomin.go

fa/GPArotation_vgQ_oblimin.go

fa/GPArotation_vgQ_quartimax.go

fa/GPArotation_vgQ_quartimin.go

fa/GPArotation_vgQ_simplimax.go

fa/GPArotation_vgQ_target.go

fa/GPArotation_vgQ_varimax.go

fa/fa.go

fa/factor2cluster.go

fa/kaiser_varimax.go

fa/psych_Promax.go

fa/psych_faRotations.go

fa/psych_fac.go

fa/psych_pinv.go

fa/psych_smc.go

fa/psych_target_rot.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BentlerQ

func BentlerQ(loadings *mat.Dense, normalize bool, eps float64, maxIter int) map[string]any

BentlerQ performs Bentler's criterion rotation (oblique). Mirrors GPArotation::bentlerQ

func BentlerT

func BentlerT(loadings *mat.Dense, normalize bool, eps float64, maxIter int) map[string]any

BentlerT performs Bentler's criterion rotation. Mirrors GPArotation::bentlerT

func CorrelationMatrix

func CorrelationMatrix(data *mat.Dense) *mat.Dense

CorrelationMatrix computes correlation matrix from data matrix This is a simplified version - full implementation would handle NAs

func CorrelationMatrixPairwise

func CorrelationMatrixPairwise(data *mat.Dense) *mat.Dense

CorrelationMatrixPairwise computes correlation matrix using pairwise complete observations

func CovarianceMatrix

func CovarianceMatrix(data *mat.Dense) *mat.Dense

CovarianceMatrix computes covariance matrix from data matrix

func CovarianceMatrixPairwise

func CovarianceMatrixPairwise(data *mat.Dense) *mat.Dense

CovarianceMatrixPairwise computes covariance matrix using pairwise complete observations

func FaRotations

func FaRotations(loadings *mat.Dense, r *mat.Dense, rotate string, hyper float64, nRotations int) any

FaRotations performs rotation selection with optional random restarts.

func Factor2Cluster

func Factor2Cluster(loadings *mat.Dense, opts *Factor2ClusterOptions) *mat.Dense

Factor2Cluster creates a cluster structure from factor loadings. Mirrors GPArotation::factor2cluster exactly

For each variable, assign it to the factor with the highest absolute loading if that loading exceeds the cut threshold. Otherwise, assign to no cluster (0).

func Factor2ClusterSimple

func Factor2ClusterSimple(loadings *mat.Dense) *mat.Dense

Factor2ClusterSimple is a backward-compatible wrapper for Factor2Cluster

func GPFoblq

func GPFoblq(A *mat.Dense, Tmat *mat.Dense, normalize bool, eps float64, maxit int, method string, gamma float64) (map[string]any, error)

GPFoblq performs oblique GPA rotation. Transliteration of GPArotation::GPFoblq from R.

func GPForth

func GPForth(A *mat.Dense, Tmat *mat.Dense, normalize bool, eps float64, maxit int, method string) (map[string]any, error)

GPForth performs orthogonal rotation using GPA. Mirrors GPArotation::GPForth exactly

func GeominQ

func GeominQ(loadings *mat.Dense, normalize bool, eps float64, maxIter int, delta float64) map[string]any

GeominQ performs geomin rotation (oblique). Mirrors GPArotation::geominQ

func GeominT

func GeominT(loadings *mat.Dense, normalize bool, eps float64, maxIter int, delta float64) map[string]any

GeominT performs geomin rotation. Mirrors GPArotation::geominT

func KaiserVarimax

func KaiserVarimax(A *mat.Dense, normalize bool, maxIter int, epsilon float64) (*mat.Dense, error)

KaiserVarimax performs Varimax rotation using the classic Jacobi rotation method as described in Kaiser (1958) and implemented in SPSS.

This method differs from GPArotation's gradient-based approach: - Uses pairwise Givens rotations instead of gradient projection - Iterates through all factor pairs until convergence - More closely matches SPSS output

References: Kaiser, H. F. (1958). The varimax criterion for analytic rotation in factor analysis. Psychometrika, 23(3), 187-200.

Algorithm: 1. Apply Kaiser normalization (row normalize by sqrt of communality) 2. For each pair of factors (p, q):

  • Compute optimal rotation angle θ that maximizes variance of squared loadings
  • Apply Givens rotation to factors p and q

3. Repeat until convergence 4. Denormalize by multiplying back by sqrt of communality

func KaiserVarimaxWithRotationMatrix

func KaiserVarimaxWithRotationMatrix(A *mat.Dense, normalize bool, maxIter int, epsilon float64) (*mat.Dense, *mat.Dense, error)

KaiserVarimaxWithRotationMatrix returns both the rotated loadings and the rotation matrix

func NormalizingWeight

func NormalizingWeight(A *mat.Dense, normalize bool) *mat.VecDense

NormalizingWeight computes normalizing weights for GPA rotation. Mirrors GPArotation::NormalizingWeight for Kaiser normalization.

func Oblimin

func Oblimin(loadings *mat.Dense, normalize bool, eps float64, maxIter int, gamma float64) map[string]any

Oblimin performs oblimin rotation. Mirrors GPArotation::oblimin

func ParseRotationResult

func ParseRotationResult(res any) (loadings, rotmat, phi *mat.Dense, f float64, ok bool)

ParseRotationResult accepts the opaque result value returned by FaRotations (or individual rotation functions) and returns typed pointers to the rotated loadings, rotation matrix (rotmat), Phi (may be nil for orthogonal rotations), the objective f and a bool indicating success. This helper centralizes key extraction so callers can programmatically compare matrices (e.g. against SPSS reference).

func Pinv

func Pinv(X *mat.Dense, tol float64) (*mat.Dense, error)

Pinv computes the Moore-Penrose pseudo-inverse of a matrix. Mirrors psych::Pinv exactly

func Promax

func Promax(x *mat.Dense, m int, normalize bool) map[string]any

Promax performs Promax rotation. Mirrors psych::Promax exactly

func Quartimax

func Quartimax(loadings *mat.Dense, normalize bool, eps float64, maxIter int) map[string]any

Quartimax performs quartimax rotation. Mirrors GPArotation::quartimax

func Quartimin

func Quartimin(loadings *mat.Dense, normalize bool, eps float64, maxIter int) map[string]any

Quartimin performs quartimin rotation. Mirrors GPArotation::quartimin

func Rotate

func Rotate(loadings *mat.Dense, method string, opts *RotOpts) (*mat.Dense, *mat.Dense, *mat.Dense, bool, error)

Rotate performs factor rotation on loadings. This is a wrapper around FaRotations for compatibility.

func RotateWithDiagnostics

func RotateWithDiagnostics(loadings *mat.Dense, method string, opts *RotOpts) (*mat.Dense, *mat.Dense, *mat.Dense, bool, map[string]interface{}, error)

RotateWithDiagnostics performs factor rotation on loadings with diagnostics. Returns rotated loadings, rotation matrix, Phi matrix, convergence status, and diagnostics map.

func SMC

func SMC(r *mat.Dense, isCorr bool) (*mat.VecDense, error)

SMC computes the squared multiple correlations for a correlation matrix. This is a wrapper around Smc for compatibility.

func Simplimax

func Simplimax(loadings *mat.Dense, normalize bool, eps float64, maxIter int, k int) map[string]any

Simplimax performs simplimax rotation. Mirrors GPArotation::simplimax

func Smc

func Smc(r *mat.Dense, opts *SmcOptions) (*mat.VecDense, map[string]interface{})

Smc computes the squared multiple correlations (SMC) for a correlation matrix. Mirrors psych::smc with complete NA handling and covar/pairwise options

func TargetRot

func TargetRot(x *mat.Dense, keys *mat.Dense) (loadings, rotmat, Phi *mat.Dense, err error)

TargetRot performs target rotation on an unrotated loading matrix x. Mirrors psych::target.rot exactly

func TargetRotWithMask

func TargetRotWithMask(x *mat.Dense, keys *mat.Dense, mask *mat.Dense) (loadings, rotmat, Phi *mat.Dense, diagnostics map[string]interface{}, err error)

TargetRotWithMask performs target rotation with optional mask for target matrix elements. Elements marked with NaN in the mask are excluded from the alignment process.

func Varimax

func Varimax(loadings *mat.Dense, normalize bool, eps float64, maxIter int) map[string]any

Varimax performs varimax rotation. Mirrors GPArotation::Varimax

func VgQOblimin

func VgQOblimin(L *mat.Dense, gamma float64) (*mat.Dense, float64, error)

VgQOblimin is the exported version for testing

Types

type FacOptions

type FacOptions struct {
	NFactors      int
	NObs          float64
	Rotate        string
	Scores        string
	Residuals     bool
	SMC           interface{} // bool or []float64
	Covar         bool
	Missing       bool
	Impute        string
	MinErr        float64
	MaxIter       int
	Symmetric     bool
	Warnings      bool
	Fm            string
	Alpha         float64
	ObliqueScores bool
	NpObs         *mat.Dense
	Use           string
	Cor           string
	Correct       float64
	Weight        []float64
	NRotations    int
	Hyper         float64
	Smooth        bool
}

FacOptions represents options for the Fac function

type FacResult

type FacResult struct {
	Values        []float64
	Rotation      string
	NObs          float64
	NpObs         *mat.Dense
	Communality   []float64
	Loadings      *mat.Dense
	Fit           float64
	Residual      *mat.Dense
	R             *mat.Dense
	Communalities []float64
	Uniquenesses  []float64
	EValues       []float64
	Model         *mat.Dense
	Fm            string
	RotMat        *mat.Dense
	Phi           *mat.Dense
	Structure     *mat.Dense
	Method        string
	Scores        *mat.Dense
	R2Scores      []float64
	Weights       *mat.Dense
	Factors       int
	Hyperplane    []float64
	Vaccounted    *mat.Dense
	ECV           []float64
}

FacResult represents the result of factor analysis

func Fac

func Fac(r *mat.Dense, opts *FacOptions) (*FacResult, error)

Fac performs factor analysis using various methods (mirrors psych::fac)

type Factor2ClusterOptions

type Factor2ClusterOptions struct {
	Cut              float64 // Loading threshold below which variables are not assigned to any cluster
	UseRLikePipeline bool    // If true, use R-like pipeline: varimax -> target.rot -> cluster
}

Factor2ClusterOptions represents options for Factor2Cluster

type RotOpts

type RotOpts struct {
	Eps         float64
	MaxIter     int
	Alpha0      float64
	Gamma       float64
	PromaxPower int
	Restarts    int
}

RotOpts represents rotation options

type SmcOptions

type SmcOptions struct {
	Covar    bool    // If true, use covariance matrix instead of correlation
	Pairwise bool    // If true, use pairwise correlations for NA handling
	Tol      float64 // Tolerance for matrix inversion
}

SmcOptions represents options for Smc function

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL