Lab 3
Introduction
library(tidyverse)
## -- Attaching core tidyverse packages ------------------------ tidyverse 2.0.0 --
## v dplyr 1.1.4 v readr 2.1.6
## v forcats 1.0.1 v stringr 1.6.0
## v ggplot2 4.0.1 v tibble 3.3.1
## v lubridate 1.9.4 v tidyr 1.3.2
## v purrr 1.2.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
## i Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
judges <-read.csv("judges.csv")
Question 1
The dataset contains 224 observations and 12 variables.
judges <- judges%>%
mutate(
gender_label =ifelse(woman==1, "Woman", "Man"),
party_label =ifelse(republican==1, "Rep appointee", "Dem appointee")
)
prop_table <- judges%>%
group_by(gender_label, party_label)%>%
summarise(count =n(), .groups = "drop")%>%
group_by(gender_label)%>%
mutate(proportion = count/ sum(count))
prop_table%>%
select(gender_label, party_label, count, proportion)
## # A tibble: 4 x 4
## # Groups: gender_label [2]
## gender_label party_label count proportion
## <chr> <chr> <int> <dbl>
## 1 Man Dem appointee 76 0.409
## 2 Man Rep appointee 110 0.591
## 3 Woman Dem appointee 27 0.711
## 4 Woman Rep appointee 11 0.289
1
In terms of gender, males and females have different representation among Democratic and Republican
appointees for judgeship (for instance, Republican presidents appoint more male judges). Women, however,
tend to be more likely than men to be appointed as Democratic judges (i.e., Democrats appoint a higher
proportion of females than Republicans do). Male judges tend to be appointed more often than female judges
from Republican presidents; however, while females tend to have a higher proportion of being appointed
Democrats, they also have the greatest adherence to a progressive voting record relative to male judges.
Question 2
ggplot(judges,aes(x = progressive.vote))+
geom_histogram(bins = 20)+
labs(title = "Distribution of Progressive Vote Share Among Circuit Court Judges",
x = "Progressive Vote Share",
y = "Count")
0
10
20
0.00 0.25 0.50 0.75 1.00
Progressive Vote Share
Count
Distribution of Progressive Vote Share Among Circuit Court Judges
The histogram shows that there is more of a grouping of progressive vote share for circuit court judges
in the middle of the range (approximately. 30 to. 60). This grouping indicates that judges tend to vote
progressively in a moderate fashion. There are also some judges in the lower part of the distribution and
one outlier who has an extremely progressive voting record.
2
Question 3
judges <- judges%>%
mutate(gender_party =ifelse(woman==0&republican==0, "Dem Man",
ifelse(woman==0&republican==1, "Rep Man",
ifelse(woman==1&republican==0, "Dem Woman", "Rep Woman"))))
group_means <- judges%>%
group_by(gender_party)%>%
summarise(mean_vote =mean(progressive.vote, na.rm = TRUE), .groups = "drop")%>%
mutate(gender_party =factor(gender_party,
levels =c("Dem Man", "Rep Man", "Dem Woman", "Rep Woman")))
group_means
## # A tibble: 4 x 2
## gender_party mean_vote
## <fct> <dbl>
## 1 Dem Man 0.507
## 2 Dem Woman 0.455
## 3 Rep Man 0.391
## 4 Rep Woman 0.307
ggplot(group_means,aes(x = gender_party, y = mean_vote))+
geom_bar(stat = "identity")+
labs(title = "Mean Progressive Vote Share by Gender and Party",
x = "Gender-Party Group",
y = "Mean Progressive Vote Share")
3
0.0
0.1
0.2
0.3
0.4
0.5
Dem Man Rep Man Dem Woman Rep Woman
Gender−Party Group
Mean Progressive Vote Share
Mean Progressive Vote Share by Gender and Party
From the bar chart, we see Democrats (regardless of gender) were favored by the highest mean progressive
vote share compared with Republicans. While there are significant differences in mean progressive vote
share within each party, male judges in both political affiliations have a higher mean progressive vote share
than their female counterparts (i.e. Male Democratic judges have a mean progressive vote share of 0.5 while
Female Democratic judges have a mean progressive vote share of 0.45; Male Republican judges have a mean
progressive vote share of 0.4 while Female Republican judges have a mean progressive vote share of 0.3).
Question 4
judges_with_children <- judges%>%
filter(child>0)
judges_with_children <- judges_with_children%>%
mutate(has_daughter =ifelse(girls>=1, "At least one daughter", "No daughters"))
ggplot(judges_with_children,aes(x = has_daughter, y = progressive.vote))+
geom_boxplot()+
labs(title = "Progressive Vote Share by Daughter Status",
x = "Daughter Status",
y = "Progressive Vote Share")
4
0.00
0.25
0.50
0.75
1.00
At least one daughter No daughters
Daughter Status
Progressive Vote Share
Progressive Vote Share by Daughter Status
result_with_daughter <- judges_with_children%>%
filter(has_daughter=="At least one daughter")%>%
summarise(mean_vote =mean(progressive.vote, na.rm = TRUE))
result_no_daughter <- judges_with_children%>%
filter(has_daughter=="No daughters")%>%
summarise(mean_vote =mean(progressive.vote, na.rm = TRUE))
mean_with_daughter <- result_with_daughter$mean_vote
mean_no_daughter <- result_no_daughter$mean_vote
diff_means <- mean_with_daughter-mean_no_daughter
The difference in mean progressive vote share between judges with at least one daughter and judges with no
daughters is 0.1101.
The box plot shows additional patterns that are not reflected in the means. First, judges with daughters
tend to have a higher median 0.44 versus 0.33 for judges without daughters. Additionally, judges without
daughters generally have tighter distributions than judges with daughters, who also have greater variability
in their progressive voting patterns. Overall, judges with no daughters will have much lower average vote
shares for progressive voting. Both groups also contain some extreme outliers, but judges with daughters
have an upward trend in the interquartile range compared to judges without daughters, suggesting that
judges with at least one daughter tend to vote more favorably on women’s issues.
5