# MultivariateStats - Factor Analysis not working for the :cm method?

**URL:** <https://discourse.julialang.org/t/multivariatestats-factor-analysis-not-working-for-the-cm-method/70418>\
**Category:** Statistics\
**Created:** [October 26, 2021, 4:56pm UTC](https://discourse.julialang.org/t/multivariatestats-factor-analysis-not-working-for-the-cm-method/70418 "2021-10-26T16:56:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![julio.ca2020](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@julio.ca2020](https://discourse.julialang.org/u/julio.ca2020)\
**Post date:** [October 26, 2021, 4:56pm UTC](https://discourse.julialang.org/t/multivariatestats-factor-analysis-not-working-for-the-cm-method/70418/1 "2021-10-26T16:56:44Z")

</div>

I am doing a factor analysis and I’ve noticed that the method :em works in all cases but not the :cm (default). Why this?

This works for example:

```julia
using MultivariateStats
X = [0.635098 0.548183 0.211851 0.171408 0.877398;
 0.348466 0.498276 0.00646129 0.374103 0.21937;
 0.172254 0.593525 0.319492 0.706334 0.51062;
 0.994453 0.542042 0.155406 0.165663 0.196073]
M = fit(FactorAnalysis, X; maxoutdim=4, method=:em)
Factor Analysis(indim = 4, outdim = 4)

```

But this one does not:

```julia
M = fit(FactorAnalysis, X; maxoutdim=4, method=:cm)
ERROR: DomainError with -0.9992656414512631:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(f::Symbol, x::Float64)
   @ Base.Math ./math.jl:33
 [2] sqrt(x::Float64)
   @ Base.Math ./math.jl:582
 [3] facm(S::Matrix{Float64}, mv::Vector{Float64}, n::Int64; maxoutdim::Int64, tol::Float64, η::Float64, maxiter::Int64)
   @ MultivariateStats ~/.julia/packages/MultivariateStats/HTpHt/src/fa.jl:119
 [4] fit(::Type{FactorAnalysis}, X::Matrix{Float64}; method::Symbol, maxoutdim::Int64, mean::Nothing, tol::Float64, η::Float64, maxiter::Int64)
   @ MultivariateStats ~/.julia/packages/MultivariateStats/HTpHt/src/fa.jl:173
 [5] top-level scope
   @ REPL[10]:1

```

---

<div class="post-metadata">

**Author:** ![julio.ca2020](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@julio.ca2020](https://discourse.julialang.org/u/julio.ca2020)\
**Post date:** [November 3, 2021, 10:48pm UTC](https://discourse.julialang.org/t/multivariatestats-factor-analysis-not-working-for-the-cm-method/70418/2 "2021-11-03T22:48:08Z")

</div>

Is someone of the MultivariateStats team working on this issue and other issues already open almost 2 years ago?
