<jupyter_start><jupyter_text>2015 US Mortality Data: Risk Factors for Suicide **Content**:- Introduction- Background- Methods- Findings- Discussion- Conclusion- References IntroductionThe value of life is priceless. However, each year, more than 40,000 people die by suicide in United States. Suicide is a major public health concern and is the 10th leading cause of death in the US.1 Luckily, suicide is preventable. Knowing risk factors for suicide can help prevent suicide. Risk factors for suicide are those characteristics associated with suicide, characteristics that make it more likely that individuals will consider, attempt, or die by suicide. They might not be direct causes.2This project explored single factor such as sex, age, marital status and the intersecting combination of them to see are those characteristics associated with suicide.The hypothesis verified in the project includes:- Are men more likely to suicide than women?- Are teenagers more likely to suicide?- Does marital status influence suicide?Besides answering the questions above, I also found some interesting facts of the comprehensive effect of combination of single factors, such as :- Men who are single are much more likely to suicide - Women who are widowed are less likely to suicide- Young men are more likely to suicide- Elder women are less likely to suicide. BackgroundSuicide is defined as death caused by self-directed injurious behavior with intent to die as a result of the behavior. Suicide is a major public health concern and it’s among the leading causes of death in the United States.3Risk factors for suicide are those characteristics associated with suicide, characteristics that increase the likelihood a individual will die by suicide. They might not be direct causes.2Many researches have been done to explore the risk factors for suicide. Thoes researches stated some interesting conclusions including that men are more likely to suicide than women, teenagers are more likely to suicide, marital status and education can influence suicide etc. To verify those conclusions, this project explored single factor such as sex, age, marital status to see if they are associated with suicide. The hypothesis verified in the project includes:- Are men more likely to suicide than women?- Are teenagers more likely to suicide?- Does marital status influence suicide?Since the risk factors for suicide are complex, to have a deeper understanding for the risk factors, I also performed analysis on intersecting combinations of thoes single factors.   Methods DataData used in this project is 2015 US Mortality Data from [CDC’s National Vital Statistics Systems](https://www.cdc.gov/nchs/data_access/vitalstatsonline.htmMortality_Multiple). It's under [CC0: Public Domain](https://creativecommons.org/publicdomain/zero/1.0/) license. The data includes 77 columns and 2,718,198 rows. Analytical MethodFirst, I performed a overall statistics analysis of the whole dataset to see how many death records do I have, and among those how many records are caused by suicide.I extracted suicide records out as sub dataset then I respectively classified whole dataset and suicide sub dataset by sex, marital status, and age. For each factor, I analyzed the count distribution of that factor among suicides. To have a different view of the effect of the factor, I also calculated the suicide ratio of each group. It's defined by Count of Suicide of that group / Count of Total Death of that group * 100%. Suicide ratio is a clearer indicator to show which group are more likely to suicide and which group are not.Since causes leading a human behavior are complex, we should also consider conprehensive effect of mixed factors besides of only considering effect of single factor in human-centered data science. Thus besides analyzing the effect of single factor, I also performed analysis on intersecting combinations of thoes single factors to figure out the comprehensive effect of mixed factors. The method is as similar as that of analyzing single factor. Findings<jupyter_code># import packages and data
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.read_csv('2015_data.csv')
df_suicide = df[df['manner_of_death'] == 2]
df.shape
df_suicide.shape
df_suicide.shape[0]/df.shape[0] * 100<jupyter_output><empty_output><jupyter_text>After loading the data, we can have a quick look at the data. In 2015 United States, there are 2,718,198 death record. Among them, 44417 died by suicide. That also means among all death, 1.63% died by suicide.  Are men more likely suicide than women?To answer this question, we can first have a look at the distribution of men and women among all people died by suicide in 2015, United States.<jupyter_code># suicide count by sex
sex_suicide = df_suicide.groupby(['sex'])['sex'].count()
sex_suicide
# plot distribution of sex among all suicides
x = np.arange(2)
fig, ax = plt.subplots()
fig.set_size_inches((6, 4))
plt.bar(x, sex_suicide.values, label = 'number of suicides')
for i, v in enumerate(sex_suicide / df_suicide.shape[0] * 100):
    ax.text(i - 0.1, v + 3, (str(round(v, 2)) + "%"), color='white')
plt.xticks(x, ['Women', 'Men'])
fig.suptitle('Distribution of Sex Among All Suicides (year 2015)')
ax.set_xlabel('Sex')
ax.set_ylabel('Count')
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>From the numbers and chart above, we can see that among people died by suicide in 2015, United States, 10256 are women, 34161 are men. Men make up 76.92% of the total suicides, while women make up 23.09%. The number of men seems to be as more than three times as many as women. But we can't conclude that men are more likely to suicide than women because the total death of men and women may be different. To solve the problem, I calculated the suicide ratio of men and women. It's defined by Count of Suicide / Count of Total Death * 100%. The relationship between suicide ratio and sex is shown as follows:<jupyter_code># suicide ratio by sex
sex_total = df.groupby(['sex'])['sex'].count()
sex_suicide_ratio = sex_suicide / sex_total * 100
sex_suicide_ratio
# plot suicide ratio vs. sex
x = np.arange(2)  
fig, ax = plt.subplots()
fig.set_size_inches((7, 4))
plt.bar(x,sex_suicide_ratio.values, label = 'suicide ratio')
for i, v in enumerate(sex_suicide_ratio):
    ax.text(i - 0.1, v + 0.07, (str(round(v, 2)) + "%"))
plt.xticks(x,['Women', 'Men'])
fig.suptitle('Suicide Ratio vs. Sex (year 2015)')
ax.set_xlabel('Sex')
ax.set_ylabel('Percentage')
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>We can see from the numbers and chart above, the suicide ratio of men is more than three times as much as women. So **it's true that men overall are more likely to suicide than women**.But why that happens? Are men easier to be impulsive? Are men faced at more pressure in sociaty than women? [Prof. <NAME>](https://loop.frontiersin.org/people/75947/overview) and his team from Auburn University in USA found there are four traits defined as “the acquired capability for suicide” which men are more likely to have than women. The traits are fearlessness of death, pain tolerance, emotional stoicism and sensation seeking. People experiencing a desire to commit suicide will not do so without first losing their fear of dying and developing the necessary pain tolerance to endure making a lethal attempt.4Here is the link of Prof. Gopikrishna Deshpande's full article : [A Neural Basis for the Acquired Capability for Suicide](https://www.frontiersin.org/articles/10.3389/fpsyt.2016.00125/full) Are teenagers more likely to suicide?To answer this question, I explored the relationship between age and suicide. The count of each age group is shown below.<jupyter_code># suicide count by age
age_suicide = df_suicide.groupby(['age_recode_12'])['age_recode_12'].count()
age_suicide<jupyter_output><empty_output><jupyter_text>The description of each code is as follows:|  Code | Description ||---| ---|| 03  | 5 - 14 years old|| 04  | 15 - 24 years old|| 05  | 25 - 34 years old|| 06  | 35 - 44 years old|| 07  | 45 - 54 years old|| 08  | 55 - 64 years old|| 09  | 65 - 74 years old|| 10  | 75 - 84 years old|| 11  | 85 years old and over|| 12  | Age not stated|The distribution of age in all suicides is shown below:<jupyter_code>age_index = ['5 - 14 years', '15 - 24 years', '25 - 34 years',
             '35 - 44 years','45 - 54 years','55 - 64 years','65 - 74 years',
            '75 - 84 years', '85 years and over', 'Age not stated']
# plot distribution of age among all suicides
x = np.arange(10)
fig, ax = plt.subplots()
fig.set_size_inches((9, 4))
plt.bar(x, age_suicide.values, label = 'number of suicides')
for i, v in enumerate(age_suicide / df_suicide.shape[0] * 100):
    ax.text(i - 0.35, v, (str(round(v, 2)) + "%"), color='white')
plt.xticks(x, age_index, rotation = 60)
fig.suptitle('Distribution of Age Among All Suicides (year 2015)')
ax.set_xlabel('Age')
ax.set_ylabel('Count')
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>Among total suicides in 2015, age group of 45-54 years old has the largest count, which is 8798, accounting for 19.81% of the total suicides. While age group 5-14 years old has the smallest count, which is 414, accounting for 0.93% of the total suicides.To compare the suicide situation of each age group, I also calculated the suicide ratio.<jupyter_code># suicide ratio by age
age_total = df.groupby(['age_recode_12'])['age_recode_12'].count()
age_suicide_ratio = age_suicide / age_total * 100
age_suicide_ratio = age_suicide_ratio[2:]
age_suicide_ratio
# plot suicide ratio vs. age
x = np.arange(10)
fig, ax = plt.subplots()
fig.set_size_inches((9, 4))
plt.bar(x, age_suicide_ratio.values, label = 'suicide ratio')
plt.xticks(x,age_index, rotation = 60)
for i, v in enumerate(age_suicide_ratio):
    ax.text(i - 0.3, v + 0.07, (str(round(v, 2)) + "%"))
fig.suptitle('Suicide Ratio vs. Age (year 2015)')
ax.set_xlabel('Age')
ax.set_ylabel('Percentage')
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>As the chart shown above, distribution of suicide ratio is very different from the distribution of suicide count. We can see that age group of 15-24 years old has the highest suicide ratio of 17.94%, which means among total death of age 15-24, 17.94% died by suicide. While age group of 85+ years old has the lowest suicide ratio of 0.14%, which means among total death of age 85+, only 0.14% died by suicide. As age increases, the suicide ratio decreases. We can conclude that **young people around 20 years old are more likely to suicide**.   Does marital status influence suicide? I used the same method to evaluate effect of marital status. The distribution of each matiral status group among all suicides is shown below:<jupyter_code># suicide count by marital status
marital_suicide = df_suicide.groupby(['marital_status'])['marital_status'].count()
marital_suicide<jupyter_output><empty_output><jupyter_text>The description of each code is as follows:|  Code | Description ||---| ---|| D  | Divorced|| M  | Married|| S  | Never married, single|| U  | Marital Status unknown|| W  | Widowed|<jupyter_code>marital_index = ['Divorced', 'Married', 'Never married, single',
             'Marital Status unknown','Widowed']
# plot distribution of marital status among all suicides
x = np.arange(5)
fig, ax = plt.subplots()
fig.set_size_inches((7, 4))
plt.bar(x, marital_suicide.values, label = 'number of suicides')
for i, v in enumerate(marital_suicide / df_suicide.shape[0] * 100):
    ax.text(i - 0.25, v, (str(round(v, 2)) + "%"), color='white')
plt.xticks(x, marital_index, rotation = 60)
fig.suptitle('Distribution of Marital Status Among All Suicides (year 2015)')
ax.set_xlabel('Marital Status')
ax.set_ylabel('Count')
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>Among total suicides in 2015, the group of people who are single(never married) has the largest count of 16063, accounting for 36.16% of the total suicides. While the group of people who are widowed has the smallest count of 2831, accounting for 6.37% of the total suicides.To compare the suicide situation of each age group, I also calculated the suicide ratio.<jupyter_code># suicide ratio by marital status
marital_total = df.groupby(['marital_status'])['marital_status'].count()
marital_suicide_ratio = marital_suicide / marital_total * 100
marital_suicide_ratio
# plot suicide ratio vs. marital status
x = np.arange(5)
fig, ax = plt.subplots()
fig.set_size_inches((9, 4))
plt.bar(x, marital_suicide_ratio.values, label = 'suicide ratio')
plt.xticks(x,marital_index, rotation = 60)
for i, v in enumerate(marital_suicide_ratio):
    ax.text(i - 0.1, v + 0.07, (str(round(v, 2)) + "%"))
fig.suptitle('Suicide Ratio vs. Marriage (year 2015)')
ax.set_xlabel('Marital Status')
ax.set_ylabel('Percentage')
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>As the chart shown above, distribution of suicide ratio is different from the distribution of suicide count. We can see that the group of people who are single(never married) has the highest suicide ratio of 4.57%, which means among total death people who are single, 4.57% died by suicide. While the group of people who are widowed has the lowest suicide ratio of 0.31%%, which means among total death people who are widowed, only 0.31% died by suicide. We can conclude that **people who are single(never married) are more likely to suicide then people who are divoced, married or widowed**. Comprehensive Effect of Sex and Marital StatusTo have a deeper understanding for the risk factors, I also performed analysis on intersecting combinations of thoes single factors. Here shows the comprehensive effect of sex and marital status.<jupyter_code>sex_marital_suicide = df_suicide.groupby(['marital_status', 'sex'])['sex'].count()
sex_marital_total = df.groupby(['marital_status', 'sex'])['sex'].count()
# Sex Distribution over Marital Status Among all Suicides
sex_marital_suicide_distribution = sex_marital_suicide / sex_suicide * 100
sex_marital_suicide_distribution
women = []
men = []
for i in range(len(sex_marital_suicide_distribution.values)):
    if i % 2 == 0:
        women.append(sex_marital_suicide_distribution.values[i])
    else:
        men.append(sex_marital_suicide_distribution.values[i])
# create plot
n_groups = 5
fig, ax = plt.subplots()
fig.set_size_inches(8,5)
index = np.arange(n_groups)
bar_width = 0.35
opacity = 0.8
 
rects1 = plt.bar(index, women, bar_width,
                 alpha=opacity,
                 color='b',
                 label='Women')
 
rects2 = plt.bar(index + bar_width, men, bar_width,
                 alpha=opacity,
                 color='g',
                 label='Men')
for i in range(n_groups):
    ax.text(index[i] - 0.2, women[i] + 1, (str(round(women[i], 2)) + "%"))
    ax.text(index[i] + 0.2, men[i] + 1, (str(round(men[i], 2)) + "%"))
plt.xlabel('Marital Status')
plt.ylabel('Percentage')
plt.title('Sex Distribution over Marital Status Among all Suicides (%)')
plt.xticks(index + bar_width, marital_index, rotation = 60)
plt.legend()
 
plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>Among all suicides, 26.56% of women are divorced, 34.65% are married, 29.94% are single and 8.11% are widowed, while 20.44% of men are divorced, 34.64% are married, 38.03 are single and 5.85% are widowed. This means that among all suicides, men and women who are married have similar percentage, women who are divorced or widowed are more than men who are also dicorced or widowed, women who are single are less than men who are also single.To explor the relationship in another view, I plot the suicide ratio distribution over marital status and sex.<jupyter_code># Distribution of Suicide Ratio over Sex and Marital Status
sex_marital_ratio_distribution = sex_marital_suicide / sex_marital_total * 100
sex_marital_ratio_distribution
women_ratio = []
men_ratio = []
for i in range(len(sex_marital_ratio_distribution.values)):
    if i % 2 == 0:
        women_ratio.append(sex_marital_ratio_distribution.values[i])
    else:
        men_ratio.append(sex_marital_ratio_distribution.values[i])
# create plot
n_groups = 5
fig, ax = plt.subplots()
fig.set_size_inches(8,5)
index = np.arange(n_groups)
bar_width = 0.35
opacity = 0.8
 
rects1 = plt.bar(index, women_ratio, bar_width,
                 alpha=opacity,
                 color='b',
                 label='Women')
 
rects2 = plt.bar(index + bar_width, men_ratio, bar_width,
                 alpha=opacity,
                 color='g',
                 label='Men')
for i in range(n_groups):
    ax.text(index[i] - 0.2, women_ratio[i] + 0.1, (str(round(women_ratio[i], 2)) + "%"))
    ax.text(index[i] + 0.2, men_ratio[i] + 0.1, (str(round(men_ratio[i], 2)) + "%"))
plt.xlabel('Marital Status')
plt.ylabel('Percentage')
plt.title('Distribution of Suicide Ratio over Sex and Marital Status(%)')
plt.xticks(index + bar_width, marital_index, rotation = 60)
plt.legend()
 
plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>In the visualization above, despite of unknown marital status groups, people are classified into 8 groups, men who are divoced, women who are divoced, men who are married, women who are married, men who are single, women who are single, men who are widowed, and women who are widowed. Among them, the group of men who are single has the highest suicide ratio of 5.95%, that means among all death who are men and single, 5.95% died by suicide. While the group of women who are widowed has the lowest suicide ratio of 0.12%, that means among all death who are women and widowed, only 0.12% died by suicide. Thus, we can conclude that men over each matital status have a higher suicide ratio than women. Besides that men who are single are much more likely to suicide. Women who are widowed are less likely to suicide.  Comprehensive Effect of Sex and AgeHere I classified age groups into 4 new groups. Age between 5-34 is definded to be "young", age between 35-64 is definded to be "mid aged", age between 65+ are defined to be "elder", other age and unknown age are definded to be "other".<jupyter_code>#  classify age groups into 4 new groups
age_group = []
for code in df['age_recode_12']:
    if code in [3, 4, 5]:
        age_group.append('young')
    elif code in [6, 7, 8]:
        age_group.append('mid aged')
    elif code in [9, 10, 11]:
        age_group.append('elder')
    else:
        age_group.append('other')

df['age_group'] = age_group
df_suicide = df[df['manner_of_death'] == 2]
sex_age_total = df.groupby(['age_group', 'sex'])['sex'].count()
sex_age_suicide = df_suicide.groupby(['age_group', 'sex'])['sex'].count()
# Sex Distribution over Age Among all Suicides
sex_age_suicide_distribution = sex_age_suicide / sex_suicide * 100
sex_age_suicide_distribution
women = []
men = []
for i in range(len(sex_age_suicide_distribution.values)):
    if i % 2 == 0:
        women.append(sex_age_suicide_distribution.values[i])
    else:
        men.append(sex_age_suicide_distribution.values[i])
# create plot
age_group_index = ['elder', 'mid aged', 'other', 'young']
n_groups = 4
fig, ax = plt.subplots()
fig.set_size_inches(8,5)
index = np.arange(n_groups)
bar_width = 0.35
opacity = 0.8
 
rects1 = plt.bar(index, women, bar_width,
                 alpha=opacity,
                 color='b',
                 label='Women')
 
rects2 = plt.bar(index + bar_width, men, bar_width,
                 alpha=opacity,
                 color='g',
                 label='Men')
for i in range(n_groups):
    ax.text(index[i] - 0.2, women[i] + 1, (str(round(women[i], 2)) + "%"))
    ax.text(index[i] + 0.2, men[i] + 1, (str(round(men[i], 2)) + "%"))
plt.xlabel('Age')
plt.ylabel('Percentage')
plt.title('Sex Distribution over Age Among all Suicides (%)')
plt.xticks(index + bar_width, age_group_index, rotation = 60)
plt.legend()
 
plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>Among all suicides in 2015, 13.49% of women are elder, 59.68% are mid aged, 26.79% are young, while 19.26% of men are elder, 51.0% are mid-aged, 29.72% are young. This means that among all suicides in 2015, women who are elder are less than men who are also elder, women who are mid-aged are more than men who are also mid-aged, women who are young are less than men who are young.To explor the relationship in another view, I plot the suicide ratio distribution over age and sex.<jupyter_code># Distribution of Suicide Ratio over Sex and Age
sex_age_ratio_distribution = sex_age_suicide / sex_age_total * 100
sex_age_ratio_distribution
women_ratio = []
men_ratio = []
for i in range(len(sex_age_ratio_distribution.values)):
    if i % 2 == 0:
        women_ratio.append(sex_age_ratio_distribution.values[i])
    else:
        men_ratio.append(sex_age_ratio_distribution.values[i])
# creat plot
n_groups = 4
fig, ax = plt.subplots()
fig.set_size_inches(8,5)
index = np.arange(n_groups)
bar_width = 0.35
opacity = 0.8
 
rects1 = plt.bar(index, women_ratio, bar_width,
                 alpha=opacity,
                 color='b',
                 label='Women')
 
rects2 = plt.bar(index + bar_width, men_ratio, bar_width,
                 alpha=opacity,
                 color='g',
                 label='Men')
for i in range(n_groups):
    ax.text(index[i] - 0.2, women_ratio[i] + 0.1, (str(round(women_ratio[i], 2)) + "%"))
    ax.text(index[i] + 0.2, men_ratio[i] + 0.1, (str(round(men_ratio[i], 2)) + "%"))
plt.xlabel('Age')
plt.ylabel('Percentage')
plt.title('Distribution of Suicide Ratio over Sex and Age(%)')
plt.xticks(index + bar_width, age_group_index, rotation = 60)
plt.legend()
 
plt.tight_layout()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09810679165517876, 'fraction_numerical': 0.02752504365407591, 'mean_word_length': 4.44075, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 54, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '461242', 'license': 'MIT', 'n_tokens_mistral': 7133, 'n_tokens_neox': 6410, 'n_words': 2610, 'path': 'Risk Factors for Suicide.ipynb', 'repo_name': 'runlaizeng/test', 'size': '21777'}