arviz_stats.kde#
- arviz_stats.kde(data, dim=None, group='posterior', var_names=None, filter_vars=None, coords=None, circular=False, **kwargs)[source]#
Compute the marginal kernel density estimates (KDE).
See the EABM chapter on Visualization of Random Variables with ArviZ for more details.
- Parameters:
- dataarray_like,
xarray.DataArray
,xarray.Dataset
,xarray.DataTree
,DataArrayGroupBy
,DatasetGroupBy
, or idata-like Input data. It will have different pre-processing applied to it depending on its type:
array-like: call array layer within
arviz-stats
.xarray object: apply dimension aware function to all relevant subsets
others: passed to
arviz_base.convert_to_dataset
then treated asxarray.Dataset
. This option is discouraged due to needing this conversion which is completely automated and will be needed again in future executions or similar functions.It is recommended to first perform the conversion manually and then call
arviz_stats.kde
. This allows controlling the conversion step and inspecting its results.
- dimsequence of
hashable
, optional Dimensions to be reduced when computing the KDE. Default
rcParams["data.sample_dims"]
.- group
hashable
, default “posterior” Group on which to compute the KDE
- var_names
str
orlist
ofstr
, optional Names of the variables for which the KDE should be computed.
- filter_vars{
None
, “like”, “regex”}, defaultNone
- coords
dict
, optional Dictionary of dimension/index names to coordinate values defining a subset of the data for which to perform the computation.
- circularbool, default
False
- **kwargs
any
, optional Forwarded to the array or dataarray interface for KDE.
- dataarray_like,
- Returns:
ndarray
,xarray.DataArray
,xarray.Dataset
,xarray.DataTree
Requested KDE of the provided input. The xarray objects will have a
kde_dim
dimension and aplot_axis
dimension with coordinates “x”, and “y”.
See also
arviz_stats.ecdf
,arviz_stats.histogram
,arviz_stats.qds
Alternative visual summaries for marginal distributions
arviz_plots.plot_dist
Examples
Calculate the KDE of a Normal random variable:
In [1]: import arviz_stats as azs ...: import numpy as np ...: data = np.random.default_rng().normal(size=2000) ...: azs.kde(data) ...: Out[1]: (array([-4.07801474e+00, -4.06344318e+00, -4.04887162e+00, -4.03430006e+00, -4.01972851e+00, -4.00515695e+00, -3.99058539e+00, -3.97601383e+00, -3.96144227e+00, -3.94687071e+00, -3.93229916e+00, -3.91772760e+00, -3.90315604e+00, -3.88858448e+00, -3.87401292e+00, -3.85944136e+00, -3.84486981e+00, -3.83029825e+00, -3.81572669e+00, -3.80115513e+00, -3.78658357e+00, -3.77201201e+00, -3.75744045e+00, -3.74286890e+00, -3.72829734e+00, -3.71372578e+00, -3.69915422e+00, -3.68458266e+00, -3.67001110e+00, -3.65543955e+00, -3.64086799e+00, -3.62629643e+00, -3.61172487e+00, -3.59715331e+00, -3.58258175e+00, -3.56801020e+00, -3.55343864e+00, -3.53886708e+00, -3.52429552e+00, -3.50972396e+00, -3.49515240e+00, -3.48058085e+00, -3.46600929e+00, -3.45143773e+00, -3.43686617e+00, -3.42229461e+00, -3.40772305e+00, -3.39315150e+00, -3.37857994e+00, -3.36400838e+00, -3.34943682e+00, -3.33486526e+00, -3.32029370e+00, -3.30572215e+00, -3.29115059e+00, -3.27657903e+00, -3.26200747e+00, -3.24743591e+00, -3.23286435e+00, -3.21829280e+00, -3.20372124e+00, -3.18914968e+00, -3.17457812e+00, -3.16000656e+00, -3.14543500e+00, -3.13086344e+00, -3.11629189e+00, -3.10172033e+00, -3.08714877e+00, -3.07257721e+00, -3.05800565e+00, -3.04343409e+00, -3.02886254e+00, -3.01429098e+00, -2.99971942e+00, -2.98514786e+00, -2.97057630e+00, -2.95600474e+00, -2.94143319e+00, -2.92686163e+00, -2.91229007e+00, -2.89771851e+00, -2.88314695e+00, -2.86857539e+00, -2.85400384e+00, -2.83943228e+00, -2.82486072e+00, -2.81028916e+00, -2.79571760e+00, -2.78114604e+00, -2.76657449e+00, -2.75200293e+00, -2.73743137e+00, -2.72285981e+00, -2.70828825e+00, -2.69371669e+00, -2.67914514e+00, -2.66457358e+00, -2.65000202e+00, -2.63543046e+00, -2.62085890e+00, -2.60628734e+00, -2.59171579e+00, -2.57714423e+00, -2.56257267e+00, -2.54800111e+00, -2.53342955e+00, -2.51885799e+00, -2.50428644e+00, -2.48971488e+00, -2.47514332e+00, -2.46057176e+00, -2.44600020e+00, -2.43142864e+00, -2.41685708e+00, -2.40228553e+00, -2.38771397e+00, -2.37314241e+00, -2.35857085e+00, -2.34399929e+00, -2.32942773e+00, -2.31485618e+00, -2.30028462e+00, -2.28571306e+00, -2.27114150e+00, -2.25656994e+00, -2.24199838e+00, -2.22742683e+00, -2.21285527e+00, -2.19828371e+00, -2.18371215e+00, -2.16914059e+00, -2.15456903e+00, -2.13999748e+00, -2.12542592e+00, -2.11085436e+00, -2.09628280e+00, -2.08171124e+00, -2.06713968e+00, -2.05256813e+00, -2.03799657e+00, -2.02342501e+00, -2.00885345e+00, -1.99428189e+00, -1.97971033e+00, -1.96513878e+00, -1.95056722e+00, -1.93599566e+00, -1.92142410e+00, -1.90685254e+00, -1.89228098e+00, -1.87770943e+00, -1.86313787e+00, -1.84856631e+00, -1.83399475e+00, -1.81942319e+00, -1.80485163e+00, -1.79028007e+00, -1.77570852e+00, -1.76113696e+00, -1.74656540e+00, -1.73199384e+00, -1.71742228e+00, -1.70285072e+00, -1.68827917e+00, -1.67370761e+00, -1.65913605e+00, -1.64456449e+00, -1.62999293e+00, -1.61542137e+00, -1.60084982e+00, -1.58627826e+00, -1.57170670e+00, -1.55713514e+00, -1.54256358e+00, -1.52799202e+00, -1.51342047e+00, -1.49884891e+00, -1.48427735e+00, -1.46970579e+00, -1.45513423e+00, -1.44056267e+00, -1.42599112e+00, -1.41141956e+00, -1.39684800e+00, -1.38227644e+00, -1.36770488e+00, -1.35313332e+00, -1.33856177e+00, -1.32399021e+00, -1.30941865e+00, -1.29484709e+00, -1.28027553e+00, -1.26570397e+00, -1.25113242e+00, -1.23656086e+00, -1.22198930e+00, -1.20741774e+00, -1.19284618e+00, -1.17827462e+00, -1.16370306e+00, -1.14913151e+00, -1.13455995e+00, -1.11998839e+00, -1.10541683e+00, -1.09084527e+00, -1.07627371e+00, -1.06170216e+00, -1.04713060e+00, -1.03255904e+00, -1.01798748e+00, -1.00341592e+00, -9.88844364e-01, -9.74272806e-01, -9.59701248e-01, -9.45129689e-01, -9.30558131e-01, -9.15986572e-01, -9.01415014e-01, -8.86843456e-01, -8.72271897e-01, -8.57700339e-01, -8.43128781e-01, -8.28557222e-01, -8.13985664e-01, -7.99414106e-01, -7.84842547e-01, -7.70270989e-01, -7.55699430e-01, -7.41127872e-01, -7.26556314e-01, -7.11984755e-01, -6.97413197e-01, -6.82841639e-01, -6.68270080e-01, -6.53698522e-01, -6.39126963e-01, -6.24555405e-01, -6.09983847e-01, -5.95412288e-01, -5.80840730e-01, -5.66269172e-01, -5.51697613e-01, -5.37126055e-01, -5.22554496e-01, -5.07982938e-01, -4.93411380e-01, -4.78839821e-01, -4.64268263e-01, -4.49696705e-01, -4.35125146e-01, -4.20553588e-01, -4.05982029e-01, -3.91410471e-01, -3.76838913e-01, -3.62267354e-01, -3.47695796e-01, -3.33124238e-01, -3.18552679e-01, -3.03981121e-01, -2.89409562e-01, -2.74838004e-01, -2.60266446e-01, -2.45694887e-01, -2.31123329e-01, -2.16551771e-01, -2.01980212e-01, -1.87408654e-01, -1.72837096e-01, -1.58265537e-01, -1.43693979e-01, -1.29122420e-01, -1.14550862e-01, -9.99793037e-02, -8.54077453e-02, -7.08361869e-02, -5.62646285e-02, -4.16930702e-02, -2.71215118e-02, -1.25499534e-02, 2.02160494e-03, 1.65931633e-02, 3.11647217e-02, 4.57362801e-02, 6.03078384e-02, 7.48793968e-02, 8.94509552e-02, 1.04022514e-01, 1.18594072e-01, 1.33165630e-01, 1.47737189e-01, 1.62308747e-01, 1.76880305e-01, 1.91451864e-01, 2.06023422e-01, 2.20594981e-01, 2.35166539e-01, 2.49738097e-01, 2.64309656e-01, 2.78881214e-01, 2.93452772e-01, 3.08024331e-01, 3.22595889e-01, 3.37167447e-01, 3.51739006e-01, 3.66310564e-01, 3.80882123e-01, 3.95453681e-01, 4.10025239e-01, 4.24596798e-01, 4.39168356e-01, 4.53739914e-01, 4.68311473e-01, 4.82883031e-01, 4.97454590e-01, 5.12026148e-01, 5.26597706e-01, 5.41169265e-01, 5.55740823e-01, 5.70312381e-01, 5.84883940e-01, 5.99455498e-01, 6.14027057e-01, 6.28598615e-01, 6.43170173e-01, 6.57741732e-01, 6.72313290e-01, 6.86884848e-01, 7.01456407e-01, 7.16027965e-01, 7.30599524e-01, 7.45171082e-01, 7.59742640e-01, 7.74314199e-01, 7.88885757e-01, 8.03457315e-01, 8.18028874e-01, 8.32600432e-01, 8.47171991e-01, 8.61743549e-01, 8.76315107e-01, 8.90886666e-01, 9.05458224e-01, 9.20029782e-01, 9.34601341e-01, 9.49172899e-01, 9.63744457e-01, 9.78316016e-01, 9.92887574e-01, 1.00745913e+00, 1.02203069e+00, 1.03660225e+00, 1.05117381e+00, 1.06574537e+00, 1.08031692e+00, 1.09488848e+00, 1.10946004e+00, 1.12403160e+00, 1.13860316e+00, 1.15317472e+00, 1.16774627e+00, 1.18231783e+00, 1.19688939e+00, 1.21146095e+00, 1.22603251e+00, 1.24060407e+00, 1.25517562e+00, 1.26974718e+00, 1.28431874e+00, 1.29889030e+00, 1.31346186e+00, 1.32803342e+00, 1.34260498e+00, 1.35717653e+00, 1.37174809e+00, 1.38631965e+00, 1.40089121e+00, 1.41546277e+00, 1.43003433e+00, 1.44460588e+00, 1.45917744e+00, 1.47374900e+00, 1.48832056e+00, 1.50289212e+00, 1.51746368e+00, 1.53203523e+00, 1.54660679e+00, 1.56117835e+00, 1.57574991e+00, 1.59032147e+00, 1.60489303e+00, 1.61946458e+00, 1.63403614e+00, 1.64860770e+00, 1.66317926e+00, 1.67775082e+00, 1.69232238e+00, 1.70689393e+00, 1.72146549e+00, 1.73603705e+00, 1.75060861e+00, 1.76518017e+00, 1.77975173e+00, 1.79432328e+00, 1.80889484e+00, 1.82346640e+00, 1.83803796e+00, 1.85260952e+00, 1.86718108e+00, 1.88175263e+00, 1.89632419e+00, 1.91089575e+00, 1.92546731e+00, 1.94003887e+00, 1.95461043e+00, 1.96918199e+00, 1.98375354e+00, 1.99832510e+00, 2.01289666e+00, 2.02746822e+00, 2.04203978e+00, 2.05661134e+00, 2.07118289e+00, 2.08575445e+00, 2.10032601e+00, 2.11489757e+00, 2.12946913e+00, 2.14404069e+00, 2.15861224e+00, 2.17318380e+00, 2.18775536e+00, 2.20232692e+00, 2.21689848e+00, 2.23147004e+00, 2.24604159e+00, 2.26061315e+00, 2.27518471e+00, 2.28975627e+00, 2.30432783e+00, 2.31889939e+00, 2.33347094e+00, 2.34804250e+00, 2.36261406e+00, 2.37718562e+00, 2.39175718e+00, 2.40632874e+00, 2.42090029e+00, 2.43547185e+00, 2.45004341e+00, 2.46461497e+00, 2.47918653e+00, 2.49375809e+00, 2.50832964e+00, 2.52290120e+00, 2.53747276e+00, 2.55204432e+00, 2.56661588e+00, 2.58118744e+00, 2.59575900e+00, 2.61033055e+00, 2.62490211e+00, 2.63947367e+00, 2.65404523e+00, 2.66861679e+00, 2.68318835e+00, 2.69775990e+00, 2.71233146e+00, 2.72690302e+00, 2.74147458e+00, 2.75604614e+00, 2.77061770e+00, 2.78518925e+00, 2.79976081e+00, 2.81433237e+00, 2.82890393e+00, 2.84347549e+00, 2.85804705e+00, 2.87261860e+00, 2.88719016e+00, 2.90176172e+00, 2.91633328e+00, 2.93090484e+00, 2.94547640e+00, 2.96004795e+00, 2.97461951e+00, 2.98919107e+00, 3.00376263e+00, 3.01833419e+00, 3.03290575e+00, 3.04747730e+00, 3.06204886e+00, 3.07662042e+00, 3.09119198e+00, 3.10576354e+00, 3.12033510e+00, 3.13490665e+00, 3.14947821e+00, 3.16404977e+00, 3.17862133e+00, 3.19319289e+00, 3.20776445e+00, 3.22233601e+00, 3.23690756e+00, 3.25147912e+00, 3.26605068e+00, 3.28062224e+00, 3.29519380e+00, 3.30976536e+00, 3.32433691e+00, 3.33890847e+00, 3.35348003e+00, 3.36805159e+00]), array([2.41376615e-03, 2.39518370e-03, 2.35837113e-03, 2.30419850e-03, 2.23392630e-03, 2.14916005e-03, 2.05179351e-03, 1.94394342e-03, 1.82787927e-03, 1.70595133e-03, 1.58052070e-03, 1.45389397e-03, 1.32826555e-03, 1.20566919e-03, 1.08794037e-03, 9.76689751e-04, 8.73287796e-04, 7.78859611e-04, 6.94288753e-04, 6.20228289e-04, 5.57117165e-04, 5.05199857e-04, 4.64547358e-04, 4.35077753e-04, 4.16889866e-04, 4.09153533e-04, 4.11976091e-04, 4.24342064e-04, 4.45877909e-04, 4.75912451e-04, 5.13699402e-04, 5.58420556e-04, 6.09190055e-04, 6.65060935e-04, 7.25035032e-04, 7.88077037e-04, 8.53133143e-04, 9.19154296e-04, 9.85123582e-04, 1.05008685e-03, 1.11318516e-03, 1.17368739e-03, 1.23133583e-03, 1.28524724e-03, 1.33547256e-03, 1.38269559e-03, 1.42598531e-03, 1.46722218e-03, 1.50634715e-03, 1.54443818e-03, 1.58259698e-03, 1.62202865e-03, 1.66462164e-03, 1.71064325e-03, 1.76176439e-03, 1.81943681e-03, 1.88416340e-03, 1.95700435e-03, 2.03861259e-03, 2.12976115e-03, 2.23022538e-03, 2.34097371e-03, 2.46100741e-03, 2.59070365e-03, 2.72998084e-03, 2.87879391e-03, 3.03718950e-03, 3.20535454e-03, 3.38365333e-03, 3.57264892e-03, 3.77342037e-03, 3.98641804e-03, 4.21296148e-03, 4.45423309e-03, 4.71204596e-03, 4.98649613e-03, 5.27924919e-03, 5.59041673e-03, 5.92042745e-03, 6.26898718e-03, 6.63584897e-03, 7.01850572e-03, 7.41523986e-03, 7.82323850e-03, 8.23906808e-03, 8.65874304e-03, 9.07782450e-03, 9.49185974e-03, 9.89540161e-03, 1.02837061e-02, 1.06522684e-02, 1.09960794e-02, 1.13113192e-02, 1.15949605e-02, 1.18437959e-02, 1.20563785e-02, 1.22318199e-02, 1.23698540e-02, 1.24707096e-02, 1.25371074e-02, 1.25717483e-02, 1.25765475e-02, 1.25569223e-02, 1.25153648e-02, 1.24577131e-02, 1.23886523e-02, 1.23135096e-02, 1.22364848e-02, 1.21638519e-02, 1.20991533e-02, 1.20486522e-02, 1.20150148e-02, 1.20037260e-02, 1.20184463e-02, 1.20628609e-02, 1.21408115e-02, 1.22558311e-02, 1.24127511e-02, 1.26161749e-02, 1.28701735e-02, 1.31795587e-02, 1.35487369e-02, 1.39841278e-02, 1.44912571e-02, 1.50757512e-02, 1.57431944e-02, 1.64998924e-02, 1.73505377e-02, 1.83015381e-02, 1.93564072e-02, 2.05196383e-02, 2.17922725e-02, 2.31766742e-02, 2.46737069e-02, 2.62815973e-02, 2.79982655e-02, 2.98193681e-02, 3.17427209e-02, 3.37595762e-02, 3.58653836e-02, 3.80492541e-02, 4.03046780e-02, 4.26235179e-02, 4.49961146e-02, 4.74147302e-02, 4.98687551e-02, 5.23531634e-02, 5.48592967e-02, 5.73818491e-02, 5.99164202e-02, 6.24583369e-02, 6.50042299e-02, 6.75520906e-02, 7.01033350e-02, 7.26567205e-02, 7.52158593e-02, 7.77821939e-02, 8.03608705e-02, 8.29555528e-02, 8.55723179e-02, 8.82167818e-02, 9.08931796e-02, 9.36103737e-02, 9.63717264e-02, 9.91836711e-02, 1.02050416e-01, 1.04976401e-01, 1.07961911e-01, 1.11009649e-01, 1.14120732e-01, 1.17286903e-01, 1.20507109e-01, 1.23773397e-01, 1.27078016e-01, 1.30409624e-01, 1.33755667e-01, 1.37102997e-01, 1.40436425e-01, 1.43740620e-01, 1.47000811e-01, 1.50202124e-01, 1.53331879e-01, 1.56377525e-01, 1.59327137e-01, 1.62177999e-01, 1.64923457e-01, 1.67566919e-01, 1.70109481e-01, 1.72560124e-01, 1.74929295e-01, 1.77230036e-01, 1.79482450e-01, 1.81705420e-01, 1.83919192e-01, 1.86147595e-01, 1.88413771e-01, 1.90739680e-01, 1.93145311e-01, 1.95651176e-01, 1.98272301e-01, 2.01022021e-01, 2.03908335e-01, 2.06938677e-01, 2.10115075e-01, 2.13434609e-01, 2.16892537e-01, 2.20480753e-01, 2.24189936e-01, 2.28008709e-01, 2.31923500e-01, 2.35919080e-01, 2.39982930e-01, 2.44100751e-01, 2.48261168e-01, 2.52451806e-01, 2.56664831e-01, 2.60886286e-01, 2.65110523e-01, 2.69327823e-01, 2.73532155e-01, 2.77713574e-01, 2.81861599e-01, 2.85968255e-01, 2.90020951e-01, 2.94006131e-01, 2.97907513e-01, 3.01710336e-01, 3.05397674e-01, 3.08946417e-01, 3.12341539e-01, 3.15561443e-01, 3.18592809e-01, 3.21418397e-01, 3.24032289e-01, 3.26420901e-01, 3.28581980e-01, 3.30516074e-01, 3.32226562e-01, 3.33728071e-01, 3.35036972e-01, 3.36169632e-01, 3.37153401e-01, 3.38019241e-01, 3.38797414e-01, 3.39523447e-01, 3.40236656e-01, 3.40970194e-01, 3.41763501e-01, 3.42653296e-01, 3.43674384e-01, 3.44857969e-01, 3.46236528e-01, 3.47831888e-01, 3.49668346e-01, 3.51763479e-01, 3.54122623e-01, 3.56750869e-01, 3.59646930e-01, 3.62801833e-01, 3.66195167e-01, 3.69807027e-01, 3.73606548e-01, 3.77553198e-01, 3.81611507e-01, 3.85731313e-01, 3.89862669e-01, 3.93947698e-01, 3.97936144e-01, 4.01769042e-01, 4.05390028e-01, 4.08748415e-01, 4.11789802e-01, 4.14471939e-01, 4.16752947e-01, 4.18597100e-01, 4.19978155e-01, 4.20873712e-01, 4.21268118e-01, 4.21157044e-01, 4.20538045e-01, 4.19426174e-01, 4.17831933e-01, 4.15776719e-01, 4.13291405e-01, 4.10406858e-01, 4.07162261e-01, 4.03603544e-01, 3.99777459e-01, 3.95736206e-01, 3.91533241e-01, 3.87221814e-01, 3.82859959e-01, 3.78504891e-01, 3.74212330e-01, 3.70032991e-01, 3.66015645e-01, 3.62205816e-01, 3.58641879e-01, 3.55357088e-01, 3.52371628e-01, 3.49702303e-01, 3.47354042e-01, 3.45326192e-01, 3.43608458e-01, 3.42178919e-01, 3.41007256e-01, 3.40060916e-01, 3.39297154e-01, 3.38669789e-01, 3.38131865e-01, 3.37630487e-01, 3.37119261e-01, 3.36549194e-01, 3.35878178e-01, 3.35067233e-01, 3.34082456e-01, 3.32897242e-01, 3.31495655e-01, 3.29865695e-01, 3.28003801e-01, 3.25910162e-01, 3.23600643e-01, 3.21087890e-01, 3.18392716e-01, 3.15535752e-01, 3.12546910e-01, 3.09445688e-01, 3.06264156e-01, 3.03024212e-01, 2.99748985e-01, 2.96458929e-01, 2.93167893e-01, 2.89886229e-01, 2.86629750e-01, 2.83398911e-01, 2.80195875e-01, 2.77024990e-01, 2.73883410e-01, 2.70768009e-01, 2.67678936e-01, 2.64614947e-01, 2.61575941e-01, 2.58563728e-01, 2.55580913e-01, 2.52631350e-01, 2.49726268e-01, 2.46873065e-01, 2.44082569e-01, 2.41368323e-01, 2.38742346e-01, 2.36213514e-01, 2.33791451e-01, 2.31485248e-01, 2.29296837e-01, 2.27225297e-01, 2.25269245e-01, 2.23417505e-01, 2.21655114e-01, 2.19966205e-01, 2.18330274e-01, 2.16717394e-01, 2.15101792e-01, 2.13453478e-01, 2.11739887e-01, 2.09934024e-01, 2.08002228e-01, 2.05920088e-01, 2.03667123e-01, 2.01222208e-01, 1.98575765e-01, 1.95717670e-01, 1.92647778e-01, 1.89369598e-01, 1.85891044e-01, 1.82230280e-01, 1.78407751e-01, 1.74443732e-01, 1.70364735e-01, 1.66199324e-01, 1.61974370e-01, 1.57719468e-01, 1.53458419e-01, 1.49220159e-01, 1.45028686e-01, 1.40900299e-01, 1.36852439e-01, 1.32898539e-01, 1.29050519e-01, 1.25314064e-01, 1.21690712e-01, 1.18185776e-01, 1.14793355e-01, 1.11515021e-01, 1.08344155e-01, 1.05277125e-01, 1.02306758e-01, 9.94260982e-02, 9.66315497e-02, 9.39205018e-02, 9.12839314e-02, 8.87209840e-02, 8.62257454e-02, 8.37991941e-02, 8.14384943e-02, 7.91405506e-02, 7.69039444e-02, 7.47294415e-02, 7.26169466e-02, 7.05654428e-02, 6.85754193e-02, 6.66453335e-02, 6.47752555e-02, 6.29631735e-02, 6.12124700e-02, 5.95184501e-02, 5.78809215e-02, 5.62980005e-02, 5.47702793e-02, 5.32934982e-02, 5.18700880e-02, 5.04967550e-02, 4.91723724e-02, 4.78964282e-02, 4.66672672e-02, 4.54832656e-02, 4.43436280e-02, 4.32451948e-02, 4.21874538e-02, 4.11682108e-02, 4.01838497e-02, 3.92329430e-02, 3.83114988e-02, 3.74175824e-02, 3.65465084e-02, 3.56945597e-02, 3.48594121e-02, 3.40382650e-02, 3.32276727e-02, 3.24238931e-02, 3.16238048e-02, 3.08262044e-02, 3.00296276e-02, 2.92327968e-02, 2.84344733e-02, 2.76344236e-02, 2.68333984e-02, 2.60308898e-02, 2.52281515e-02, 2.44251003e-02, 2.36227220e-02, 2.28217851e-02, 2.20219058e-02, 2.12244137e-02, 2.04303459e-02, 1.96390452e-02, 1.88506329e-02, 1.80653958e-02, 1.72833556e-02, 1.65052837e-02, 1.57316327e-02, 1.49623417e-02, 1.41998182e-02, 1.34445502e-02, 1.26988147e-02, 1.19645065e-02, 1.12443745e-02, 1.05408556e-02, 9.85671071e-03, 9.19483689e-03, 8.55935860e-03, 7.95309428e-03, 7.37878920e-03, 6.83977237e-03, 6.33832892e-03, 5.87824932e-03, 5.46120133e-03, 5.08819654e-03, 4.76183166e-03, 4.48351250e-03, 4.25325425e-03, 4.07149710e-03, 3.93857671e-03, 3.85435645e-03, 3.81748148e-03, 3.82768874e-03, 3.88337129e-03, 3.98226712e-03, 4.12216069e-03, 4.30121990e-03, 4.51735518e-03, 4.76668448e-03, 5.04576737e-03, 5.35162709e-03, 5.68001692e-03, 6.02751663e-03, 6.38970778e-03, 6.76211202e-03, 7.14063589e-03, 7.52101421e-03, 7.89843832e-03, 8.26797339e-03, 8.62596093e-03, 8.96793670e-03, 9.28971230e-03, 9.58680137e-03, 9.85570009e-03, 1.00927800e-02, 1.02955056e-02, 1.04602889e-02, 1.05862748e-02, 1.06713934e-02, 1.07142303e-02]), array(0.16498435))
Calculate the KDE for specific variables:
In [2]: import arviz_base as azb ...: dt = azb.load_arviz_data("centered_eight") ...: azs.kde(dt, var_names=["mu", "theta"]) ...: Out[2]: <xarray.DataTree 'posterior'> Group: /posterior Dimensions: (plot_axis: 2, kde_dim: 512, school: 8) Coordinates: * plot_axis (plot_axis) <U1 8B 'x' 'y' bw_mu float64 8B 0.3569 * school (school) <U16 512B 'Choate' 'Deerfield' ... 'Mt. Hermon' bw_theta (school) float64 64B 0.5168 0.5102 0.5383 ... 0.4794 0.5383 Dimensions without coordinates: kde_dim Data variables: mu (plot_axis, kde_dim) float64 8kB -7.485 -7.435 ... 0.001112 theta (plot_axis, school, kde_dim) float64 66kB -14.87 ... 0.0007317
Calculate the KDE also over the school dimension (for variables where present):
In [3]: azs.kde(dt, dim=["chain", "draw", "school"]) Out[3]: <xarray.DataTree 'posterior'> Group: /posterior Dimensions: (plot_axis: 2, kde_dim: 512) Coordinates: * plot_axis (plot_axis) <U1 8B 'x' 'y' bw_mu float64 8B 0.3569 bw_theta float64 8B 0.3822 bw_tau float64 8B 0.2737 Dimensions without coordinates: kde_dim Data variables: mu (plot_axis, kde_dim) float64 8kB -7.485 -7.435 ... 0.001112 theta (plot_axis, kde_dim) float64 8kB -29.63 -29.49 ... 0.0001257 tau (plot_axis, kde_dim) float64 8kB 0.9156 0.9539 ... 0.002818