Extract from az, with correlation

Dear all
I am using a model to estimate 6 parameters
Later, I would like to extract 100 values from the trace to use them as an input in a function

To achieve this, I’m performing the following steps in a loop:

var_t = az.extract(trace,var_names=["a","b","c","d","f","g"], num_samples=1)
res=model((temp[1])[i],(temp[3])[i],var_t["b"],var_t["d"],var_t["a"],var_t["c"],var_t["f"],var_t["g"]))

Anyway I was wondering if, by extracting the values in this way, I’m assuming that all the variables are independent. If that is the case, is there a way to extract the values while considering the correlation between parameters?

The relationships between the variables are determined by the posterior from which your model samples. Arviz, for its part, is just pulling out lists of numbers, so there’s nothing to take into consideration at that point. If the samples from the variables’ marginal posterior distributions are correlated, that will be captured in the samples (lists of numbers) that you are extracting.

You can visually inspect if there are any correlations by looking at pair plots, using az.plot_pair. Even if your priors are independent, it doesn’t necessarily mean the posterior will be.

But this doesn’t necessarily mean that specifically the last 100 samples from the trace will be correlated, because these 100 samples might not reflect the full posterior. In general, it’s discouraged to discard parts of the trace, in order to avoid accidentally discarding information about the posterior.

1 Like