Last active
August 12, 2016 05:29
-
-
Save dmargala/be3ef4c7cd676eac07e3dc8add4603d2 to your computer and use it in GitHub Desktop.
blinds statsmodel summary output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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