partitions = get_partition_list(args.partition) partition_str = '-'.join(partitions) for m in models: dir_path = p.outdir + '/' + m if args.ablated_models: data_path = dir_path + '/X_conv_' + partition_str + '.csv' else: data_path = p.outdir + '/' + m.split( '!')[0] + '/X_conv_' + partition_str + '.csv' stderr('Two-step analysis using data file %s\n' % data_path) if os.path.exists(data_path): p.set_model(m) f = Formula(p['formula']) model_form = f.to_lmer_formula_string( z=args.zscore, correlated=not args.uncorrelated) model_form = model_form.replace('-', '_') is_lme = '|' in model_form df = pd.read_csv(data_path, sep=' ', skipinitialspace=True) for c in df.columns: if df[c].dtype.name == 'object': df[c] = df[c].astype(str) new_cols = [] for c in df.columns: new_cols.append(c.replace('-', '_')) df.columns = new_cols
argparser.add_argument('-z', '--standardize_response', action='store_true', help='Standardize (Z-transform) response in plots. Ignored unless model was fitted using setting ``standardize_respose=True``.') argparser.add_argument('-n', '--nsamples', type=int, default=None, help='Number of posterior samples to average (only used for CDRBayes)') argparser.add_argument('-u', '--unscaled', action='store_true', help='Do not multiply outputs by CDR-fitted coefficients') argparser.add_argument('-a', '--algorithm', type=str, default='MAP', help='Algorithm ("sampling" or "MAP") to use for extracting predictions.') argparser.add_argument('-A', '--ablated_models', action='store_true', help='Perform convolution using ablated models. Otherwise only convolves using the full model in each ablation set.') args, unknown = argparser.parse_known_args() for path in args.config_paths: p = Config(path) if not p.use_gpu_if_available: os.environ['CUDA_VISIBLE_DEVICES'] = '-1' models = filter_models(p.model_list, args.models) cdr_formula_list = [Formula(p.models[m]['formula']) for m in models if (m.startswith('CDR') or m.startswith('DTSR'))] cdr_models = [m for m in models if (m.startswith('CDR') or m.startswith('DTSR'))] if not args.ablated_models: cdr_models_new = [] for model_name in cdr_models: if len(model_name.split('!')) == 1: #No ablated variables, which are flagged with "!" cdr_models_new.append(model_name) cdr_models = cdr_models_new evaluation_sets = [] evaluation_set_partitions = [] evaluation_set_names = [] evaluation_set_paths = [] for p_name in args.partition:
models = filter_models(p.model_list, args.models) run_baseline = False run_cdr = False for m in models: if not run_baseline and m.startswith('LM') or m.startswith('GAM'): run_baseline = True elif not run_cdr and (m.startswith('CDR') or m.startswith('DTSR')): run_cdr = True if not (run_baseline or run_cdr): stderr('No models to run. Exiting...\n') exit() cdr_formula_list = [ Formula(p.models[m]['formula']) for m in models if (m.startswith('CDR') or m.startswith('DTSR')) ] cdr_formula_name_list = [ m for m in p.model_list if (m.startswith('CDR') or m.startswith('DTSR')) ] all_rangf = [v for x in cdr_formula_list for v in x.rangf] partitions = get_partition_list(args.partition) X_paths, y_paths = paths_from_partition_cliarg(partitions, p) X, y = read_data(X_paths, y_paths, p.series_ids, categorical_columns=list( set(p.split_ids + p.series_ids + [v for x in cdr_formula_list for v in x.rangf])))
args, unknown = argparser.parse_known_args() p = Config(args.config_path) models = filter_models(p.model_list, args.models) run_baseline = False run_cdr = False for m in models: if not run_baseline and m.startswith('LM') or m.startswith('GAM'): run_baseline = True elif not run_cdr and (m.startswith('CDR') or m.startswith('DTSR')): run_cdr = True cdr_formula_list = [ Formula(p.models[m]['formula']) for m in models if (m.startswith('CDR') or m.startswith('DTSR')) ] cdr_formula_name_list = [ m for m in p.model_list if (m.startswith('CDR') or m.startswith('DTSR')) ] evaluation_sets = [] evaluation_set_partitions = [] evaluation_set_names = [] evaluation_set_paths = [] for p_name in args.partition: partitions = get_partition_list(p_name) partition_str = '-'.join(partitions)
if 'impulse_to_transform' in config: for key in config['impulse_to_transform']: impulse_to_transform[key] = config['impulse_to_transform'][key] newpred_rangf = ['subject'] if 'newpred_rangf' in config: newpred_rangf = config['newpred_rangf']['rangf'].strip().split() baseline_found = False for name in config: if (name.startswith('model_CDR') or name.startswith('model_DTSR')) and name.endswith('_BASELINE'): baseline_found = True new_name = name[:-9] model_template = config[name] f = Formula(model_template['formula']) for effect in main_effects: if effect.startswith('~'): ablate = True effect = effect[1:] else: ablate = False irf_str = impulse_to_irf.get(effect, default_irf_str) effect_name = effect transform = impulse_to_transform.get(effect, ['s']) if transform == 'None': transform = [] elif isinstance(transform, str): transform = transform.strip().split()
argparser.add_argument('-e', '--extra_cols', action='store_true', help='For prediction from CDR models, dump prediction outputs and response metadata to a single csv.') args, unknown = argparser.parse_known_args() p = Config(args.config_path) models = filter_models(p.model_list, args.models) run_baseline = False run_cdr = False for m in models: if not run_baseline and m.startswith('LM') or m.startswith('GAM'): run_baseline = True elif not run_cdr and (m.startswith('CDR') or m.startswith('DTSR')): run_cdr = True cdr_formula_list = [Formula(p.models[m]['formula']) for m in models if (m.startswith('CDR') or m.startswith('DTSR'))] cdr_formula_name_list = [m for m in p.model_list if (m.startswith('CDR') or m.startswith('DTSR'))] evaluation_sets = [] evaluation_set_partitions = [] evaluation_set_names = [] evaluation_set_paths = [] for p_name in args.partition: partitions = get_partition_list(p_name) partition_str = '-'.join(partitions) X_paths, y_paths = paths_from_partition_cliarg(partitions, p) X, y = read_data(X_paths, y_paths, p.series_ids, categorical_columns=list(set(p.split_ids + p.series_ids + [v for x in cdr_formula_list for v in x.rangf]))) X, y, select, X_response_aligned_predictor_names, X_response_aligned_predictors, X_2d_predictor_names, X_2d_predictors = preprocess_data( X, y,