Skip to content

How to obtain y and d residuals for plotting #161

Discussion options

You must be logged in to vote

Just a small correction. To calculate the correct residuals the predictions have to be reshaped:

# Predictions for nuisance part 'ml_l' and 'ml_m' stored in an array with dimensions (n_obs x n_rep x n_treat)
print(dml_plr.predictions['ml_l'].shape)
print(dml_plr.predictions['ml_m'].shape)

# Compute residuals for ml_l = E[Y|X]
residuals_ml_l_d1 = dml_data.y - dml_plr.predictions['ml_l'][:,:,0].reshape(-1)

# Compute residuals for ml_m = E[D_1 | X] (for first treatment variable)
residuals_ml_m_d1 = dml_data.data[dml_data.d_cols[0]].values - dml_plr.predictions['ml_m'][:,:,0].reshape(-1)

# Generate a scatter plot of the residuals 
import matplotlib.pyplot as plt

# Fixing random state for …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by SvenKlaassen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants