The following objects are masked from 'package:stats':
decompose, spectrum
The following object is masked from 'package:base':
union
Code
library(network)
'network' 1.18.1 (2023-01-24), part of the Statnet Project
* 'news(package="network")' for changes since last version
* 'citation("network")' for citation information
* 'https://statnet.org' for help, support, and other information
Attaching package: 'network'
The following objects are masked from 'package:igraph':
%c%, %s%, add.edges, add.vertices, delete.edges, delete.vertices,
get.edge.attribute, get.edges, get.vertex.attribute, is.bipartite,
is.directed, list.edge.attributes, list.vertex.attributes,
set.edge.attribute, set.vertex.attribute
Rows: 200 Columns: 6
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (5): Region From, From, To, Mode, Notes
dbl (1): Miles
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Code
head(got_distances)
# A tibble: 6 × 6
`Region From` From To Miles Mode Notes
<chr> <chr> <chr> <dbl> <chr> <chr>
1 Westerlands Casterly Rock the Golden Tooth 240 land <NA>
2 Westerlands Casterly Rock Lannisport 40 land <NA>
3 Westerlands Casterly Rock Kayce 100 land <NA>
4 Westerlands Casterly Rock Kayce 12 water <NA>
5 Westerlands Casterly Rock Deep Den 240 land Goldroad
6 Westerlands Deep Den King’s Landing 590 land Goldroad
degree indegree outdegree
Min. :0.000 Min. :0.000 Min. :0.000
1st Qu.:3.000 1st Qu.:1.000 1st Qu.:1.000
Median :4.000 Median :2.000 Median :2.000
Mean :3.883 Mean :1.942 Mean :1.942
3rd Qu.:5.000 3rd Qu.:3.000 3rd Qu.:3.000
Max. :8.000 Max. :5.000 Max. :5.000
Source Code
---title: "Week3_Challenge_Niharika Pola"author: "Niharika Pola"description: "Degree and Density of a Network"date: "03/10/2023"format: html: toc: true code-fold: true code-copy: true code-tools: true# editor: visualcategories: - challenge_1 - instructions---```{r}#| label: setup#| include: false``````{r, warning=FALSE}#loading librarieslibrary(igraph)library(network)library(tidyverse)library(readr)``````{r}got_distances <-read_csv("_data/got/got_distances.csv")head(got_distances)got_distances.ig <-graph_from_data_frame(got_distances, directed =TRUE)``````{r}# number of edgesecount(got_distances.ig)# number of verticesvcount(got_distances.ig)# vertex and edge attributesvertex_attr_names(got_distances.ig)edge_attr_names(got_distances.ig)# network featuresis_directed(got_distances.ig)is_bipartite(got_distances.ig)is_weighted(got_distances.ig)# dyad censusigraph::dyad.census(got_distances.ig)# triad censustriad_census(got_distances.ig)```The vertex attribute is 'name' and edge attributes are "To", "Miles", "Mode", "Notes".```{r}# number of componentsigraph::components(got_distances.ig)$no# size of componentsigraph::components(got_distances.ig)$csize ```Compute the density of the network. Is this a global or local measure? Does it have a relationship with average degree?```{r}# network densitygraph.density(got_distances.ig)# density without loopsgraph.density(got_distances.ig, loops=TRUE)``````{r}# average network degreeigraph::degree(got_distances.ig)``````{r}ig_nodes<-data.frame(name=V(got_distances.ig)$name, degree=igraph::degree(got_distances.ig,loops=FALSE))ig_nodes<-nodes_ig %>%mutate(indegree=igraph::degree(got_distances.ig, mode="in", loops=FALSE),outdegree=igraph::degree(got_distances.ig, mode="out", loops=FALSE))head(ig_nodes)``````{r}erdos_renyi.ig <-sample_gnm(103, 200, directed =TRUE, loops =FALSE)# density of random networkgraph.density(erdos_renyi.ig)# dyad census of random networkigraph::dyad.census(erdos_renyi.ig)# triad census of random networkigraph::triad.census(erdos_renyi.ig)``````{r}rand_nodes<-data.frame(degree=igraph::degree(erdos_renyi.ig))rand_nodes<-rand_nodes %>%mutate(indegree=igraph::degree(erdos_renyi.ig, mode="in", loops=FALSE),outdegree=igraph::degree(erdos_renyi.ig, mode="out", loops=FALSE))head(rand_nodes)``````{r}summary(rand_nodes)```