Skip to content

Instantly share code, notes, and snippets.

@dmargala
Last active August 12, 2016 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmargala/be3ef4c7cd676eac07e3dc8add4603d2 to your computer and use it in GitHub Desktop.
Save dmargala/be3ef4c7cd676eac07e3dc8add4603d2 to your computer and use it in GitHub Desktop.
blinds statsmodel summary output
class Blinders(object):
def __init__(self, medusa, peripherals=['Std.Err.', 't', 'P>|t|']):
'''Helper to only view `peripherals` of `medusa`'''
# the coefficient we want to blind
self.medusa = medusa
# the stats we don't want to blind
self.peripherals = peripherals
def blind_summary(self, model):
'''Filters the result of `model.summary2()`'''
# sm model method summary2() contains the pandas dataframe
# that we want to blind
summary = model.summary2()
results = summary.tables[1]
# Find the columns that we want to blind
blinded_columns = list(set(results.columns) - set(self.peripherals))
# set the values that we don't want to see to np.nan
# TODO: is this really the best we can do?
results.loc[self.medusa, blinded_columns] = np.nan
return summary
def view_summary(self, model):
'''Prints a blinded summary of `model`'''
print(self.blind_summary(model))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment