0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

issue-codeからエッジリストを抽出する

Posted at

はじめに

NOMINATEのデータって実はスコアだけじゃなくてissue-codeも付いてるんですよね。
しかもこいつ1つの法案に対して複数のissue-codeが与えられていたりするので、同じ法案に付されたissue-codeを「繋がっている」扱いにしてネットワークデータを作成してみたいと思います。
データ元:
Lewis, Jeffrey B., Keith Poole, Howard Rosenthal, Adam Boche, Aaron Rudkin, and Luke Sonnet (2020). Voteview: Congressional Roll-Call Votes Database. https://voteview.com/

データを編集

読み込み

library(tidyverse)
rollcalls <- readRDS("data/NOMINATE/rollcalls_all.rds") 
# 元データが死ぬほど重いのでrds化してあります

差し当たり上院に提出された法案について見て行きたいと思います。

# 下院を会期別にみてみる
con <- 93 #仮に93議会についてやってみます
RC_year <- rollcalls %>%
  filter(congress==con, chamber=="Senate") %>% #93議会の上院を抽出
  select(issue_codes) #issue codeを抽出

df <- list()
for(i in 1:nrow(RC_year)){
  if(length(RC_year$issue_codes[[i]]) >= 2){
    df <- c(df, list(RC_year$issue_codes[[i]]))
  }else{}
}

dataframe <- matrix(NA, length(df), 2)
colnames(dataframe) <- c("code1", "code2")
for(j in 1:length(df)){
  dataframe[j,1] <- df[[j]][1]
  dataframe[j,2] <- df[[j]][2]
}
topic.e <- as_tibble(dataframe)

なんかもっと上手いことできる気がする。
ちなみに重み付けを処理しようとすると以下のようになります。
//なんでか知らんけど重み付けの行をigraphに読ませられてないので読ませたら加筆します。
//誰か教えてくれ(投げやり

topic.e <- topic.e %>%
  group_by(code1, code2) %>%
  summarise(multi=n())

library(igraph)
g <- graph.data.frame(topic.e[1:2],directed=F)

これをプロットしてみるとこんな感じの図ができます。
Rplot_93Senate_issuecodes.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?