Week 3 Data Dive

In this data dive, I will be looking at the average age and average amount of terms served across multiple groups.

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
cdata <- read.csv("/Users/cadgo/Downloads/data_aging_congress.csv")
cdf <- data.frame(cdata)

Group By Data Frames

Below is where I grouped the data by congress to show their mean age and the mean amount of terms in congress.

total_rows <- length(cdf$party_code)
cdf_congress <- cdf |>
  group_by(congress) |>
  summarise(total_count = n(),
            probability = total_count/total_rows,
            mean_age = mean(age_years),
            mean_terms_served = mean(cmltv_cong))
cdf_congress
## # A tibble: 53 × 5
##    congress total_count probability mean_age mean_terms_served
##       <int>       <int>       <dbl>    <dbl>             <dbl>
##  1       66         555      0.0191     51.7              4.04
##  2       67         560      0.0192     52.6              4.01
##  3       68         557      0.0191     52.6              4.01
##  4       69         548      0.0188     53.2              4.31
##  5       70         551      0.0189     54.0              4.73
##  6       71         567      0.0195     54.6              4.90
##  7       72         563      0.0193     54.4              4.96
##  8       73         547      0.0188     53.5              4.17
##  9       74         549      0.0189     52.6              4.16
## 10       75         554      0.0190     52.5              4.25
## # ℹ 43 more rows
cdf_congress |>
  ggplot(mapping = aes(x = congress, y = mean_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 = 'loess' and formula = 'y ~ x'

In the above table and graph, you can see the change in the average age of congress over the years. Starting at about Congress number 100, the average age has seemed to increase consistently after a dip in the age.

cdf_congress |>
  ggplot(mapping = aes(x = congress, y = mean_terms_served)) + 
  geom_point(color = "gray") +
  geom_smooth(se = FALSE) +
  theme_classic() +
  labs(title = "Average Terms Served In Each Congress",
       x = "Congress Number",
       y = "Terms Served")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

The above graph shows the gradual increase in the average amount of terms served by members of congress over the years.

Both graphs and the data shows that congress is now the oldest and most experienced group ever in American history. I believe this is due to an increasing percentage of the population continuing to vote for incumbent career politicians instead of voting newer, younger candidates into office. This can be tested be looking at voting data for the past 100 years or so.

The probability and count numbers don’t give us a huge amount of information in the table. The count number just shows how many people are counted for each congress section, and you can reference that column to the amount that served in that year by looking online. It wasn’t until 1929 until the Federal Government froze the number of seats in the House of Representatives at 435, where now Congress has 535 members in total each term from then until present. (https://www.npr.org/2021/04/20/988865415/stuck-at-435-representatives-why-the-u-s-house-hasnt-grown-with-census-counts)

My hypothesis for why there are more counted in the data than seats available is that there are multiple people that serve for an area, either because of a death, firing, resignation, suspension, or sabbatical by the incumbent member. That would require more research to find out how many members left without having been voted out of office.

total_rows <- length(cdf$party_code)
cdf_chamber <- cdf |>
  group_by(chamber) |>
  summarise(total_count = n(),
            probability = total_count/total_rows,
            mean_age = mean(age_years),
            mean_terms_served = mean(cmltv_cong))
cdf_chamber
## # A tibble: 2 × 5
##   chamber total_count probability mean_age mean_terms_served
##   <chr>         <int>       <dbl>    <dbl>             <dbl>
## 1 House         23622       0.811     52.8              5.01
## 2 Senate         5498       0.189     57.9              7.13

The table above shows the average age and the average amount of terms served by members of the house and senate. As shown above, members of the senate on average are older and have served more terms in congress than members of the house.

The probability column just represents the percentage of the data that are in either chamber. Out of all the members of congress that are represented in the data, 81% served in the house and 18% served in the senate.

My hypothesis for the data is that since there is a greater age requirement to be in the senate, fewer members, and the house of representatives being the stepping stone to the senate, that the members are older and more tenured than the house of representatives.

cdf_chamber |>
  ggplot() +  
  geom_col(mapping = aes(x = chamber, y = mean_age)) +
  theme_minimal()

cdf_chamber |>
  ggplot() +  
  geom_col(mapping = aes(x = chamber, y = mean_terms_served)) +
  theme_minimal()

total_rows <- length(cdf$party_code)
cdf_state <- cdf |>
  group_by(state_abbrev) |>
  summarise(total_count = n(),
            probability = total_count/total_rows,
            mean_age = mean(age_years),
            mean_terms_served = mean(cmltv_cong))
cdf_state
## # A tibble: 50 × 5
##    state_abbrev total_count probability mean_age mean_terms_served
##    <chr>              <int>       <dbl>    <dbl>             <dbl>
##  1 AK                   102     0.00350     59.0              7.74
##  2 AL                   553     0.0190      53.3              6.02
##  3 AR                   391     0.0134      52.4              5.76
##  4 AZ                   328     0.0113      54.9              6.17
##  5 CA                  2070     0.0711      54.4              5.33
##  6 CO                   387     0.0133      54.4              4.38
##  7 CT                   417     0.0143      51.7              4.53
##  8 DE                   164     0.00563     55.7              5.34
##  9 FL                   876     0.0301      53.6              5.31
## 10 GA                   719     0.0247      53.9              5.15
## # ℹ 40 more rows

In the table above, it shows the average age and average amount of terms served grouped by state. The total_count shows how many representatives are from each state and the probability shows the percentage that they make up of the amount of members in congress. We can see for large states, like California and New York, have far more representatives than states like Alaska and Delaware.

The states with more representatives are the states with the largest portion of the United States population, hence why they have more representatives serving in the House of Representatives and make up for a large portion of congress.

total_rows <- length(cdf$party_code)
cdf_party <- cdf |>
  group_by(party_code) |>
  summarise(total_count = n(),
            probability = total_count/total_rows,
            mean_age = mean(age_years),
            mean_terms_served = mean(cmltv_cong))
cdf_party
## # A tibble: 14 × 5
##    party_code total_count probability mean_age mean_terms_served
##         <int>       <int>       <dbl>    <dbl>             <dbl>
##  1        100       15804   0.543         53.7              5.78
##  2        112           3   0.000103      49.8              2   
##  3        200       13181   0.453         53.8              4.98
##  4        328          44   0.00151       64.0              7.84
##  5        329           3   0.000103      43.1              1   
##  6        331           2   0.0000687     51.7              2   
##  7        347           1   0.0000343     53.6              3   
##  8        356           1   0.0000343     54.0              1   
##  9        370          29   0.000996      53.8              4.52
## 10        380           4   0.000137      61.1              3   
## 11        402           1   0.0000343     34.4              1   
## 12        522           7   0.000240      40.4              4   
## 13        523           1   0.0000343     42.2              4   
## 14        537          39   0.00134       52.5              2.87
f_cdf <- cdf[cdf$party_code %in% c('100','200'),]
f_cdf1 <- f_cdf |>
    group_by(congress, party_code) |>
      summarise(total_count = n(),
            probability = total_count/(total_rows),
            mean_age = mean(age_years))
## `summarise()` has grouped output by 'congress'. You can override using the
## `.groups` argument.
f_cdf1
## # A tibble: 106 × 5
## # Groups:   congress [53]
##    congress party_code total_count probability mean_age
##       <int>      <int>       <int>       <dbl>    <dbl>
##  1       66        100         253     0.00869     51.1
##  2       66        200         299     0.0103      52.3
##  3       67        100         178     0.00611     52.0
##  4       67        200         380     0.0130      52.9
##  5       68        100         261     0.00896     51.1
##  6       68        200         291     0.00999     53.9
##  7       69        100         227     0.00780     52.3
##  8       69        200         315     0.0108      53.9
##  9       70        100         247     0.00848     53.0
## 10       70        200         300     0.0103      54.7
## # ℹ 96 more rows

The table above shows the data grouped by congress and party code. It shows how often they were counted in the data and the average age. This table will be used to create the two line graphs below to show the change in age of each party in congress over time.

dem_cdf <- f_cdf1[f_cdf1$party_code == '100',]
dem_cdf |> 
        ggplot(mapping = aes(x = congress, y = mean_age)) + 
        geom_line(color = "blue") +
        geom_point(color = "blue") +
        theme_classic() +
        labs(title = "Average age in the Democratic Party in each congress",
           x = "Congress Number",
           y = "Age")

This table shows the average age of the democratic party members in congress over time. There was a decline to it’s lowest at around 50 years old before it increased significantly until the most recent congress session at around 60 years old. That shows that in about 20 congress sessions, the average age of the democratic party has increased by 10 years.

rep_cdf <- f_cdf1[f_cdf1$party_code == '200',]
rep_cdf |> 
        ggplot(mapping = aes(x = congress, y = mean_age)) + 
        geom_line(color = "red") +
        geom_point(color = "red") +
        theme_classic() +
        labs(title = "Average age in the republican party in each congress",
           x = "Congress Number",
           y = "Age")

This table shows the average age of the republican party members in congress over time. As you see between the republicans and the democrats, their trends are generally very similar. The republican party on average is a little bit younger than their democratic party counterparts.

Possible Combinations

gb_df <- f_cdf |>
    group_by(chamber, party_code) |>
      summarise(total_count = n(),
            probability = total_count/(total_rows))
## `summarise()` has grouped output by 'chamber'. You can override using the
## `.groups` argument.
gb_df
## # A tibble: 4 × 4
## # Groups:   chamber [2]
##   chamber party_code total_count probability
##   <chr>        <int>       <int>       <dbl>
## 1 House          100       12852      0.441 
## 2 House          200       10688      0.367 
## 3 Senate         100        2952      0.101 
## 4 Senate         200        2493      0.0856

For the above table, it shows the probability that a member is either in the House of Representatives or Senate, and if they are a Republican or Democrat. The most common combinations include the House of Representatives as they have had more members than the senate has. Out of the house and senate, there have been more democrats than republicans in each chamber.