# Prediction new data

Hi,

I am new with this library, and I have been reading an article, which use this model:

``````with pm.Model(coords=coords) as model_hierar:
# Define hyperpriors
mu_beta = pm.Normal('mu_beta', mu=0, sd=0.01)
sd_beta = pm.HalfNormal('sd_beta', sd=1)
# Define priors
beta_bdnf = pm.Normal('beta_bdnf', mu=mu_beta, sd=sd_beta, shape=(6,1))
beta_syn = pm.Normal('beta_syn', mu=mu_beta, sd=sd_beta, shape=(2,1))
beta_nnf = pm.Normal('beta_nnf', mu=mu_beta, sd=sd_beta, shape=(4,1))

# Imputation of X missing values for BDNF
Xmu_bdnf = pm.Normal('Xmu_bdnf', mu=0, sd=0.01, shape=(1,6))
Xsigma_bdnf = pm.HalfNormal('Xsigma_bdnf', sd=1, shape=(1,6))
X_bdnf_modelled = pm.Normal('X_bdnf_modelled',
mu=Xmu_bdnf, sigma=Xsigma_bdnf, observed=X_bdnf_train)

# Likelihood for BDNF
# SLogP, Cbrain/Cblood, BBB, Pgp->BDNF
lp_bdnf = pm.Deterministic('lp_bdnf', pm.math.dot(X_bdnf_modelled, beta_bdnf))
y_obs_bdnf = pm.Bernoulli('y_obs_bdnf', logit_p=lp_bdnf, observed=Y_bdnf_train)

# Imputation of X missing values for SYN
Xmu_syn = pm.Normal('Xmu_syn', mu=0, sd=0.01, shape=(1,2))
Xsigma_syn = pm.HalfNormal('Xsigma_syn', sd=1, shape=(1,2))
X_syn_modelled = pm.Normal('X_syn_modelled',
mu=Xmu_syn, sigma=Xsigma_syn, observed=X_syn_train)

# Likelihood for SYN
# BDNF->SYN
lp_syn = pm.Deterministic('lp_syn', lp_bdnf + pm.math.dot(X_syn_modelled, beta_syn))
y_obs_syn = pm.Bernoulli("y_obs_syn", logit_p=lp_syn, observed=Y_syn)

# Imputation of X missing values for NNF
Xmu_nnf = pm.Normal('Xmu_nnf', mu=0, sd=0.01, shape=(1,4))
Xsigma_nnf = pm.HalfNormal('Xsigma_nnf', sd=1, shape=(1,4))
X_nnf_modelled = pm.Normal('X_nnf_modelled',
mu=Xmu_nnf, sd=Xsigma_nnf, observed=X_nnf_train)

# Likelihood for NNF
# BDNF->SYN->NNF
lp_nnf = pm.Deterministic('lp_nnf', lp_syn + pm.math.dot(X_nnf_modelled, beta_nnf))
y_obs_nnf = pm.Bernoulli("y_obs_nnf", logit_p=lp_nnf, observed=Y_nnf)

# Define causal relationships for DNT
lp_dnt = pm.Deterministic('lp_dnt', lp_bdnf + lp_syn + lp_nnf)
y_obs_dnt = pm.Bernoulli('y_obs_dnt', logit_p=lp_dnt, observed=Y_dnt)
#     trace_hierar = pm.sample(cores=1, draws=10000, nuts ={'target_accept':0.90})
#     idata_pow = az.from_pymc3(trace_hierar, dims=dims)
# Checking the proposed structure of model
model_hierar.check_test_point()
``````

How is it possible predict new data??? I have read something about I would have to transform my new data with pm.Data and after use set_data. But Could you help me with code for an example like this?

Thanks

1 Like

Welcome!

I think it would probably be easier to start with a simplified version of your model. Once you/we work out how to incorporated `pm.Data`, then you can build things back up to where you need them to be. So would it be possible to get a simpler version of your model to work on?