Hello,

I’m trying to an analysis similar to one in the example notebook `factor_analysis`

(you can find it here). The example does a good job of showing how to fit a model with `k`

latent variables (2 in the example) if your data was generated from a latent vaiable model using the same `k`

.

However, what we want from a factor analysis is usually more than that. We would like it to converge also for values of `k`

that are not the correct value and then to prefer the model with the correct number of random variables.

To explore this, I changed the number of latent variables from 2 to 3 between the simulation and the fit in the notebook. Thus, we are trying to fit a variable with 3 latent variables to data that only had 2 latent variables. This does not converge (see below). Does anyone have ideas on how best to fix it?

I’m only including the changed code and the output of the effort to fit the model.

Changed code:

```
k = 3
coords = {"latent_columns": np.arange(k), "rows": np.arange(n), "observed_columns": np.arange(d)}
with pm.Model(coords=coords) as PPCA_identified:
W = makeW(d, k, ("observed_columns", "latent_columns"))
F = pm.Normal("F", dims=("latent_columns", "rows"))
psi = pm.HalfNormal("psi", 1.0)
X = pm.Normal("X", mu=at.dot(W, F), sigma=psi, observed=Y, dims=("observed_columns", "rows"))
trace = pm.sample(tune=2000, cores=1, chains=4) # target_accept=0.9
for i in trace.posterior.chain:
samples = trace.posterior["W"].sel(chain=i, observed_columns=3, latent_columns=1)
plt.plot(samples, label="Chain {}".format(i + 1))
plt.legend(ncol=4, loc="lower center", fontsize=8), plt.xlabel("Sample");
```

## Output. Click to open

```
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Sequential sampling (4 chains in 1 job)
NUTS: [W_z, W_b, F, psi]
100.00% [3000/3000 01:36<00:00 Sampling chain 0, 103 divergences]
100.00% [3000/3000 01:39<00:00 Sampling chain 1, 6 divergences]
100.00% [3000/3000 01:38<00:00 Sampling chain 2, 91 divergences]
100.00% [3000/3000 01:56<00:00 Sampling chain 3, 91 divergences]
Sampling 4 chains for 2_000 tune and 1_000 draw iterations (8_000 + 4_000 draws total) took 411 seconds.
There were 103 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.689, but should be close to 0.8. Try to increase the number of tuning steps.
There were 109 divergences after tuning. Increase `target_accept` or reparameterize.
There were 200 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.6792, but should be close to 0.8. Try to increase the number of tuning steps.
There were 291 divergences after tuning. Increase `target_accept` or reparameterize.
The acceptance probability does not match the target. It is 0.6768, but should be close to 0.8. Try to increase the number of tuning steps.
c:\miniconda3\envs\pymc-examples\lib\site-packages\IPython\core\events.py:89: UserWarning: constrained_layout not applied because axes sizes collapsed to zero. Try making figure larger or axes decorations smaller.
func(*args, **kwargs)
c:\miniconda3\envs\pymc-examples\lib\site-packages\IPython\core\pylabtools.py:151: UserWarning: constrained_layout not applied because axes sizes collapsed to zero. Try making figure larger or axes decorations smaller.
fig.canvas.print_figure(bytes_io, **kw)
![output|690x332](upload://v9WPjqiAt7Abuyv4HFlJcDIg6pw.png)
```