# MultivariateStats - Factor Analysis - transform/reconstruct not working?

**URL:** <https://discourse.julialang.org/t/multivariatestats-factor-analysis-transform-reconstruct-not-working/70505>\
**Category:** Statistics\
**Created:** [October 27, 2021, 7:47pm UTC](https://discourse.julialang.org/t/multivariatestats-factor-analysis-transform-reconstruct-not-working/70505 "2021-10-27T19:47:10Z")\
**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 27, 2021, 7:47pm UTC](https://discourse.julialang.org/t/multivariatestats-factor-analysis-transform-reconstruct-not-working/70505/1 "2021-10-27T19:47:10Z")

</div>

In factor analysis transforming observations into latent variables or reconstructing observations from latent variables seem to be not working? ([Factor Analysis — MultivariateStats 0.1.0 documentation](https://multivariatestatsjl.readthedocs.io/en/stable/fa.html))

```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)
x1 = [1,0,0,0]
y1 = transform(M,x1)
ERROR: MethodError: no method matching transform(::FactorAnalysis{Float64}, ::Vector{Int64})
Closest candidates are:
  transform(::Whitening, ::AbstractVecOrMat{T} where T) at /Users/julio/.julia/packages/MultivariateStats/HTpHt/src/whiten.jl:38
  transform(::PCA{T}, ::AbstractVecOrMat{T}) where T<:Real at /Users/julio/.julia/packages/MultivariateStats/HTpHt/src/pca.jl:46
  transform(::PPCA{T}, ::AbstractVecOrMat{T}) where T<:Real at /Users/julio/.julia/packages/MultivariateStats/HTpHt/src/ppca.jl:22
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

y2 = [1,0,0,0]
x2 = reconstruct(M, y2)
ERROR: MethodError: no method matching reconstruct(::FactorAnalysis{Float64}, ::Vector{Int64})
Closest candidates are:
  reconstruct(::PCA{T}, ::AbstractVecOrMat{T}) where T<:Real at /Users/julio/.julia/packages/MultivariateStats/HTpHt/src/pca.jl:47
  reconstruct(::PPCA{T}, ::AbstractVecOrMat{T}) where T<:Real at /Users/julio/.julia/packages/MultivariateStats/HTpHt/src/ppca.jl:30
  reconstruct(::KernelPCA{T}, ::AbstractVecOrMat{T}) where T<:Real at /Users/julio/.julia/packages/MultivariateStats/HTpHt/src/kpca.jl:61
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[7]:1

```

---

<div class="post-metadata">

**Author:** ![trahflow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trahflow/32/30585_2.png) [@trahflow](https://discourse.julialang.org/u/trahflow)\
**Post date:** [November 7, 2021, 3:42pm UTC](https://discourse.julialang.org/t/multivariatestats-factor-analysis-transform-reconstruct-not-working/70505/3 "2021-11-07T15:42:24Z")

</div>

Hi @julio.ca2020 ,

> [@julio.ca2020](#):
>
> `x1 = [1,0,0,0]`

the problem is that you’re putting a vector of **integers** into `transform()`, but it wants a vector of **floats**.

(note that this is actually what the error says: `transform()` is not implemented for `Vector{Int64}`)

if you do

```julia
x1 = [1., 0., 0., 0.]

```

instead, it should work.
