df.csv (94.7 KB)

Hello,

I’m just curious to know why I’m getting two different results in the Mixture of regression. I tried to standardize the data but still obtained different results from the two model setups. Below are codes used in the analysis. I have also attached the data.

Model 1:

```
k = 2
with pm.Model() as Mixture_regression1:
# Priors for weight parameter
π1 = pm.Uniform('π1', 0, 1)
π2 = pm.Deterministic('π2', 1. - π1)
# Priors for unknown model parameters
α1 = pm.Normal('α1', mu=0, sd=100) #Intercept
β1 = pm.Normal('β1', mu=0, sd=100)
σ1 = pm.HalfCauchy('σ1', 5) #Noise
α2 = pm.Normal('α2', mu=0, sd=100) #Intercept
β2 = pm.Normal('β2', mu=0, sd=100)
σ2 = pm.HalfCauchy('σ2', 5) #Noise
μ1 = α1 + β1*X
μ2 = α2 + β2*X
mu = T.stack([μ1, μ2]).T
sd = T.stack([σ1, σ2])
π = T.stack([π1, π2])
likelihood = pm.NormalMixture('likelihood', π, mu, sd=sd, observed=Y)
```

Model 1 results:

Model 2:

```
n = X.shape[0]
with pm.Model() as Mixture_regression2:
# Proportion in each mixture
π = pm.Dirichlet('π', np.array([1]*k), testval=np.ones(k)/k)
# Priors for unknown model parameters
α = pm.Normal('α', mu=Y.mean(), sd=100,shape=k) #Intercept
β = pm.Normal('β', mu=0, sd=100, shape=k)
σ = pm.HalfCauchy('σ', 5,shape=k) #Noise
# Classifying each observation
category = pm.Categorical('category', p=π, shape=n)
α1 = pm.Deterministic('α1', α[category])
β1 = pm.Deterministic('β1', β[category])
σ1 = pm.Deterministic('σ1', σ[category])
μ = α1 + β1*X
# Likelihood
likelihood = pm.Normal('likelihood', mu=μ, sd=σ1, observed=Y)
step1 = pm.Metropolis([π, α, β, σ])
step2 = pm.ElemwiseCategorical([category], values=range(k))
trace = pm.sample(niter, [step1, step2], random_seed=1345, progressbar=True)
```

Model 2 results:

Thank you for the help!