andrey.data.missingness.draw#
- andrey.data.missingness.draw(data, mechanism, *, seed)[source]#
Draw the missing values of
mechanismover completedata.The draw comes from its own stream of
seed, the onemissing=onsample()takes, sodraw(ds.data, mechanism, seed=s)on a complete sampledswith seedsand noscreengives the mask of the sample withmissing=mechanism. A draw that leaves a column that can go missing with fewer than 2 observed values is drawn again from the next stream ofseed.- Parameters:
- Returns:
The mask and the parents of each indicator.
np.where(m.mask, np.nan, data)is the data with the missing values.- Return type:
- Raises:
ValueError – If
datais not a 2-D array of finite numbers with at least 2 rows,parentsnames a columndatalacks, the columns cannot hold the mechanism (a"mar"mask needs one always-observed column and one that can go missing, an"mnar"mask two that can go missing), a parent is constant, or no draw in 100 keeps 2 observed values in every column.
Examples
>>> import numpy as np >>> from andrey.data.missingness import draw, mcar >>> X = np.random.default_rng(0).standard_normal((200, 3)) >>> m = draw(X, mcar(0.1), seed=0) >>> m.mask.shape, sorted(m.parents) ((200, 3), [0, 1, 2])