def fit(self): df = self.data.copy() df['group'] = 'All' # smooth self.smoothed = neighbor_mean_std( df=df, col_val=self.outcome, col_group='group', col_axis=self.covariates, radius=self.radius ) if self.num_smooths > 1: i = 1 data = self.smoothed.copy() data.rename(columns={'residual_std': 'residual'}, inplace=True) data.drop(columns={'residual_mean'}, axis=1, inplace=True) while i < self.num_smooths: self.smoothed = neighbor_mean_std( df=data, col_val='residual', col_group='group', col_axis=self.covariates, radius=self.radius ) data = self.smoothed.copy() data.rename(columns={'residual_mean': 'residual'}, inplace=True) data.drop(['residual_std'], inplace=True, axis=1) i += 1 self.smoothed.drop('residual_std', inplace=True, axis=1) self.smoothed.rename(columns={'residual_mean': 'residual_std'}, inplace=True)
def fit(self): df = self.data.copy() df['Smooth_Group'] = 'All' # smooth self.smoothed = neighbor_mean_std(df=df, col_val=self.outcome, col_group='Smooth_Group', col_axis=self.covariates, radius=self.radius)
def get_smoothed_residuals(self, radius): """ Smooth residuals for all of the data across some radius Args: radius: List[int] with two elements indicating the width and height of the square that we want to smooth over. Returns: smoothed_residuals: (pd.DataFrame) """ smoothed_residuals = neighbor_mean_std( df=self.all_residuals, col_val='residual', col_group=self.col_group, col_axis=['far_out', 'num_data'], radius=radius) return smoothed_residuals