Hi there! Welcome to my data visualization land. Today I will use
the data about judges and the number of children they have to do the
pro-feminist analysis.
Import Data and observe it.
judges <- read.csv("C:/R-language/PBA/judges.csv",header = TRUE)
#install.packages("crosstable")
library(crosstable)
## Warning: 套件 'crosstable' 是用 R 版本 4.2.2 來建造的
crosstable(judges,c(woman,republican),by=republican)
## # A tibble: 2 × 5
## .id label variable `0` `1`
## <chr> <chr> <chr> <chr> <chr>
## 1 woman woman 0 82 (39.81%) 124 (60.19%)
## 2 woman woman 1 27 (71.05%) 11 (28.95%)
#install.packages("gmodels")
library(gmodels)
## Warning: 套件 'gmodels' 是用 R 版本 4.2.2 來建造的
gender_rep_table <- CrossTable(judges$woman,judges$republican);gender_rep_table
##
##
## Cell Contents
## |-------------------------|
## | N |
## | Chi-square contribution |
## | N / Row Total |
## | N / Col Total |
## | N / Table Total |
## |-------------------------|
##
##
## Total Observations in Table: 244
##
##
## | judges$republican
## judges$woman | 0 | 1 | Row Total |
## -------------|-----------|-----------|-----------|
## 0 | 82 | 124 | 206 |
## | 1.092 | 0.882 | |
## | 0.398 | 0.602 | 0.844 |
## | 0.752 | 0.919 | |
## | 0.336 | 0.508 | |
## -------------|-----------|-----------|-----------|
## 1 | 27 | 11 | 38 |
## | 5.920 | 4.780 | |
## | 0.711 | 0.289 | 0.156 |
## | 0.248 | 0.081 | |
## | 0.111 | 0.045 | |
## -------------|-----------|-----------|-----------|
## Column Total | 109 | 135 | 244 |
## | 0.447 | 0.553 | |
## -------------|-----------|-----------|-----------|
##
##
## $t
## y
## x 0 1
## 0 82 124
## 1 27 11
##
## $prop.row
## y
## x 0 1
## 0 0.3980583 0.6019417
## 1 0.7105263 0.2894737
##
## $prop.col
## y
## x 0 1
## 0 0.75229358 0.91851852
## 1 0.24770642 0.08148148
##
## $prop.tbl
## y
## x 0 1
## 0 0.33606557 0.50819672
## 1 0.11065574 0.04508197
We can see there are 244 judges in this data set. 84.4% of judges
are men, and the party composition(otherwise:Republican) for women is
0.398:0.602, whereas for man is 0.711:0.289.
Now I want to investigate whether judges support the woman’s issues
depends on their gender?
require(ggplot2)
## 載入需要的套件:ggplot2
## Warning: 套件 'ggplot2' 是用 R 版本 4.2.2 來建造的
x <- ggplot(judges, aes(x = progressive_vote, fill = as.factor(woman)))
x1 <- x + geom_histogram(bins = 10); x1

We can notice that the highest density of progressive_vote is
between 0.25 to 0.5 whether the gender of judges is woman or not, which
means that most of judges didn’t completely support the woman’s
issues.
According to the result, I’m curious about the progressive vote
between two party, so I use tapply() to calculate the mean of
progressive_vote in each of these groups.
require(dplyr)
## 載入需要的套件:dplyr
##
## 載入套件:'dplyr'
## 下列物件被遮斷自 'package:stats':
##
## filter, lag
## 下列物件被遮斷自 'package:base':
##
## intersect, setdiff, setequal, union
judges$gender_party <- case_when(
judges$republican == 0 & judges$woman == 1 ~ "F_Demo",
judges$republican == 1 & judges$woman == 1 ~ "F_Repub",
judges$republican == 0 & judges$woman == 0 ~ "M_Demo",
judges$republican == 1 & judges$woman == 0 ~ "M_Repub",
TRUE ~ "other"
)
gender_party_means <- tapply(judges$progressive_vote,judges$gender_party,mean);gender_party_means
## F_Demo F_Repub M_Demo M_Repub
## 0.4547162 0.3069867 0.5062359 0.3952614
barplot(height = gender_party_means,col = 'orange')

According to the bar chart, the Democratic party has a higher
proportion on progressive_vote rate in both woman and man. Although
there are lower than a half of progressive_vote rate in two party, the
democratic party tends to support it more.
Will judges with at least 1 girl tend to support woman issues more?
Let’s see:
we seperate to two dimensions first:
judges$any_girls <- ifelse(judges$girls >= 1,1,0)
parents <- subset(judges,child >= 1)
ATE <- tapply(judges$progressive_vote,judges$any_girls,mean);ATE
## 0 1
## 0.3878099 0.4518024
g <- ggplot(judges, aes(x = progressive_vote, fill = as.factor(any_girls)))
g1 <- g + geom_histogram(bins = 10); g1

Then we seperate it in more detail:
BTE <- tapply(judges$progressive_vote,judges$girls,mean);BTE
## 0 1 2 3 4 5
## 0.3878099 0.4488561 0.4491672 0.4980700 0.2142857 0.5625000
g <- ggplot(judges, aes(x = progressive_vote, fill = as.factor(girls)))
g1 <- g + geom_histogram(bins = 10); g1

It is shown that people who have at least one daughter would tend to
make a decision in a pro-feminist direction.
But it seems like no significant difference which is caused by the
judges having a daughter. Trying to make sure it is right and be more
precisely, I divide the number of daughters that judges have into 6
factors.
After dropping the outliers (judges have 4 or 5 daughters) as their
samples are too small, there is a rising trend on this chart, and it is
apparent to say that the more daughters judges have, you will be more
willing to vote on woman’s issues.
That’s all my observation. See you next time!