"""Case 012: same deterministic teaching data as R; NumPy only."""
import itertools
import numpy as np
c,a,b,e,d = np.array(list(itertools.product([-1.,1.],repeat=5))).T
x=c+a
m=x+b
y=x+2*c+2*m+e
def slope(y,*predictors):
    X=np.column_stack([np.ones(len(y)),*predictors])
    return np.linalg.lstsq(X,y,rcond=None)[0][1]
first=np.array([slope(y,x),slope(y,x,c),slope(y,x,c,m)])
print("Unadjusted, confounder-adjusted, mediator-adjusted:",first)
x2=a
y2=x2+b+e
k=x2+b+d
second=np.array([slope(y2,x2),slope(y2,x2,k)])
print("Separate world: unadjusted, collider-adjusted:",second)
assert len(y)==32
assert np.allclose(first,[4,3,1],atol=1e-10,rtol=0)
assert np.allclose(second,[1,.5],atol=1e-10,rtol=0)
print("All assertions passed; NumPy",np.__version__)
