<jupyter_start><jupyter_text>HedgesDo female characters really use more hedges? Let's find out! Table of Contents1. [Finding Hedges](findhedge)2. [Graphs](graphs)3. [Statistical Tests](sig)  Finding Hedges<jupyter_code>import pandas as pd
movies_df = pd.read_pickle(r"C:/Users/cassi/Desktop/Data_Science/Animated-Movie-Gendered-Dialogue/private/all_tagged_dialogue.pkl")
movies_df.info()
#First, make a list of hedges
hedge_list = ['i believe', 'i guess', 'i suppose', 'maybe', 'might', 'may', 
         'possibly', 'perhaps', "i don't know","i do not know",
         "i'm not sure", "i am not sure", "i think","i don't think", "i do not think", 'seems', 'kind of',
        'in my opinion', 'sort of', 'would', 'could', 'well', 'a bit',
             'a little', 'almost', 'actually', 'apparently', 'somewhat']
def find_hedges(line):
    hedge_count = 0
    for hedge in hedge_list:
        if hedge in line:
            hedge_count += 1
    return hedge_count
movies_df['Hedges'] = movies_df.Text.map(lambda x: find_hedges(x))
movies_df.Hedges.describe()
movies_df.groupby('Gender')['Hedges'].describe()<jupyter_output><empty_output><jupyter_text>Graphs<jupyter_code>from matplotlib import pyplot as plt
#only comparing male female, pro, ant, and helpers
movies_gen_df = movies_df[movies_df.Gender != 'n']
movies_role_df = movies_df[movies_df.Role != 'N']
movies_gen_role_df = movies_df[(movies_df.Gender != 'n') & (movies_df.Role != 'N')]
hedge_by_gen = movies_gen_df.groupby('Gender')['Hedges'].describe()['mean']
hedge_by_gen.plot.bar(color=['magenta', 'blue'])
hedge_by_role = movies_role_df.groupby('Role')['Hedges'].describe()['mean']
hedge_by_role.plot.bar(color=['red', 'purple', 'blue'])
hedge_by_role_gen = movies_gen_role_df.groupby(['Gender', 'Role'])['Hedges'].describe()['mean']
hedge_by_role_gen.unstack().plot.bar(color = ['red', 'purple', 'blue'], figsize=(15,6))
plt.title("Avg Hedge Count per Line by Gender and Role")
plt.savefig(r"C:\Users\cassi\Desktop\Data_Science\Animated-Movie-Gendered-Dialogue\images\hedges_by_gen_role.png")
hedge_by_role_gen = movies_gen_role_df.groupby(['Disney_Period','Gender', 'Role'], sort=False)['Hedges'].describe()['mean']
hedge_by_role_gen.unstack().plot.bar(color = ['red', 'blue', 'purple'], figsize = (15, 6))
hedge_by_era_gen = movies_gen_role_df.groupby(['Disney_Period','Gender'], sort=False)['Hedges'].describe()['mean']
hedge_by_era_gen.unstack().plot.bar(color = ['magenta', 'blue'], figsize = (15, 6))
plt.title('Avg Hedge Count over Time by Gender')
plt.savefig(r"C:\Users\cassi\Desktop\Data_Science\Animated-Movie-Gendered-Dialogue\images\hedge_over_era_gen.png")
hedge_by_era_role = movies_gen_role_df.groupby(['Disney_Period','Role'], sort=False)['Hedges'].describe()['mean']
hedge_by_era_role.unstack().plot.bar(color = ['red', 'blue', 'purple'], figsize = (15, 6))<jupyter_output><empty_output><jupyter_text>Statistical Tests<jupyter_code>from scipy import stats
f_movies = movies_df[movies_df.Gender == 'f']
m_movies = movies_df[movies_df.Gender == 'm']
pro_movies = movies_df[movies_df.Role == 'PRO']
ant_movies = movies_df[movies_df.Role == 'ANT']
helper_movies = movies_df[movies_df.Role == 'HELPER']<jupyter_output><empty_output><jupyter_text>Gender Overall<jupyter_code>#Between male and female characters overall
stats.ttest_ind(m_movies.Hedges, f_movies.Hedges, equal_var=False) #no significant difference!<jupyter_output><empty_output><jupyter_text>Overall, female speakers actually use slightly fewer hedges than male characters, but this difference isn't signficant.<jupyter_code>#female lines in each era
f_movies_early = f_movies[f_movies.Disney_Period == 'EARLY']
f_movies_mid = f_movies[f_movies.Disney_Period == 'MID']
f_movies_late = f_movies[f_movies.Disney_Period == 'LATE']
#male lines in each era
m_movies_early = m_movies[m_movies.Disney_Period == 'EARLY']
m_movies_mid = m_movies[m_movies.Disney_Period == 'MID']
m_movies_late = m_movies[m_movies.Disney_Period == 'LATE']<jupyter_output><empty_output><jupyter_text>Female Hedges over Time<jupyter_code>stats.f_oneway(f_movies_early.Hedges, f_movies_mid.Hedges, f_movies_late.Hedges)
stats.ttest_ind(f_movies_early.Hedges, f_movies_mid.Hedges, equal_var=False)
stats.ttest_ind(f_movies_early.Hedges, f_movies_late.Hedges, equal_var=False)
stats.ttest_ind(f_movies_mid.Hedges, f_movies_late.Hedges, equal_var=False)<jupyter_output><empty_output><jupyter_text>Overall, there appears to be a significant difference between hedge counts over time (saving between the middle era and the late era). In all two-way comparisons, the previous era's women used more hedges than the next era's women. This difference is signifcant between the early and late eras, and between the early and mid eras.  Male Hedges over Time<jupyter_code>stats.f_oneway(m_movies_early.Hedges, m_movies_mid.Hedges, m_movies_late.Hedges)<jupyter_output><empty_output><jupyter_text>No siginificant three way difference. Let's narrow this.<jupyter_code>stats.ttest_ind(m_movies_early.Hedges, m_movies_mid.Hedges, equal_var=False)
stats.ttest_ind(m_movies_early.Hedges, m_movies_late.Hedges, equal_var=False)
stats.ttest_ind(m_movies_mid.Hedges, m_movies_late.Hedges, equal_var=False)<jupyter_output><empty_output><jupyter_text>So, there is a significant difference between female hedge counts overtime, but not between male hedges over time.  Male vs Female Hedges Over Time<jupyter_code>stats.ttest_ind(m_movies_early.Hedges, f_movies_early.Hedges, equal_var=False)
stats.ttest_ind(m_movies_mid.Hedges, f_movies_mid.Hedges, equal_var=False)
stats.ttest_ind(m_movies_late.Hedges, f_movies_late.Hedges, equal_var=False)<jupyter_output><empty_output><jupyter_text>Here, we see that the difference between how genders use hedges has changed over time. While men used signficantly fewer hedges than women in Disney's early period, this difference isn't significant in the mid and late periods.  Role Role Overall<jupyter_code>stats.f_oneway(pro_movies.Hedges, ant_movies.Hedges, helper_movies.Hedges) #hardly
stats.f_oneway(pro_movies.Hedges, ant_movies.Hedges) #yep!
stats.f_oneway(pro_movies.Hedges, helper_movies.Hedges) #nope!
stats.f_oneway(helper_movies.Hedges, ant_movies.Hedges) #hardly<jupyter_output><empty_output><jupyter_text>Overall, it seems that a characters role DOES factor into how hedges are used. This difference is most significant between protagonists and antagonists. Protagonists use WAY more hedges than antagonists do. There's a slight significant difference between how helpers and antagonists use hedges.  Antagonist Hedges Over Time<jupyter_code>ant_movies_early = ant_movies[ant_movies.Disney_Period == 'EARLY']
ant_movies_mid = ant_movies[ant_movies.Disney_Period == 'MID']
ant_movies_late = ant_movies[ant_movies.Disney_Period == 'LATE']

pro_movies_early = pro_movies[pro_movies.Disney_Period == 'EARLY']
pro_movies_mid = pro_movies[pro_movies.Disney_Period == 'MID']
pro_movies_late = pro_movies[pro_movies.Disney_Period == 'LATE']
stats.f_oneway(ant_movies_early.Hedges, ant_movies_mid.Hedges, ant_movies_late.Hedges) #hardly<jupyter_output><empty_output><jupyter_text>A barely siginificant three way difference. Let's narrow this.<jupyter_code>stats.ttest_ind(ant_movies_early.Hedges, ant_movies_mid.Hedges, equal_var=False) #nope
stats.ttest_ind(ant_movies_early.Hedges, ant_movies_late.Hedges, equal_var=False) #hardly
stats.ttest_ind(ant_movies_mid.Hedges, ant_movies_late.Hedges, equal_var=False)<jupyter_output><empty_output><jupyter_text>The only significant difference here is between the early and late periods. Between the early and late Disney Eras, an antagonist's use of hedges has gone down.  Protagonist Hedges Over Time<jupyter_code>stats.f_oneway(pro_movies_early.Hedges, pro_movies_mid.Hedges, pro_movies_late.Hedges) #way more significant<jupyter_output><empty_output><jupyter_text>Looks like in general, there's a significant difference between how protagonists use hedges over time<jupyter_code>stats.ttest_ind(pro_movies_early.Hedges, pro_movies_mid.Hedges, equal_var=False) #yep!
stats.ttest_ind(pro_movies_early.Hedges, pro_movies_late.Hedges, equal_var=False) #yep!
stats.ttest_ind(pro_movies_mid.Hedges, pro_movies_late.Hedges, equal_var=False) #NOPE!<jupyter_output><empty_output><jupyter_text>While protagonists' use of hedges over time has decreased, there's no significant difference between the mid and late periods.  Antagonists vs Protagonists Over Time<jupyter_code>stats.ttest_ind(pro_movies_early.Hedges, ant_movies_early.Hedges, equal_var=False) #nope
stats.ttest_ind(pro_movies_mid.Hedges, ant_movies_mid.Hedges, equal_var=False) #nope
stats.ttest_ind(pro_movies_late.Hedges, ant_movies_late.Hedges, equal_var=False) #nope<jupyter_output><empty_output><jupyter_text>Within each period, there is no significant difference between how often protagonists and antagonists use hedges.  By Gender and Role Overall<jupyter_code>pro_f = movies_gen_role_df[(movies_gen_role_df.Gender == 'f') & (movies_gen_role_df.Role == 'PRO')]
pro_m = movies_gen_role_df[(movies_gen_role_df.Gender == 'm') & (movies_gen_role_df.Role == 'PRO')]
ant_f = movies_gen_role_df[(movies_gen_role_df.Gender == 'f') & (movies_gen_role_df.Role == 'ANT')]
ant_m = movies_gen_role_df[(movies_gen_role_df.Gender == 'm') & (movies_gen_role_df.Role == 'ANT')]
stats.ttest_ind(pro_f.Hedges, pro_m.Hedges, equal_var=False) 
#female protagonists actually significantly fewer hedges than male protagonists
stats.ttest_ind(ant_f.Hedges, ant_m.Hedges, equal_var=False)
#female antagonists use significantly more hedges than male antagonists
stats.ttest_ind(pro_f.Hedges, ant_f.Hedges, equal_var=False)
stats.ttest_ind(pro_m.Hedges, ant_m.Hedges, equal_var=False)<jupyter_output><empty_output><jupyter_text>The most significant difference here is between male protagonists and antagonists, with male protagonists using significantly more hedges than male antagonists. Unlike what I predicted, female protagonists use fewer hedges than male protagonists, but female antagonists use more hedges than male antagonists.   Across Companies<jupyter_code>#### Across Companies
disney_f = movies_gen_df[(movies_gen_df.Gender == 'f') & (movies_gen_df.Disney_Period != 'DREAMWORKS')]
disney_m = movies_gen_df[(movies_gen_df.Gender == 'm') & (movies_gen_df.Disney_Period != 'DREAMWORKS')]
dw_f = movies_gen_df[(movies_gen_df.Gender == 'f') & (movies_gen_df.Disney_Period == 'DREAMWORKS')]
dw_m = movies_gen_df[(movies_gen_df.Gender == 'm') & (movies_gen_df.Disney_Period == 'DREAMWORKS')]
stats.ttest_ind(disney_m.Hedges, disney_f.Hedges, equal_var=False) # no significant difference
stats.ttest_ind(disney_f.Hedges, dw_f.Hedges, equal_var=False) #nope
stats.ttest_ind(disney_m.Hedges, dw_m.Hedges, equal_var=False) #nope
stats.ttest_ind(dw_m.Hedges, dw_f.Hedges, equal_var=False) #nope (but closer)
#slightly fewer hedges for female Dreamworks characters<jupyter_output><empty_output><jupyter_text>There are no significant differences based on gender across companies. What about role across companies?<jupyter_code>disney_pro = movies_role_df[(movies_role_df.Role == 'PRO') & (movies_role_df.Disney_Period != 'DREAMWORKS')]
disney_ant = movies_role_df[(movies_role_df.Role == 'ANT') & (movies_role_df.Disney_Period != 'DREAMWORKS')]
dw_pro = movies_role_df[(movies_role_df.Role == 'PRO') & (movies_role_df.Disney_Period == 'DREAMWORKS')]
dw_ant = movies_role_df[(movies_role_df.Role == 'ANT') & (movies_role_df.Disney_Period == 'DREAMWORKS')]
stats.ttest_ind(disney_pro.Hedges, disney_ant.Hedges, equal_var=False) # no significant difference
stats.ttest_ind(disney_pro.Hedges, dw_pro.Hedges, equal_var=False) #nope
stats.ttest_ind(disney_ant.Hedges, dw_ant.Hedges, equal_var=False) #nope
stats.ttest_ind(dw_pro.Hedges, dw_ant.Hedges, equal_var=False) #YES!
#Dreamworks antagonists use fewer hedges than Dreamworks protagonists<jupyter_output><empty_output><jupyter_text>Overall, disney antagonists use fewer hedges than dreamworks protagonists!  Gender and Role Over Time?<jupyter_code>early_pro_f = pro_f[pro_f.Disney_Period == 'EARLY']
early_pro_m = pro_m[pro_m.Disney_Period == 'EARLY']
early_ant_f = ant_f[ant_f.Disney_Period == 'EARLY']
early_ant_m = ant_m[ant_m.Disney_Period == 'EARLY']
mid_pro_f = pro_f[pro_f.Disney_Period == 'MID']
mid_pro_m = pro_m[pro_m.Disney_Period == 'MID']
mid_ant_f = ant_f[ant_f.Disney_Period == 'MID']
mid_ant_m = ant_m[ant_m.Disney_Period == 'MID']
late_pro_f = pro_f[pro_f.Disney_Period == 'LATE']
late_pro_m = pro_m[pro_m.Disney_Period == 'LATE']
late_ant_f = ant_f[ant_f.Disney_Period == 'LATE']
late_ant_m = ant_m[ant_m.Disney_Period == 'LATE']
#Female protagonists over time
stats.f_oneway(early_pro_f.Hedges, mid_pro_f.Hedges, late_pro_f.Hedges) #BIG DIFF!
stats.ttest_ind(early_pro_f.Hedges, mid_pro_f.Hedges, equal_var=False) #yep!
stats.ttest_ind(early_pro_f.Hedges, late_pro_f.Hedges, equal_var=False) #yep!
stats.ttest_ind(mid_pro_f.Hedges, late_pro_f.Hedges, equal_var=False) #no significant difference<jupyter_output><empty_output><jupyter_text>Female protagonists have used fewer hedges over time<jupyter_code>#Now looking at Male Protagonists over Time
stats.f_oneway(early_pro_m.Hedges, mid_pro_m.Hedges, late_pro_m.Hedges) #nope!
stats.ttest_ind(early_pro_m.Hedges, mid_pro_m.Hedges, equal_var=False) #nope!
stats.ttest_ind(early_pro_m.Hedges, late_pro_m.Hedges, equal_var=False) #nope!
stats.ttest_ind(mid_pro_m.Hedges, late_pro_m.Hedges, equal_var=False) #nope!<jupyter_output><empty_output><jupyter_text>Male protagonists have not changed how often they use hedges over time<jupyter_code>#Between male and female protagonists in each era!
stats.ttest_ind(early_pro_f.Hedges, early_pro_m.Hedges, equal_var=False) #nope!
stats.ttest_ind(mid_pro_f.Hedges, mid_pro_m.Hedges, equal_var=False) #nope!
stats.ttest_ind(late_pro_f.Hedges, late_pro_m.Hedges, equal_var=False) #yep!<jupyter_output><empty_output><jupyter_text>Within each era, whether the protagonists are male or female makes no significant difference in their use of hedges EXCEPT for the late era! In the late era, female protagonists use significantly fewer hedges than male protagonists Between Female Antagonists over Time<jupyter_code>#Female antagonists over time
stats.f_oneway(early_ant_f.Hedges, mid_ant_f.Hedges, late_ant_f.Hedges) #NO DIFF!
stats.ttest_ind(early_ant_f.Hedges, mid_ant_f.Hedges, equal_var=False) #NO!
stats.ttest_ind(early_ant_f.Hedges, late_ant_f.Hedges, equal_var=False) #NO!
stats.ttest_ind(mid_ant_f.Hedges, late_ant_f.Hedges, equal_var=False) #no significant difference<jupyter_output><empty_output><jupyter_text>Between Male Antagonists over Time<jupyter_code>#Male protagonists over time
stats.f_oneway(early_ant_m.Hedges, mid_ant_m.Hedges, late_ant_m.Hedges) #NO DIFF!
stats.ttest_ind(early_ant_m.Hedges, mid_ant_m.Hedges, equal_var=False) #NO!
stats.ttest_ind(early_ant_m.Hedges, late_ant_m.Hedges, equal_var=False) #NO!
stats.ttest_ind(mid_ant_m.Hedges, late_ant_m.Hedges, equal_var=False) #no significant difference<jupyter_output><empty_output><jupyter_text>Between Male Antagonists and Protagonists over Time<jupyter_code>#Differences in Hedge Use by Male Role Over Time
stats.ttest_ind(early_pro_m.Hedges, early_ant_m.Hedges, equal_var=False) #NO DIFF!
stats.ttest_ind(mid_pro_m.Hedges, mid_ant_m.Hedges, equal_var=False) #NO!
stats.ttest_ind(late_pro_m.Hedges, late_ant_m.Hedges, equal_var=False) #yep!<jupyter_output><empty_output><jupyter_text>Male protagonists are hedging way more than male antagonists in the late period Between Female Antagonists and Protagonists Over Time<jupyter_code>#Differences in Hedge Use by Female Role Over Time
stats.ttest_ind(early_pro_f.Hedges, early_ant_f.Hedges, equal_var=False) #NO DIFF!
stats.ttest_ind(mid_pro_f.Hedges, mid_ant_f.Hedges, equal_var=False) #NO!
stats.ttest_ind(late_pro_f.Hedges, late_ant_f.Hedges, equal_var=False) #NO!<jupyter_output><empty_output><jupyter_text>Between Female Antagonists and Male Antagonists over Time:<jupyter_code>#Between male and female antagonists in each era!
stats.ttest_ind(early_ant_f.Hedges, early_ant_m.Hedges, equal_var=False) #nope!
stats.ttest_ind(mid_ant_f.Hedges, mid_ant_m.Hedges, equal_var=False) #nope!
stats.ttest_ind(late_ant_f.Hedges, late_ant_m.Hedges, equal_var=False) #NOPE!<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1136698599852616, 'fraction_numerical': 0.001043969540653402, 'mean_word_length': 8.386167146974064, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 105, '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': '26', 'dir': 'jupyter-structured-clean-dedup', 'id': '445195', 'license': 'RSA-MD', 'n_tokens_mistral': 6282, 'n_tokens_neox': 6073, 'n_words': 1150, 'path': 'code/Analysis_code/Hedges.ipynb', 'repo_name': 'Data-Science-for-Linguists-2019/Animated-Movie-Gendered-Dialogue', 'size': '16284'}