Suicide=read.csv(file.choose("suicide"),header = T)
#DATA CLEANING...
Suicide<-na.omit(Suicide)
Suicide <- subset(Suicide, select = -country.year)
#Q1. Average of the Number of suicides and HDI for year?
mean(Suicide$suicides_no)
## [1] 206.1243
mean(Suicide$HDI.for.year)
## [1] 0.7766011
#Q2.What is the distribution of suicides between males and females in the dataset?
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
suicides_by_gender <- Suicide %>%
group_by(sex) %>%
summarise(total_suicides = sum(suicides_no))
print(suicides_by_gender)
## # A tibble: 2 × 2
## sex total_suicides
## <chr> <int>
## 1 female 411000
## 2 male 1313024
#Q3.What is the distribution of suicides before 2014 and after 2014 in the dataset?
library(dplyr)
Suicide$year <- as.numeric(Suicide$year)
Suicide <- Suicide %>%
mutate(before_2014 = ifelse(year < 2014, "Before 2014", "After 2014"))
suicides_by_year <- Suicide %>%
group_by(before_2014) %>%
summarise(total_suicides = sum(suicides_no))
print(suicides_by_year)
## # A tibble: 2 × 2
## before_2014 total_suicides
## <chr> <int>
## 1 After 2014 182389
## 2 Before 2014 1541635
#Q4.Which country has the highest number of suicide cases in the dataset?
library(dplyr)
suicides_by_country <- Suicide %>%
group_by(country) %>%
summarise(total_suicides = sum(suicides_no))
country_with_most_suicides <- suicides_by_country %>%
filter(total_suicides == max(total_suicides))
print(country_with_most_suicides)
## # A tibble: 1 × 2
## country total_suicides
## <chr> <int>
## 1 United States 355963
#Q5.Which is the country with the highest population among all countries represented in the dataset?
total_population <- aggregate(population ~ country, data = Suicide, FUN = sum)
max_population_country <- total_population[which.max(total_population$population), ]
print(max_population_country)
## country population
## 88 United States 2696244887
#Q7.What is the distribution of suicides among different age group in the dataset?
library(ggplot2)
r=ggplot(data = Suicide, aes(x = age, fill = sex)) +
geom_bar() +
labs(title = "Distribution of Suicides Among Different Age Groups",
x = "Age Group",
y = "Number of Suicides",
fill = "Sex") +
theme_minimal()
plotly::ggplotly(r)
#Q8.What is the population of male and female among different age group?
library(ggplot2)
w=ggplot(data = Suicide, aes(x = age, y = population, fill = sex)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "Population of Males and Females Among Different Age Groups",
x = "Age Group",
y = "Population",
fill = "Sex") +
theme_minimal()
plotly::ggplotly(w)
#Q9.What is the coorelation between GDP Per capita And HDI.for.year?
library(GGally)
## Warning: package 'GGally' was built under R version 4.3.3
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
library(ggplot2)
relation1<- cor(Suicide$gdp_per_capita....,Suicide$HDI.for.year)
relation2<-ggplot(data=Suicide,aes(x=gdp_per_capita....,y=HDI.for.year))+geom_point(color="springgreen3",size=-1)+geom_abline(intercept = 0,slope = 1)+geom_smooth(method="lm")+
labs(title = "correlation",
x="GDP",
y="HDI Per year")
plotly::ggplotly(relation2)
## `geom_smooth()` using formula = 'y ~ x'
#Q10. Correlogram of suicides_no,gdp_per_capita....,population,HDI.for.year,year.
library(corrplot)
## Warning: package 'corrplot' was built under R version 4.3.3
## corrplot 0.92 loaded
c1<-Suicide[, c("suicides_no","gdp_per_capita....","population","HDI.for.year","year")]
correlation_matrix <- cor(c1)
corrplot(correlation_matrix, method = "shade", addCoef.col = "white")

#Q11.What will be the multiple regression model of this dataset.
reg=lm(suicides_no~gdp_per_capita....+HDI.for.year+population,data=Suicide)
final= -5.387-5.695*200+6.921*100+1.184*150
print(final)
## [1] -274.687
#Q12.How does the suicide rate vary among different generations in Albania?
library(ggplot2)
albania_data <- Suicide[Suicide$country == "Albania", ]
ggplot(albania_data, aes(x = generation, y = suicides.100k.pop, fill = generation)) +
geom_boxplot() +
labs(title = "Distribution of Suicide Rates Among Different Generations in Albania",
x = "Generation",
y = "Suicides per 100k Population") +
scale_fill_manual(values = c("#FFA500", "#808080", "#008000", "#0000FF", "#800080", "#FF0000"))

#Q13. Standard deviation of Column suicide per 100k population?
standard_deviation <- sd(Suicide$suicides.100k.pop)
print(standard_deviation)
## [1] 17.36177
#Q14. Correlation between the Human Development Index (HDI) and suicide rate in Albania?
library(corrplot)
library(dplyr)
albania_data <- Suicide[Suicide$country == "Albania", ]
correlation <- cor(albania_data$HDI.for.year, albania_data$suicides.100k.pop)
print(correlation)
## [1] -0.1594833
#Q15.Correlation between population and suicide rate within each country?
library(dplyr)
grouped_data <- Suicide %>%group_by(country)
correlation_data <- grouped_data %>%
summarize(correlation = cor(population, suicides.100k.pop))
## Warning: There was 1 warning in `summarize()`.
## ℹ In argument: `correlation = cor(population, suicides.100k.pop)`.
## ℹ In group 2: `country = "Antigua and Barbuda"`.
## Caused by warning in `cor()`:
## ! the standard deviation is zero
print(correlation_data)
## # A tibble: 90 × 2
## country correlation
## <chr> <dbl>
## 1 Albania -0.224
## 2 Antigua and Barbuda NA
## 3 Argentina -0.487
## 4 Armenia -0.424
## 5 Australia 0.0573
## 6 Austria -0.224
## 7 Azerbaijan -0.656
## 8 Bahamas -0.0350
## 9 Bahrain 0.222
## 10 Barbados -0.125
## # ℹ 80 more rows
#Q16.In which countries do we see the most significant disparity between male and female suicide rates?
library(ggplot2)
library(dplyr)
Suicide_diff <- Suicide %>%
group_by(country) %>%
summarize(abs_diff = abs(mean(suicides.100k.pop[sex == "male"]) - mean(suicides.100k.pop[sex == "female"]))) %>%
arrange(desc(abs_diff))
ggplot(Suicide_diff, aes(x = reorder(country, -abs_diff), y = abs_diff)) +
geom_bar(stat = "identity", fill = "skyblue", color = "black") +
theme_minimal() +
labs(title = "Difference Between Male and Female Suicide Rates Across Countries",
x = "Country",
y = "Absolute Difference in Suicide Rates")
