Week 2 Data Dive - Summaries : Chandler Davis

In this week’s data dive, I will be doing a basic summary and analysis of my data that I chose.

The data that I will be analyzing is the data_aging_congress.csv where it has an entry for every member of congress who served at any point during a particular congress between January 1947 and February 2014.

I will be using the data to look at the statistics regarding the age of each congress, how many terms they served, what party are they affiliated with, what chamber they were in, what generation they were apart of, and what state they are from.

The following code reads the CSV file and shows an overview of the data.

library(tidyverse)  
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
cdata <- read.csv("/Users/cadgo/Downloads/data_aging_congress.csv")
cdf <- data.frame(cdata)

Numeric Summary of Data

Here I will be doing a basic analysis of some data points within the file. I will be looking for how many unique members have been in congress, their age statistics, their term statistics, generations statistics, and state statistics.

Unique Members

unique_members <- length(unique(cdf$bioname))
print(paste0('There are ', unique_members , ' unique members of congress in the dataset'))
## [1] "There are 5251 unique members of congress in the dataset"

Average Age

age_mean <- mean(cdf$age_years)
print(paste0('The average age of a congressman at the start of each new term is ', age_mean))
## [1] "The average age of a congressman at the start of each new term is 53.7324753104527"

Oldest Age at the start of the term

age_max <- max(cdf$age_years)
print(paste0('The oldest congressman in congress was ', age_max, ' years old'))
## [1] "The oldest congressman in congress was 98.0807665982204 years old"

Youngest Age at the start of the term

age_min <- min(cdf$age_years)
print(paste0('The youngest congressman in congress was ', age_min , ' years old'))
## [1] "The youngest congressman in congress was 23.6659822039699 years old"

Quantile Distribution

quant <- quantile(cdf$age_years, probs=c(0.25, 0.5, 0.75))
print(paste0('The quantile distribution of the age of congressman are as follows')) 
## [1] "The quantile distribution of the age of congressman are as follows"
quant
##      25%      50%      75% 
## 45.80972 53.45106 61.21629

Number of members in each chamber

counthouse <- table(cdf$chamber)
print('The number of members in each chamber are as follows')
## [1] "The number of members in each chamber are as follows"
counthouse
## 
##  House Senate 
##  23622   5498

Number of members from each generation

gens <- table(cdf$generation)
knitr::kable(gens, format = "html")
Var1 Freq
Boomers 5108
Gen X 1130
Gen Z 1
Gilded 15
Greatest 7147
Lost 4732
Millennial 133
Missionary 4768
Progressive 485
Silent 5601

Number of unique members from each generation

uniqdf <- data.frame(cdata)
uniqdf <- uniqdf %>% distinct(bioname, .keep_all = TRUE)
uniqdfs <- uniqdf[order(uniqdf$birthday, decreasing = TRUE), ]
uniquegens <- table(uniqdfs$generation)
knitr::kable(uniquegens, format = "html",)
Var1 Freq
Boomers 848
Gen X 316
Gen Z 1
Gilded 6
Greatest 1108
Lost 912
Millennial 69
Missionary 1087
Progressive 155
Silent 749

Number of members from each state

states <- table(cdf$state_abbrev)
knitr::kable(states, format = "html")
Var1 Freq
AK 102
AL 553
AR 391
AZ 328
CA 2070
CO 387
CT 417
DE 164
FL 876
GA 719
HI 136
IA 487
ID 218
IL 1361
IN 684
KS 407
KY 546
LA 531
MA 792
MD 501
ME 246
MI 997
MN 577
MO 704
MS 418
MT 203
NC 749
ND 199
NE 321
NH 219
NJ 847
NM 230
NV 203
NY 2165
OH 1263
OK 462
OR 339
PA 1588
RI 227
SC 457
SD 203
TN 609
TX 1491
UT 242
VA 669
VT 173
WA 505
WI 614
WV 362
WY 168

Number of members from each party code

party <- table(cdf$party_code)
knitr::kable(party, format = "html")
Var1 Freq
100 15804
112 3
200 13181
328 44
329 3
331 2
347 1
356 1
370 29
380 4
402 1
522 7
523 1
537 39

Number of members from each new term of congress

congress_num <- table(cdf$congress)
knitr::kable(congress_num, format = "html")
Var1 Freq
66 555
67 560
68 557
69 548
70 551
71 567
72 563
73 547
74 549
75 554
76 561
77 561
78 554
79 564
80 553
81 553
82 553
83 552
84 540
85 545
86 552
87 558
88 551
89 548
90 543
91 551
92 548
93 548
94 551
95 551
96 544
97 545
98 544
99 541
100 544
101 545
102 548
103 546
104 543
105 544
106 539
107 547
108 539
109 540
110 549
111 553
112 546
113 548
114 541
115 555
116 544
117 551
118 536

Questions to Investigate

After looking at the above data, I have some questions that I would like to answer upon further investigation:

What is the average age of congress members in each congress?

What is the average age of congress members in each generation?

What states had the fewest unique members of congress (or most amount of incumbent congressmen)?

What is the average age of congress members in each state?

What is the average amount of terms in congress for each generation?

Plots

The following plot will visualize the average age of each congress over the years. The x-axis is each congress number, and the y-axis is age. The gray dots show each individual member in that congress and their age. The blue line shows the average age in each congress.

congress_number <- cdf$congress 
age <- cdf$age_years
cdf |>
  ggplot(mapping = aes(x = congress_number, y = age)) + 
  geom_point(color = "gray") +
  geom_smooth(se = FALSE) +
  theme_classic() +
  labs(title = "Average Age In Each Congress",
       x = "Congress Number",
       y = "Age")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

In this plot, the blue line shows the average amount of accumulated terms in each congress. The gray dots represent each member’s amount of served time in each congress session.

cdf |>
  ggplot(mapping = aes(x = congress_number, y = cmltv_cong)) + 
  geom_point(color = "gray") +
  geom_smooth(se = FALSE) +
  theme_classic() +
  labs(title = "Average tenure In Each Congress",
       x = "Congress Number",
       y = "Cumulative Terms of each member")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

The following plot shows the age versus amount of terms in office comparison for each generation. This shows the correlation between congressman getting older and the amount of terms they have served.

cong_gen <- cdf$generation
cdf |>
  ggplot(mapping = aes(cmltv_cong, age_years)) +
  geom_point(data = mutate(cdf, generation = NULL), colour = "grey85") +
  geom_point(color = "darkblue") +
  facet_wrap(vars(generation)) +
  theme_classic() +
  labs(title = "Age vs Terms by Generation",
       x = "Terms in Congress",
       y = "Age")

This bar plot shows the curve of how many terms are served by members of congress. Everyone in the data has at least served one term, and the amount they serve after that drops off at a steady percentage term by term.

cdf |>
  ggplot() +  
  geom_bar(mapping = aes(x = cmltv_cong)) +
  theme_minimal()