<jupyter_start><jupyter_text>Social desirability experiment data analysis This notebook documents the analysis of the social desirability experiment 2 X 2 fully-crossed between-subject experiment: * Question wording:  + no excuse statement  + with excuse statement    * Response options:  + Yes/ No   + Yes with any reason/ Yes only when neccessary/ No  * Conditions:  + Control: no excuse statement, Yes/No  + Condition A: with excuse statement, Yes/No  + Condition B: no excuse statement, Yes with any reason/ Yes only when neccessary/ No  + Condition C: with excuse statement, Yes with any reason/ Yes only when neccessary/ No   * To test the overall effect of:  + excuse statement: Control + B vs. A + C  + response options: Control + A vs. B + C<jupyter_code>import numpy as np
import pandas as pd

import utility as util
df = pd.read_csv('../output/SD_experiment_df.csv', skipinitialspace=True)
df.shape
df.columns
df['condition'].value_counts().sort_index()
# numeric -> character display
display_change_cols = ['gone_to_friend', 'had_visitors', 'had_close_contact', 'gone_outside']

for col in display_change_cols:
    df[col] = df[[col]].replace([1, 2, 3, 4], ["1. Yes/Yes any time", "2. Yes only when neccessary", "3. No", "4. Unsure"])
# combine top two response options into "yes"
combine_top_two = {"1. Yes/Yes any time": "1. Yes", 
                   "2. Yes only when neccessary": "1. Yes", 
                   "3. No": "2. No",
                   "4. Unsure": "3. Unsure"}
# create recodes that reflect the combinations
SD_cols = ['gone_to_friend', 'had_visitors', 'had_close_contact', 'gone_outside']

for col in SD_cols:
    df[f'{col}_r'] = df[col].map(combine_top_two)
recoded_cols = ['gone_to_friend_r', 'had_visitors_r', 'had_close_contact_r', 'gone_outside_r']
# create two separate factor variables
excuse_map = {'Control': 'no_excuse',
              'B': 'no_excuse',
              'A': 'with_excuse', 
              'C': 'with_excuse'}

response_map = {'Control': 'two_response',
                'A': 'two_response',
                'B': 'three_response', 
                'C': 'three_response'}
df['excuse_statement_condition'] = df['condition'].map(excuse_map)
df['response_set_condition'] = df['condition'].map(response_map)
# use variable label for table display
gender_map = {1.0: '1. Woman',
              2.0: '2. Man',
              np.nan: np.nan}

marital_map = {1.0: '1. Married',
               7.0: '2. Not married',
               8.0: np.nan,
               np.nan: np.nan}

age_group_map = {2.0: '19-25',
                 3.0: '26-35',
                 4.0: '36-45', 
                 5.0: '46-55',
                 6.0: '56-65',
                 7.0: '66+',
                 np.nan: np.nan}

education_map = {4.0: '1. Less than high school diploma',
                 5.0: '2. High school diploma',
                 6.0: '3. Some college',
                 7.0: '4. Bachelor degree',
                 8.0: '5. Graduate degree',
                 np.nan: np.nan}
df['gender'] = df['gender'].map(gender_map)
df['marital'] = df['marital'].map(marital_map)
df['age_group'] = df['age_group'].map(age_group_map)
df['education'] = df['education'].map(education_map)
# create a version of the data that excludes "unsure"
df_no_miss = df[(df['gone_to_friend'] != '4. Unsure') & (df['had_visitors'] != '4. Unsure') & 
                (df['had_close_contact'] != '4. Unsure') & (df['gone_outside'] != '4. Unsure')]
df_no_miss.shape<jupyter_output><empty_output><jupyter_text>Full crosstab tables<jupyter_code>conditions = ['Control', 'A', 'B', 'C']
for col in SD_cols:
    util.crosstab_chisq(col, 'condition', df_no_miss, conditions, chisqtest=False)<jupyter_output><empty_output><jupyter_text>Testing the effect of question wording Question wording:  + no excuse statement  + with excuse statement<jupyter_code>excuse_statement_order = ['no_excuse', 'with_excuse']
for col in recoded_cols:
    util.crosstab_chisq(col, 'excuse_statement_condition', df_no_miss, excuse_statement_order)<jupyter_output><empty_output><jupyter_text>Testing the effect of response set Response set:  + two response set: Yes/ No   + three response set: Yes with any reason/ Yes only when neccessary/ No<jupyter_code>response_set_order = ['two_response', 'three_response']
for col in SD_cols:
    util.crosstab_chisq(col, 'response_set_condition', df_no_miss, response_set_order, chisqtest=False)
for col in recoded_cols:
    util.crosstab_chisq(col, 'response_set_condition', df_no_miss, response_set_order)<jupyter_output><empty_output><jupyter_text>Comparing control vs. C<jupyter_code>df_no_miss_controlC = df_no_miss[df_no_miss["condition"].isin(["Control", "C"])]
conditions_control_C = ['Control', 'C']
for col in recoded_cols:
    util.crosstab_chisq(col, 'condition', df_no_miss_controlC, conditions_control_C)<jupyter_output><empty_output><jupyter_text>Demographic distributions<jupyter_code>demographic_cols = ['gender', 'marital', 'age_group', 'education']
for col in demographic_cols:
    util.crosstab_chisq(col, 'condition', df_no_miss, conditions)<jupyter_output><empty_output><jupyter_text>Export data<jupyter_code>df_no_miss.to_csv('../output/df_no_miss.csv', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13580719204284622, 'fraction_numerical': 0.016258607498087222, 'mean_word_length': 3.762295081967213, 'pattern_counts': {'":': 4, '<': 29, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '601919', 'license': 'MIT', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1743, 'n_words': 439, 'path': 'report/7.2_SD_experiment_analysis.ipynb', 'repo_name': 'rosalynnyang/fb_uas_study', 'size': '5228'}