Пример #1
0
    def standardized_mean_differences(self, iptw_only=True):
        """Calculates the standardized mean differences for all variables. Default calculates the standardized mean
        difference for all variables included in the IPTW denominator

        Parameters
        ----------
        iptw_only : bool, optional
            Whether the diagnostic should be run on IPTW only or include weights from the missing_model. Default is
            True, which returns IPTW only

        Returns
        -------
        DataFrame
            Returns pandas DataFrame of calculated standardized mean differences. Columns are labels (variables labels),
            smd_u (unweighted standardized difference), and smd_w (weighted standardized difference)
        """
        if iptw_only:
            df = self.df
            df['_ipfw_'] = self.iptw
        else:
            df = self.df
            df['_ipfw_'] = self.iptw * self.ipmw

        s = standardized_mean_differences(df=df,
                                          treatment=self.treatment,
                                          weight='_ipfw_',
                                          formula=self.__mdenom)
        return s
Пример #2
0
    def standardized_mean_differences(self):
        """Calculates the standardized mean differences for all variables based on the inverse probability weights.

        Returns
        -------
        DataFrame
            Returns pandas DataFrame of calculated standardized mean differences. Columns are labels (variables labels),
            smd_u (unweighted standardized difference), and smd_w (weighted standardized difference)
        """
        df = self.df.copy()
        df['_ipw_'] = np.where(df[self.exposure] == 1, 1 / df['_g1_'], 1 / (1 - df['_g1_']))
        s = standardized_mean_differences(df=df, treatment=self.exposure,
                                          weight='_ipw_', formula=self.__mweight)
        return s