## Social network analysis

In this challenge, you will analyze the Twitter network of the Members of the U.S. Congress.

In the `data` folder, you will find two data files:

- `congress-twitter-network-edges.csv` contains the edges of this network. Note that these nodes are directed: they indicate whether the legislator in the `source` column follows the legislator in the `target` column.

- `congress-twitter-network-nodes.csv` contains information about each of the nodes. The only important variables we will use here are: `id_str` (the unique Twitter ID for each legislator; same as in the edge list), `name` (full name of each legislator), `party` (Republican, Democrat or Independent), and `chamber` (`rep` for the House of Representatives, `sen` for the Senate).

The first step will be to read these two datasets into R and construct the igraph object. How many nodes and edges does this network have?

```{r}

```

This network is too large for us to visualize it directly with R, so let's try to learn more about it using what we have learned so far.

Who are the most relevant Members of Congress, according to different measures of centrality? Note that this is a directed network, which means there is a difference between indegree and outdegree.

```{r}

```

Estimate the density of this network, and the levels of reciprocity and transitivity. Interpret the results.

```{r}

```

Split the network into two components, defined by party. Compute reciprocity and transitivity in each of the two components. What do you find?

```{r}

```


What communities can you find in the network? Use the additional node-level variables to try to identify whether these communities overlap with any of these other attributes.

```{r}

```

Finally, we'll try to visualize part of the network as well: only the Senators. Note also that instead of plotting it in the Viewer window, we'll write directly to a PDF file. I have added some code here for you so that it's faster, but note that this may take 1-2 minutes.

```{r, eval=FALSE}
sen <- induced_subgraph(g, V(g)$chamber=="sen")

set.seed(123)
fr <- layout_with_fr(sen, niter=1000)
V(sen)$color <- ifelse(V(sen)$party=="Republican", "red", "blue") # clue
V(sen)$label <- NA
V(sen)$size <- authority_score(sen)$vector * 5

pdf("congress-network.pdf")
par(mar=c(0,0,0,0))
plot(sen, edge.curved=.25, edge.width=.05, edge.arrow.mode=0)
dev.off()
```




