You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Plotting functions such as plot_posterior() and plot_trace() identify coordinates in variables by their coordinate names. But summary() does not. Using coordinate names in the summary() method would result in clearer output.
Code to demonstrate:
import pystan
import arviz
import numpy
print(arviz.__version__)
code = """
data {
int<lower=1> N;
int<lower=1> P;
vector[N] y;
matrix[N,P] X;
}
parameters {
vector[P] beta;
real alpha;
real<lower=0> sigma;
}
model {
beta ~ std_normal();
alpha ~ std_normal();
sigma ~ cauchy(0, 1) T[0,];
y ~ normal_id_glm(X, alpha, beta, sigma);
}
"""
# Compile model
model = pystan.StanModel(model_code=code)
#### Data
# Dimensions
P = 4
N = 200
# Parameters
alpha = 1
beta = numpy.array(range(P)) - (P - 1)/2
sigma = 2
# Data
rg = numpy.random.default_rng()
X = rg.normal(size=(N,P))
y = numpy.matmul(X, beta) + alpha + rg.normal(scale=sigma, size=N)
# Sample
fit = model.sampling(
data={'N':N, 'P':P, 'X':X, 'y':y},
init='random', n_jobs=1,
pars=['alpha','beta','sigma'])
samples = arviz.from_pystan(fit,
observed_data='y',
constant_data='X',
coords={'observation':list(range(200)),
'covariate':['A','B','C','D']},
dims={'y':['observation'],
'beta':['covariate'],
'X':['observation','covariate']})
arviz.plot_posterior(samples)
arviz.plot_trace(samples)
print(arviz.summary(samples))
If changing the structure of the data frame would cause unwanted side effects, then I think the simplest approach could be the first alternate output, replacing "0", "1", etc with the coordinate names in the text of the index. No extra columns or multiindex would be needed in that case.
Plotting functions such as
plot_posterior()
andplot_trace()
identify coordinates in variables by their coordinate names. Butsummary()
does not. Using coordinate names in the summary() method would result in clearer output.Code to demonstrate:
Output
0.6.1
Desired output
(plots unchanged)
Alternatively, a pandas multiindex could be used:
The text was updated successfully, but these errors were encountered: