Esempio n. 1
0
 def get_change(self, retest_dataset):
     demographics = self.data
     
     retest = get_demographics(retest_dataset)
     retest = residualize_baseline(retest, self.residualize_vars)
     if 'BMI' in retest.columns:
         retest.drop(['WeightPounds', 'HeightInches'], axis=1, inplace=True)
     # get common variables
     common_index = sorted(list(set(demographics.index) & set(retest.index)))
     common_columns = sorted(list(set(demographics.columns) & set(retest.columns)))
     demographics = demographics.loc[common_index, common_columns] 
     retest = retest.loc[common_index, common_columns]
     raw_change = retest-demographics
     # convert to scores
     c = self.get_c()
     demographic_factor_weights = get_attr(self.results['factor_tree_Rout_oblimin'][c],'weights')
     demographic_scores = scale(demographics).dot(demographic_factor_weights)
     retest_scores = scale(retest).dot(demographic_factor_weights)
     
     
     factor_change = pd.DataFrame(retest_scores-demographic_scores,
                           index=common_index,
                           columns = self.get_scores().columns)
     factor_change = self.reorder_factors(factor_change)
     factor_change.columns = [i + ' Change' for i in factor_change.columns]
     return factor_change, raw_change
 def get_change(self, retest_dataset):
     demographics = self.data
     
     retest = get_demographics(retest_dataset)
     retest = residualize_baseline(retest, self.residualize_vars)
     if 'BMI' in retest.columns:
         retest.drop(['WeightPounds', 'HeightInches'], axis=1, inplace=True)
     # get common variables
     common_index = sorted(list(set(demographics.index) & set(retest.index)))
     common_columns = sorted(list(set(demographics.columns) & set(retest.columns)))
     demographics = demographics.loc[common_index, common_columns] 
     retest = retest.loc[common_index, common_columns]
     raw_change = retest-demographics
     # convert to scores
     c = self.get_c()
     demographic_factor_weights = get_attr(self.results['factor_tree_Rout_oblimin'][c],'weights')
     demographic_scores = scale(demographics).dot(demographic_factor_weights)
     retest_scores = scale(retest).dot(demographic_factor_weights)
     
     
     factor_change = pd.DataFrame(retest_scores-demographic_scores,
                           index=common_index,
                           columns = self.get_scores().columns)
     factor_change = self.reorder_factors(factor_change)
     factor_change.columns = [i + ' Change' for i in factor_change.columns]
     return factor_change, raw_change
Esempio n. 3
0
 def __init__(self, data, residualize=True, residualize_vars=['Age', 'Sex'],
              boot_iter=1000):
     self.raw_data = data
     self.residualize_vars = residualize_vars
     if residualize:
         data = residualize_baseline(data, self.residualize_vars)
     if 'BMI' in data.columns:
         data.drop(['WeightPounds', 'HeightInches'], axis=1, inplace=True)
     
     super().__init__(data, boot_iter=boot_iter)
 def __init__(self, data, residualize=True, residualize_vars=['Age', 'Sex'],
              boot_iter=1000):
     self.raw_data = data
     self.residualize_vars = residualize_vars
     if residualize:
         data = residualize_baseline(data, self.residualize_vars)
     if 'BMI' in data.columns:
         data.drop(['WeightPounds', 'HeightInches'], axis=1, inplace=True)
     
     super().__init__(data, boot_iter=boot_iter)
ideo_data = ideo_data.loc[ideo_demographics.index]




# define targets
targets = {'ideo_factors': ideo_data.filter(regex='Factor'),
           'ideo_orientations': ideo_data.drop(ideo_data.filter(regex='Factor|SECS').columns, axis=1).drop(['Conservatism','Intellectual Humility'], axis=1),
           'ideo_policies': ideo_data.filter(regex='SECS')}
for key, target in targets.items():
    imputed = pd.DataFrame(SoftImpute().fit_transform(target),
                            index=target.index,
                            columns=target.columns)
    
    # residualize
    imputed = residualize_baseline(imputed.join(ideo_demographics), 
                                                baseline_vars=ideo_demographics.columns)
    targets[key] = imputed+1E-5

# ****************************************************************
# run prediction
# ****************************************************************
predictors = {}
predictions = {}
shuffled_predictions = {}
# do prediction with ontological factors
if run_factors:
    # define predictors
    survey_scores = results['survey'].EFA.get_scores(rotate=EFA_rotation)
    task_scores = results['task'].EFA.get_scores(rotate=EFA_rotation)
    predictors.update({'survey_%s' % EFA_rotation: survey_scores,
                      'task_%s' % EFA_rotation: task_scores,