arviz.InferenceData.rename_vars#

InferenceData.rename_vars(name_dict=None, groups=None, filter_groups=None, inplace=False)[source]#

Perform xarray renaming of variable or coordinate names on all groups.

Loops groups to perform Dataset.rename_vars(name_dict) for every key in name_dict if key is a variable or coordinate names of the dataset. The renaming is performed on all relevant groups (like posterior, prior, sample stats) while non relevant groups like observed data are omitted. See xarray.Dataset.rename_vars()

Parameters
name_dict: dict

Dictionary whose keys are current variable or coordinate names and whose values are the desired names.

groups: str or list of str, optional

Groups where the selection is to be applied. Can either be group names or metagroup names.

filter_groups: {None, “like”, “regex”}, optional, default=None

If None (default), interpret groups as the real group or metagroup names. If “like”, interpret groups as substrings of the real group or metagroup names. If “regex”, interpret groups as regular expressions on the real group or metagroup names. A la pandas.filter.

inplace: bool, optional

If True, modify the InferenceData object inplace, otherwise, return the modified copy.

Returns
InferenceData

A new InferenceData object with renamed variables including coordinates by default. When inplace==True perform renaming in-place and return None

See also

xarray.Dataset.rename_vars

Returns a new object with renamed variables including coordinates.

rename

Perform xarray renaming of variable and dimensions on all groups of an InferenceData object.

rename_dims

Perform xarray renaming of dimensions on all groups of InferenceData object.

Examples

Use rename_vars to renaming of variable and coordinates on all groups of the InferenceData object. We first check the data variables of original object:

In [1]: import arviz as az
   ...: idata = az.load_arviz_data("rugby")
   ...: print(list(idata.posterior.data_vars))
   ...: print(list(idata.prior.data_vars))
   ...: 
['home', 'intercept', 'atts_star', 'defs_star', 'sd_att', 'sd_def', 'atts', 'defs']
['sd_att_log__', 'intercept', 'atts_star', 'defs_star', 'away_points', 'sd_att', 'sd_def_log__', 'home', 'atts', 'sd_def', 'home_points', 'defs']

In order to rename the data variables, we use:

In [2]: idata.rename_vars({"home": "home_new"}, inplace=True)
   ...: print(list(idata.posterior.data_vars))
   ...: print(list(idata.prior.data_vars))
   ...: 
['home_new', 'intercept', 'atts_star', 'defs_star', 'sd_att', 'sd_def', 'atts', 'defs']
['sd_att_log__', 'intercept', 'atts_star', 'defs_star', 'away_points', 'sd_att', 'sd_def_log__', 'home_new', 'atts', 'sd_def', 'home_points', 'defs']