library(tidyverse)
library (dplyr)
library (ggfortify)
library(plotly)
setwd("/Users/jeffreyren/Downloads/Directory")
suidata <- read_csv("sui.csv")Project 2
Introduction
This dataset is an extensive dataset about suicide rates and socioeconomic factors I found on Kaggle using World Bank and World Health Organization as sources for the data. It includes data from almost every country, as well as almost every year from 1990 to 2022. The suicide rates variables include the total number, crude rate per 100,000, and also an age-standardized rate for more accuracy. The socioeconomic variables include population, GDP, GNI, GPD and GNI per capita, inflation rate, and employment-population ratio. I chose this data set because me and my friend were discussing this topic recently and it caught my eye when I saw a data set about this.I decided to clean the data set for five specific countries, and the reasoning for that would be discussed in the conclusion essay.
Loaded in the necessary libraries and read the csv.
I filtered for these countries because these are the five highest countries (that exist in the dataset) in terms of depression rate according to https://gitnux.org/countries-with-highest-depression-rate/
filter1 <- suidata |>
filter((CountryCode %in% c("USA", "UKR", "NLD", "COL", "BRA")) & (Year == 2019))
filter2 <- suidata |>
filter((CountryCode %in% c("USA", "UKR", "NLD", "COL", "BRA")) & (Year %in% 1990:2020) & (Sex == "Male")) Analyze the linear regression.
datalm <- lm (StdDeathRate ~ GDPPerCapita, data = filter2)
summary(datalm)
Call:
lm(formula = StdDeathRate ~ GDPPerCapita, data = filter2)
Residuals:
Min 1Q Median 3Q Max
-11.615 -8.267 -3.377 4.082 31.410
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.712e+01 1.244e+00 13.761 <2e-16 ***
GDPPerCapita -6.447e-05 4.414e-05 -1.461 0.146
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 10.78 on 145 degrees of freedom
(5 observations deleted due to missingness)
Multiple R-squared: 0.0145, Adjusted R-squared: 0.007708
F-statistic: 2.134 on 1 and 145 DF, p-value: 0.1462
autoplot(datalm, 1:4, nrow=2, ncol=2)Created a line graph of suicide rates of males in 5 countries with some of the highest depression rates from 1990 to 2020 using geom line and geom point. Used ggplotly to add interactivity.
linegraph <- ggplot(filter2, aes(x = Year, y = StdDeathRate, color = CountryName)) +
geom_line() +
geom_point() +
labs(x = "Year", y = "Age Standardized Suicide Rate (Per 100,000)",
title = "Suicide Rates of Males in 5 Countries With Some of the Highest Depression Rates (1990-2020)",
caption = "Data sources: World Health Organization, World Bank Data, and Gitnux.org") +
theme_minimal() +
scale_color_manual(values = c(Ukraine = "blue", Brazil = "green", Colombia = "yellow", Netherlands = "purple", `United States of America` = "red"))
ggplotly(linegraph)I couldn’t include both male and female in the line graph so I made a bar graph of the countries with both genders in 2019 using geom col.
barplot <- ggplot(filter1, aes(x = CountryName, y = StdDeathRate, fill = Sex)) +
geom_col(position = "dodge") +
labs(title = "Suicide Rates by Country in 2019",
x = "Country",
y = "Suicide Rate",
fill = "Gender") +
scale_fill_manual(values = c("red", "blue", "gray"))
ggplotly(barplot)