knitr::opts_chunk$set(echo = TRUE)
The purpose of this vignette is to check the Nyakatoke village data provided in (source) and compare descriptive statistics with what is stated in published works.
This part of the code is simply loads the raw data in the extdata folder and saves it as an R data set
baseLoc <- system.file(package="riskSharing") extPath <- file.path(baseLoc, "extdata")
nyakatoke <- read.csv(file.path(extPath, file.path("tanzania_data.csv"))) save(nyakatoke, file = "../data/nyakatoke.RData", compress = "xz")
We load the igraph package and reload the data
library(riskSharing) data("nyakatoke")
Let's create an undirected graph from the data. In this case, we say two households share a link if either household reported the other.
library(igraph) g <- graph_from_data_frame(nyakatoke[nyakatoke$willingness_link1 == 1 | nyakatoke$willingness_link2,], directed = FALSE) g <- simplify(g)
library(xtable) g.order <- length(igraph::V(g)) g.size <- length(igraph::E(g)) g.mean.degree <- mean(degree(g)) g.min.degree <- min(degree(g)) g.max.degree <- max(degree(g)) g.med.degree <- median(degree(g)) g.distances <- distance_table(g)$res names(g.distances) <- 1:length(g.distances) summary.stats <- data.frame(g.mean.degree, g.med.degree, g.min.degree, g.max.degree) xt <- xtable(summary.stats, auto = TRUE, digits = 2) names(xt) <- c("Mean", "Median", "Min", "Max") print(xt, type = "html")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.