Show the code
if (!require(ggplot2)) install.packages("ggplot2"); library(ggplot2)Loading required package: ggplot2
insert subtitle here
Background: Violence is a major public health issue globally, especially prevalent in the United States as the US continually has the highest rate of violent deaths compared to high-income countries (Grinshteyn & Hemenway, 2019). Violence is defined as the use of force to cause physical or mental harm to an individual or group (Rutherford et al., 2007). It is critical to address the issue of violence, as violence can cause psychological trauma, socio-behavioral issues, and physical/life threatening harm (Zimmerman & Posick, 2016). It is important to recognize how violence is preventable and how violence prevention approaches can be implemented to reduce violence and achieve community safety. Method: The aim of this study is to evaluate what violence prevention/intervention approach – policing, legislation, hospital-based intervention, community-based intervention, educational programs – is perceived as the most effective way to prevent violence and achieve safety and to evaluate if these perceptions differ by gender. A convenient sample was recruited by tabling on campus and in the broader Broome County area. The inclusion criteria for the study is adults who are 18 years of age or older and Binghamton University students or Broome County residents. Results: The violence prevention/intervention startegy perceived as the most effective way to prevent violence and acheive safety was educational programs. Generally both men and women rated educational programs from effective to highly effective, however men on average rated educational programs more highly effective than women did. Discussion: Results indicate the men may support care-based interventions more than women, however more research and evidence is needed to make this comparsion. Varation within the women’s data when rating the effectivness of educational programs could possibly be due to lack of considertion for other variables that affect womens’ perceptions around safety and violence.
educational programs, gender, care-based strategies, fear-based strategies, fear
if (!require(ggplot2)) install.packages("ggplot2"); library(ggplot2)Loading required package: ggplot2
library(readxl)
alldata <- read_excel("10.20.2025.data.team1.clean.xlsx", col_names=TRUE)
alldata[alldata == -99]<-NA
alldata[alldata == -50]<-NA
#source: (Wickham & Bryan, 2025) https://readxl.tidyverse.org/
#explanation: data was imported from excel. -99 and -50 data are filtered out as missing datalibrary(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
selectdata <- alldata %>% select(EFFECT_CARE_COMM, EFFECT_CARE_EDUCATION, EFFECT_CARE_HVIP, EFFECT_FEAR_LEG, EFFECT_FEAR_POLICE, GENDER)
selectdata <- na.omit(selectdata)
selectdata <- subset(selectdata, GENDER != 2)
#source: (Wickham et al., 2023) https://r4ds.hadley.nz/workflow-style.html#sec-pipes
##explanation: created new data frame with my intended variables. Omitted any NAs in the select data data set and filtered out Gender = 2 because their was only one response. # 0 - Girl or Woman
# 1 - Boy or Man
# 2 - Nonbinary, Genderfluid, or Genderqueer
# 3 - I am not sure or Questioning
#source: (Wickham et al., 2023) https://r4ds.hadley.nz/workflow-style.html#sec-pipes
##explanation: listed which code corresponded to which genderggplot(selectdata, mapping=aes(x=EFFECT_CARE_COMM)) +
geom_histogram(binwidth = 1, color = "black")#source: Normality Test in R: https://www.sthda.com/english/wiki/normality-test-in-r#google_vignette
##Explanation: checking for normality within the EFFECT_CARE_COMM data set using a Histogram ggplot(selectdata, mapping=aes(x=EFFECT_CARE_EDUCATION)) +
geom_histogram(binwidth = 1, color = "black")#source: Normality Test in R: https://www.sthda.com/english/wiki/normality-test-in-r#google_vignette
##Explanation: checking for normality within the EFFECT_CARE_EDUCATION data set using a Histogramggplot(selectdata, mapping=aes(x=EFFECT_CARE_HVIP)) +
geom_histogram(binwidth = 1, color = "black")#source: Normality Test in R: https://www.sthda.com/english/wiki/normality-test-in-r#google_vignette
##Explanation: checking for normality within the EFFECT_CARE_HVIP data set using a Histogramggplot(selectdata, mapping=aes(x= EFFECT_FEAR_LEG)) +
geom_histogram(binwidth = 1, color = "black")#source: Normality Test in R: https://www.sthda.com/english/wiki/normality-test-in-r#google_vignette
##Explanation: checking for normality within the EFFECT_FEAR_LEG data set using a Histogramggplot(selectdata, mapping=aes(x= EFFECT_FEAR_POLICE)) +
geom_histogram(binwidth = 1, color = "black")#source: Normality Test in R: https://www.sthda.com/english/wiki/normality-test-in-r#google_vignette
##Explanation: checking for normality within the EFFECT_FEAR_POLICE data set using a Histogrammean(selectdata$EFFECT_CARE_COMM)[1] 4.75
mean(selectdata$EFFECT_CARE_EDUCATION)[1] 4.803571
mean(selectdata$EFFECT_CARE_HVIP)[1] 3.928571
mean(selectdata$EFFECT_FEAR_LEG)[1] 4.303571
mean(selectdata$EFFECT_FEAR_POLICE)[1] 3.267857
sd(selectdata$EFFECT_CARE_COMM)[1] 1.099587
sd(selectdata$EFFECT_CARE_EDUCATION)[1] 1.150804
sd(selectdata$EFFECT_CARE_HVIP)[1] 0.9882426
sd(selectdata$EFFECT_FEAR_LEG)[1] 1.263755
sd(selectdata$EFFECT_FEAR_POLICE)[1] 1.34152
median(selectdata$EFFECT_CARE_COMM)[1] 5
median(selectdata$EFFECT_CARE_EDUCATION)[1] 5
median(selectdata$EFFECT_CARE_HVIP)[1] 4
median(selectdata$EFFECT_FEAR_LEG)[1] 4
median(selectdata$EFFECT_FEAR_POLICE)[1] 3
min(selectdata$EFFECT_CARE_COMM)[1] 1
min(selectdata$EFFECT_CARE_EDUCATION)[1] 1
min(selectdata$EFFECT_CARE_HVIP)[1] 2
min(selectdata$EFFECT_FEAR_LEG)[1] 1
min(selectdata$EFFECT_FEAR_POLICE)[1] 1
max(selectdata$EFFECT_CARE_COMM)[1] 6
max(selectdata$EFFECT_CARE_EDUCATION)[1] 6
max(selectdata$EFFECT_CARE_HVIP)[1] 6
max(selectdata$EFFECT_FEAR_LEG)[1] 6
max(selectdata$EFFECT_FEAR_POLICE)[1] 6
# source: (Cotton, 2024) https://campus.datacamp.com/courses/hypothesis-testing-in-r/introduction-to-hypothesis-testing-1?ex=3
##Explanation: evaluated the mean of each variable to see which variable is perceived as the most effective way to prevent violence and achieve safety? Also evaluated the standard deviation, median, min, and max of each variable to better statistically compare the variables. selectdata2 <- selectdata %>% select(EFFECT_CARE_EDUCATION, GENDER)
# source: (Wickham et al., 2023) https://r4ds.hadley.nz/data-visualize.html#the-penguins-data-frame
## Explanation: made new data frame to only include the variables EFFECT_CARE_EDUCATION and GENDER. Educational programs was rated the highest in terms of effectiveness therefore, I created this new data frame to compare how different genders perceive the effectiveness of educational programs in achieving safety and reducing violence. wilcox.test(selectdata2$EFFECT_CARE_EDUCATION, selectdata2$GENDER, paired=FALSE)
Wilcoxon rank sum test with continuity correction
data: selectdata2$EFFECT_CARE_EDUCATION and selectdata2$GENDER
W = 3126.5, p-value < 2.2e-16
alternative hypothesis: true location shift is not equal to 0
# source: (Cotton, 2024) https://campus.datacamp.com/courses/hypothesis-testing-in-r/non-parametric-tests?ex=10
##Explanation: Mann-Whitney U Test was used because I had non-normal distributed data for my independent variables. The test showed that there is a statistically significant difference in how men vs. women responded to the effectiveness of educational programs in achieving safety and reducing violence. selectdata2$GENDER <- factor(selectdata2$GENDER)
# source: (Wickham et al., 2023) https://r4ds.hadley.nz/factors.html
## explanation: Factored the variable "Gender" to turn the data into a categorical type.library(ggplot2)
plot_gender_effectiveness <- ggplot(selectdata2, aes(x =EFFECT_CARE_EDUCATION, fill = GENDER)) +
geom_bar() +
facet_wrap(~ GENDER,
labeller = as_labeller(c("0"= "Women", "1"= "Men"))) +
scale_fill_manual(
values = c("0" = "#F8766D", "1" = "#00BFC4"),
labels = c("Women","Men")) +
labs(
title = "Perceived Effectivenss by Gender",
x = "Effectiveness of Educational Programs",
y = "Number of Respondents",
fill = "Gender"
) +
theme_minimal()
theme(axis.text.x = element_text(angle = 45, hjust= 1),
panel.spacing = unit(1, "lines"))<theme> List of 2
$ axis.text.x : <ggplot2::element_text>
..@ family : NULL
..@ face : NULL
..@ italic : chr NA
..@ fontweight : num NA
..@ fontwidth : num NA
..@ colour : NULL
..@ size : NULL
..@ hjust : num 1
..@ vjust : NULL
..@ angle : num 45
..@ lineheight : NULL
..@ margin : NULL
..@ debug : NULL
..@ inherit.blank: logi FALSE
$ panel.spacing: 'simpleUnit' num 1lines
..- attr(*, "unit")= int 3
@ complete: logi FALSE
@ validate: logi TRUE
#print and save to plots folders
print(plot_gender_effectiveness) # source: Facets for ggplot2 in R: https://www.datacamp.com/tutorial/facets-ggplot-r?utm_cid=19589720830&utm_aid=192320612808&utm_campaign=230119_1-ps-other~dsa~tofu-tutorial_2-b2c_3-nam_4-prc_5-na_6-na_7-le_8-pdsh-go_9-nb-e_10-na_11-na&utm_loc=9005440-&utm_mtd=-c&utm_kw=&utm_source=google&utm_medium=paid_search&utm_content=ps-other~nam-en~dsa~tofu~tutorial~r&gad_source=1&gad_campaignid=19589720830&gbraid=0AAAAADQ9WsE-qQWqJzrNtLk3a92Tas6fv&gclid=Cj0KCQjw9obIBhCAARIsAGHm1mSIm-RYrKJvBT8eFnXOLvPH0K9Ad_Zrc5-Xa6MAYJXC5SAaWiN1SrYaAsliEALw_wcB
## explanation: geom_bar was used to create a bar chart. facet_wrap was used to create two bar charts side by side, making for more clear comparison. scale_fill_manual was used to assign different colors to women and men. ggsave("plots/plot1_gender_effectiveness.png",
plot = plot_gender_effectiveness,
width = 10, height = 8, dpi = 300)
# source: The Quantitative Playbook for Public Health Research in R (McCarty, 2025)
## explanation: saved plot one to plots folderlibrary(ggplot2)
# make gender a categorical value
selectdata2$GENDER <- factor(selectdata2$GENDER, levels = c(0, 1),
labels = c("Women", "Man"))
#Find means of Men and Women
means <- selectdata2 %>%
group_by(GENDER) %>%
summarise(mean_effect = mean(EFFECT_CARE_EDUCATION, na.rm = TRUE))
# ggplot density plot
plot2_gender_effectiveness <- ggplot(selectdata2, aes(x= EFFECT_CARE_EDUCATION, fill = GENDER))+
geom_density(alpha = 0.4) +
geom_vline(data = means, aes(xintercept = mean_effect, color = GENDER),
linetype = "dashed", size = 1) +
labs(title="Perceived Effectivenss by Gender",x="Effectiveness of Education Program", y = "Density") +
theme_minimal()Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
#print and save to plots folders
print(plot2_gender_effectiveness)# source:(Wickham et al., 2023) https://r4ds.hadley.nz/data-visualize.html#visualizing-distributions
#source: (Wickham et al., 2016) https://ggplot2.tidyverse.org/reference/geom_abline.html
## explanation: factor() function was used to make gender a categorical variable. Next the mean was found for both women and men. geom_density was used to create a density plot. geom_vline was used to display the mean for women and men as vertical lines. ggsave("plots/plot2_gender_effectiveness.png",
plot = plot2_gender_effectiveness,
width = 10, height = 8, dpi = 300)
# source: The Quantitative Playbook for Public Health Research in R (McCarty, 2025)
## explanation: saved plot two to plots folder
## Descriptive Statistics (Categorical Variable)
::: {.cell}
```{.r .cell-code}
selectdata2 %>%
group_by(GENDER) %>%
summarise(
mean = mean(EFFECT_CARE_EDUCATION, na.rm = TRUE),
sd = sd(EFFECT_CARE_EDUCATION, na.rm = TRUE),
median = median(EFFECT_CARE_EDUCATION, na.rm = TRUE),
min = min(EFFECT_CARE_EDUCATION, na.rm = TRUE),
max = max(EFFECT_CARE_EDUCATION, na.rm = TRUE))
# A tibble: 2 × 6
GENDER mean sd median min max
<fct> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Women 4.68 1.29 5 1 6
2 Man 5.05 0.780 5 4 6
# source: (Cotton, 2024) https://campus.datacamp.com/courses/hypothesis-testing-in-r/introduction-to-hypothesis-testing-1?ex=3
##Explanation: Evaluated the mean, sd, median, min, and max of men and women in terms of their rating of effectiveness of educational programs. Mean is higher for men, showing overall higher effectiveness rating of men. Standard deviation and range of data for women is higher, showing more variation in perceptions of effectiveness in women than men. :::