def calc_bonuses(data):
    bonus_experiments = [
        'angling_risk_task_always_sunny', 'two_stage_decision',
        'columbia_card_task_hot', 'columbia_card_task_cold',
        'hierarchical_rule', 'kirby', 'discount_titrate', 'bickel_titrator'
    ]
    bonuses = []
    for row in data.iterrows():
        if row[1]['experiment_exp_id'] in bonus_experiments:
            try:
                df = extract_row(row[1], clean=False)
            except TypeError:
                bonuses.append(np.nan)
                continue
            bonus = df.iloc[-1].get('performance_var', 'error')
            if pd.isnull(bonus):
                bonus = df.iloc[-5].get('performance_var', 'error')
            if not isinstance(bonus, (int, float)):
                bonus = json.loads(bonus)['amount']
            bonuses.append(bonus)
        else:
            bonuses.append(np.nan)
    data.loc[:, 'bonus'] = bonuses
    data.loc[:, 'bonus_zscore'] = data['bonus']
    means = data.groupby('experiment_exp_id').bonus.mean()
    std = data.groupby('experiment_exp_id').bonus.std()
    for exp in bonus_experiments:
        data.loc[data.experiment_exp_id == exp,
                 'bonus_zscore'] = (data[data.experiment_exp_id == exp].bonus -
                                    means[exp]) / std[exp]
def calc_bonuses(data):
    bonus_experiments = ['angling_risk_task_always_sunny', 'two_stage_decision',
                         'columbia_card_task_hot', 'columbia_card_task_cold', 'hierarchical_rule',
                         'kirby','discount_titrate','bickel_titrator']
    bonuses = []
    for row in data.iterrows():
        if row[1]['experiment_exp_id'] in bonus_experiments:
            try:
                df = extract_row(row[1], clean = False)
            except TypeError:
                bonuses.append(np.nan)
                continue
            bonus = df.iloc[-1].get('performance_var','error')
            if pd.isnull(bonus):
                bonus = df.iloc[-5].get('performance_var','error')
            if not isinstance(bonus,(int,float)):
                bonus = json.loads(bonus)['amount']
            bonuses.append(bonus)
        else:
            bonuses.append(np.nan)
    data.loc[:,'bonus'] = bonuses
    data.loc[:,'bonus_zscore'] = data['bonus']
    means = data.groupby('experiment_exp_id').bonus.mean()
    std = data.groupby('experiment_exp_id').bonus.std()
    for exp in bonus_experiments:
        data.loc[data.experiment_exp_id == exp,'bonus_zscore'] = (data[data.experiment_exp_id == exp].bonus-means[exp])/std[exp]
Пример #3
0
def calc_time_taken(data):
    '''Selects a worker (or workers) from results object and sorts based on experiment and time of experiment completion
    '''
    instruction_lengths = []
    exp_lengths = []
    for i, row in data.iterrows():
        if row['experiment_template'] == 'jspsych':
            exp_data = extract_row(row, clean=False)
            #ensure there is a time elapsed variable
            assert 'time_elapsed' in exp_data.iloc[-1].keys(), \
                '"time_elapsed" not found for at least one dataset in these results'
            #sum time taken on instruction trials
            instruction_length = exp_data[
                (exp_data.trial_id == 'instruction') |
                (exp_data.trial_id == 'instructions')]['rt'].sum()
            #Set the length of the experiment to the time elapsed on the last
            #jsPsych trial
            experiment_length = exp_data.iloc[-1]['time_elapsed']
            instruction_lengths.append(instruction_length / 1000.0)
            exp_lengths.append(experiment_length / 1000.0)
        else:
            instruction_lengths.append(numpy.nan)
            exp_lengths.append(numpy.nan)
    data.loc[:, 'total_time'] = exp_lengths
    data.loc[:, 'instruct_time'] = instruction_lengths
    data.loc[:, 'ontask_time'] = data['total_time'] - data['instruct_time']
    print('Finished calculating time taken')
Пример #4
0
def calc_time_taken(data):
    '''Selects a worker (or workers) from results object and sorts based on experiment and time of experiment completion
    '''
    instruction_lengths = []
    exp_lengths = []
    for row in data.iterrows():
        if row[1]['experiment_template'] == 'jspsych':
            try:
                exp_data = extract_row(row[1],clean = False)
            except TypeError:
                exp_lengths.append(numpy.nan)
                instruction_lengths.append(numpy.nan)
                continue
            #ensure there is a time elapsed variable
            assert 'time_elapsed' in exp_data.iloc[-1].keys(), \
                '"time_elapsed" not found for at least one dataset in these results'
            #sum time taken on instruction trials
            instruction_length = exp_data[(exp_data.trial_id == 'instruction') | (exp_data.trial_id == 'instructions')]['rt'].sum()     
            #Set the length of the experiment to the time elapsed on the last 
            #jsPsych trial
            experiment_length = exp_data.iloc[-1]['time_elapsed']
            instruction_lengths.append(instruction_length/1000.0)
            exp_lengths.append(experiment_length/1000.0)
        else:
            instruction_lengths.append(numpy.nan)
            exp_lengths.append(numpy.nan)
    data.loc[:,'total_time'] = exp_lengths
    data.loc[:,'instruct_time'] = instruction_lengths
    data.loc[:,'ontask_time'] = data['total_time'] - data['instruct_time']
    print('Finished calculating time taken')
Пример #5
0
def get_post_task_responses(data):
    question_responses = [numpy.nan] * len(data)
    for i, row in data.iterrows():
        if row['experiment_template'] == 'jspsych':
            row_data = extract_row(row, clean=False)
            if row_data.iloc[-2].get('trial_id') =='post task questions' and \
                'responses' in row_data.iloc[-2].keys():
                question_responses[i] = (row_data.iloc[-2]['responses'])
    data.loc[:, 'post_task_responses'] = question_responses
    print('Finished extracting post task responses')
def get_credit(data):
    credit_array = []
    for i,row in data.iterrows():
        if row['experiment_template'] in 'jspsych':
            df = extract_row(row, clean = False)
            credit_var = df.iloc[-1].get('credit_var',np.nan)
            if credit_var != None:
                credit_array.append(float(credit_var))
            else:
                credit_array.append(np.nan)
        else:
            credit_array.append(np.nan)
    data.loc[:,'credit'] = credit_array   
def get_credit(data):
    credit_array = []
    for i, row in data.iterrows():
        if row['experiment_template'] in 'jspsych':
            df = extract_row(row, clean=False)
            credit_var = df.iloc[-1].get('credit_var', np.nan)
            if credit_var != None:
                credit_array.append(float(credit_var))
            else:
                credit_array.append(np.nan)
        else:
            credit_array.append(np.nan)
    data.loc[:, 'credit'] = credit_array
Пример #8
0
def get_post_task_responses(data):
    question_responses = [numpy.nan] * len(data)
    for i,row in zip(range(0, len(data)),data.iterrows()):
        if row[1]['experiment_template'] == 'jspsych':
            try:
                row_data = extract_row(row[1],clean = False)
            except TypeError:
                continue
            if row_data.iloc[-2].get('trial_id') =='post task questions' and \
                'responses' in row_data.iloc[-2].keys():
                question_responses[i]= (row_data.iloc[-2]['responses'])
    data.loc[:,'post_task_responses'] = question_responses
    print('Finished extracting post task responses')
Пример #9
0
def get_post_task_responses(data):
    question_responses = [numpy.nan] * len(data)
    for i,row in zip(range(0, len(data)),data.iterrows()):
        if row[1]['experiment_template'] == 'jspsych':
            try:
                row_data = extract_row(row[1],clean = False)
            except TypeError:
                continue
            if row_data.iloc[-2].get('trial_id') =='post task questions' and \
                'responses' in row_data.iloc[-2].keys():
                question_responses[i]= (row_data.iloc[-2]['responses'])
    data.loc[:,'post_task_responses'] = question_responses
    print('Finished extracting post task responses')