bebi103.hmc.extract_variable

bebi103.hmc.extract_variable(samples, variable, inc_warmup=False, one_indexed=True)

Extracts sample of a variable as a Numpy array.

Parameters:
  • samples (dict or cmdstanpy.CmdStanMCMC instance) – MCMC samples as either a dictionary where each entry is a 2D Numpy array or a cmdstanpy.CmdStanMCMC instance

  • variable (string) – The name of the variable to extract

  • inc_warmup (bool, default False) – If True, include warmup when extracting from a cmdstanpy.CmdStanMCMC instance. Ignored if samples is a dict.

  • one_indexed (bool, default True) – True if the bracketed indices in the keys of samples start at 1, as is the case with Stan, and False if they start at 0.

Returns:

output – The first dimension of the output is the chain. The second is the draw. If the variable is scalar, the result is two- dimensional. If the variable is vector-valued, the third dimension is the index of the dimension of the vector. If the variable is matrix-valued, the third and fourth dimensions are the matrix indices. And so on.

Return type:

Numpy array of at least two dimensions