R - statnet - grp_month - week 2
2017.12.02 - work log - prelim - R - statnet - grp month
Related files:
network descriptives
network-level
files
R scripts:
context_text/R/db_connect.r
context_text/R/sna/functions-sna.r
context_text/R/sna/sna-load_data.r
context_text/R/sna/igraph/*
context_text/R/sna/statnet/*
statnet/sna
sna::gden()
- graph densityR scripts:
context_text/R/sna/statnet/sna-statnet-init.r
context_text/R/sna/statnet/sna-statnet-network-stats.r
context_text/R/sna/statnet/sna-qap.r
igraph
igraph::transitivity()
- vector of transitivity scores for each node in a graph, plus network-level transitivity score.
R scripts:
context_text/R/sna/statnet/sna-igraph-init.r
context_text/R/sna/statnet/sna-igraph-network-stats.r
Store important directories and file names in variables:
In [1]:
getwd()
In [2]:
# code files (in particular SNA function library, modest though it may be)
code_directory <- "/home/jonathanmorgan/work/django/research/context_analysis/R/sna"
sna_function_file_path <- paste( code_directory, "/", 'functions-sna.r', sep = "" )
# home directory
home_directory <- getwd()
home_directory <- "/home/jonathanmorgan/work/django/research/work/phd_work/methods"
# data directories
data_directory <- paste( home_directory, "/data", sep = "" )
workspace_file_name <- "statnet-grp_month.RData"
workspace_file_path <- paste( data_directory, "/", workspace_file_name )
In [3]:
# set working directory to data directory for now.
setwd( data_directory )
getwd()
In [4]:
source( sna_function_file_path )
source the file statnet/functions-statnet.r
.
In [5]:
# statnet/sna functions
# - /home/jonathanmorgan/work/django/research/context_analysis/R/sna/stanet/functions-statnet.r
statnetFunctionFilePath <- paste( code_directory, "/statnet/", 'functions-statnet.r', sep = "" )
In [6]:
source( statnetFunctionFilePath )
First, need render to render network data and upload it to your server.
Directions for rendering network data are in 2017.11.14-work_log-prelim-network_analysis.ipynb. You want a tab-delimited matrix that includes both the network and attributes of nodes as columns, and you want it to include a header row.
Once you render your network data files, you should place them on the server.
High level data file layout:
person_id
and person_type
)Files and their location on server:
This is data from the Grand Rapids Press articles from December of 2009, coded by both humans and OpenCalais. The second full week of articles in this time period runs from 2009-12-13 to 2009-12-19.
Files:
sourcenet_data-20180326-040445-grp_month-automated-week2_subset.tab
sourcenet_data-20180326-034401-grp_month-human-week2_subset.tab
Location in Dropbox: Dropbox/academia/MSU/program_stuff/prelim_paper/data/network_analysis/2017.11.14/network/new_coders/grp_month
Location on server: /home/jonathanmorgan/work/django/research/work/phd_work/data/network/grp_month
You must load this file's workspace, from a previous run, if one exists:
In [7]:
# assumes that you've already set working directory above to the
# working directory.
setwd( data_directory )
load( workspace_file_name )
In [6]:
output_prefix <- "grp_week_2"
grp_week_2
(gw2) - automated - OpenCalaisFirst, we'll analyze the week of data coded by OpenCalais. Set up some variables to store where data is located:
grp_week_2
(gw2) - automated - Read dataRead in the data from tab-delimited data file, then get it in right data structures for use in R SNA.
In [10]:
# initialize variables
gw2AutomatedDataFolder <- paste( data_directory, "/network/grp_month", sep = "" )
gw2AutomatedDataFile <- "sourcenet_data-20180326-040445-grp_month-automated-week2_subset.tab"
gw2AutomatedDataPath <- paste( gw2AutomatedDataFolder, "/", gw2AutomatedDataFile, sep = "" )
In [11]:
gw2AutomatedDataPath
Load the data file into memory
In [12]:
# tab-delimited:
gw2AutomatedDataDF <- read.delim( gw2AutomatedDataPath, header = TRUE, row.names = 1, check.names = FALSE )
In [13]:
# get count of rows...
gw2AutomatedRowCount <- nrow( gw2AutomatedDataDF )
paste( output_prefix, "automated row count =", gw2AutomatedRowCount, sep = " " )
# ...and columns
gw2AutomatedColumnCount <- ncol( gw2AutomatedDataDF )
paste( output_prefix, "automated column count =", gw2AutomatedColumnCount, sep = " " )
Get just the tie rows and columns for initializing network libraries.
In [14]:
# the below syntax returns only as many columns as there are rows, so
# omitting any trait columns that lie in columns on the right side
# of the file.
gw2AutomatedNetworkDF <- gw2AutomatedDataDF[ , 1 : gw2AutomatedRowCount ]
#str( gw2AutomatedNetworkDF )
In [15]:
# convert to a matrix
gw2AutomatedNetworkMatrix <- as.matrix( gw2AutomatedNetworkDF )
# str( gw2AutomatedNetworkMatrix )
grp_week_2
(gw2) - automated - initialize statnetFirst, load the statnet package, then load the automated grp_month week 2 subset data into statnet object and assign attributes to nodes.
Based on context_text/R/sna/statnet/sna-statnet-init.r
.
In [16]:
# make sure you've loaded the statnet library
# install.packages( "statnet" )
library( statnet )
In [17]:
# If you have a data frame of attributes (each attribute is a column, with
# attribute name the column name), you can associate those attributes
# when you create the network.
# attribute help: http://www.inside-r.org/packages/cran/network/docs/loading.attributes
# load attributes from a file:
#tab_attribute_test1 <- read.delim( "tab-test1-attribute_data.txt", header = TRUE, row.names = 1, check.names = FALSE )
# or create DataFrame by just grabbing the attribute columns
gw2AutomatedNetworkAttributeDF <- gw2AutomatedDataDF[ , 1168:1169 ]
# convert matrix to statnet network object instance.
gw2AutomatedNetworkStatnet <- network( gw2AutomatedNetworkMatrix, matrix.type = "adjacency", directed = FALSE, vertex.attr = gw2AutomatedNetworkAttributeDF )
# look at information now.
gw2AutomatedNetworkStatnet
# Network attributes:
# vertices = 314
# directed = FALSE
# hyper = FALSE
# loops = FALSE
# multiple = FALSE
# bipartite = FALSE
# total edges= 309
# missing edges= 0
# non-missing edges= 309
#
# Vertex attribute names:
# person_type vertex.names
#
# No edge attributes
In [18]:
# calais - include ties Greater than or equal to 0 (GE0)
gw2AutomatedMeanTieWeightGE0Vector <- apply( gw2AutomatedNetworkMatrix, 1, calculateListMean )
gw2AutomatedDataDF$meanTieWeightGE0 <- gw2AutomatedMeanTieWeightGE0Vector
# calais - include ties Greater than or equal to 1 (GE1)
gw2AutomatedMeanTieWeightGE1Vector <- apply( gw2AutomatedNetworkMatrix, 1, calculateListMean, minValueToIncludeIN = 1 )
gw2AutomatedDataDF$meanTieWeightGE1 <- gw2AutomatedMeanTieWeightGE1Vector
# automated - Max tie weight?
gw2AutomatedMaxTieWeightVector <- apply( gw2AutomatedNetworkMatrix, 1, calculateListMax )
gw2AutomatedDataDF$maxTieWeight <- gw2AutomatedMaxTieWeightVector
grp_week_2
(gw2) - automated - Basic metrics
In [19]:
# assuming that our statnet network object is in reference test1_statnet.
# Use the degree function in the sna package to create vector of degree values
# for each node. Make sure to pass the gw2ode parameter to tell it that the
# graph is not directed (gw2ode = "graph", instead of "digraph").
# Doc: http://www.inside-r.org/packages/cran/sna/docs/degree
#degree_vector <- degree( test1_statnet, gw2ode = "graph" )
# If you have other libraries loaded that also implement a degree function, you
# can also call this with package name:
gw2AutomatedDegreeVector <- sna::degree( gw2AutomatedNetworkStatnet, gmode = "graph" )
# output the vector
gw2AutomatedDegreeVector
# want more info on the degree function? You can get to it eventually through
# the following:
#help( package = "sna" )
#??sna::degree
# what is the average (mean) degree?
gw2AutomatedAvgDegree <- mean( gw2AutomatedDegreeVector )
paste( output_prefix, "average degree =", gw2AutomatedAvgDegree, sep = " " )
# subset vector to get only those that are above mean
gw2AutomatedAboveMeanVector <- gw2AutomatedDegreeVector[ gw2AutomatedDegreeVector > gw2AutomatedAvgDegree ]
# Take the degree and associate it with each node as a node attribute.
# (%v% is a shortcut for the get.vertex.attribute command)
gw2AutomatedNetworkStatnet %v% "degree" <- gw2AutomatedDegreeVector
# also add degree vector to original data frame
gw2AutomatedDataDF$degree <- gw2AutomatedDegreeVector
In [20]:
# average author degree (person types 2 and 4)
gw2AutomatedAverageAuthorDegree2And4 <- calcAuthorMeanDegree( dataFrameIN = gw2AutomatedDataDF, includeBothIN = TRUE )
paste( output_prefix, "average author degree (2 and 4) =", gw2AutomatedAverageAuthorDegree2And4, sep = " " )
# average author degree (person type 2 only)
gw2AutomatedAverageAuthorDegreeOnly2 <- calcAuthorMeanDegree( dataFrameIN = gw2AutomatedDataDF, includeBothIN = FALSE )
paste( output_prefix, "average author degree (only 2) =", gw2AutomatedAverageAuthorDegreeOnly2, sep = " " )
# average source degree (person types 3 and 4)
gw2AutomatedAverageSourceDegree3And4 <- calcSourceMeanDegree( dataFrameIN = gw2AutomatedDataDF, includeBothIN = TRUE )
paste( output_prefix, "average source degree (3 and 4) =", gw2AutomatedAverageSourceDegree3And4, sep = " " )
# average source degree (person type 3 only)
gw2AutomatedAverageSourceDegreeOnly3 <- calcSourceMeanDegree( dataFrameIN = gw2AutomatedDataDF, includeBothIN = FALSE )
paste( output_prefix, "average source degree (only 3) =", gw2AutomatedAverageSourceDegreeOnly3, sep = " " )
grp_week_2
(gw2) - automated - More metricsNow that we have the data in statnet object, run the code in the following for more in-depth information:
context_text/R/sna/statnet/sna-statnet-network-stats.r
In [21]:
# Links:
# - manual (PDF): http://cran.r-project.org/web/packages/sna/sna.pdf
# - good notes: http://www.shizukalab.com/toolkits/sna/node-level-calculations
# Also, be advised that statnet and igraph don't really play nice together.
# If you'll be using both, best idea is to have a workspace for each.
#==============================================================================#
# statnet
#==============================================================================#
# make sure you've loaded the statnet library (includes sna)
# install.packages( "statnet" )
#library( statnet )
#==============================================================================#
# NODE level
#==============================================================================#
# what is the standard deviation of the degrees?
gw2AutomatedDegreeSd <- sd( gw2AutomatedDegreeVector )
paste( output_prefix, "degree SD =", gw2AutomatedDegreeSd, sep = " " )
# what is the variance of the degrees?
gw2AutomatedDegreeVar <- var( gw2AutomatedDegreeVector )
paste( output_prefix, "degree variance =", gw2AutomatedDegreeVar, sep = " " )
# what is the max value among the degrees?
gw2AutomatedDegreeMax <- max( gw2AutomatedDegreeVector )
paste( output_prefix, "degree max =", gw2AutomatedDegreeMax, sep = " " )
# calculate and plot degree distributions
gw2AutomatedDegreeFrequenciesTable <- table( gw2AutomatedDegreeVector )
paste( output_prefix, "degree frequencies =", gw2AutomatedDegreeFrequenciesTable, sep = " " )
gw2AutomatedDegreeFrequenciesTable
# node-level undirected betweenness
gw2AutomatedBetweenness <- sna::betweenness( gw2AutomatedNetworkStatnet, gmode = "graph", cmode = "undirected" )
#paste( "betweenness = ", gw2AutomatedBetweenness, sep = "" )
# associate with each node as a node attribute.
# (%v% is a shortcut for the get.vertex.attribute command)
gw2AutomatedNetworkStatnet %v% "betweenness" <- gw2AutomatedBetweenness
# also add degree vector to original data frame
gw2AutomatedDataDF$betweenness <- gw2AutomatedBetweenness
#==============================================================================#
# NETWORK level
#==============================================================================#
# graph-level degree centrality
gw2AutomatedDegreeCentrality <- sna::centralization( gw2AutomatedNetworkStatnet, sna::degree, mode = "graph" )
paste( output_prefix, "degree centrality =", gw2AutomatedDegreeCentrality, sep = " " )
# graph-level betweenness centrality
gw2AutomatedBetweennessCentrality <- sna::centralization( gw2AutomatedNetworkStatnet, sna::betweenness, mode = "graph", cmode = "undirected" )
paste( output_prefix, "betweenness centrality =", gw2AutomatedBetweennessCentrality, sep = " " )
# graph-level connectedness
gw2AutomatedConnectedness <- sna::connectedness( gw2AutomatedNetworkStatnet )
paste( output_prefix, "connectedness =", gw2AutomatedConnectedness, sep = " " )
# graph-level transitivity
gw2AutomatedTransitivity <- sna::gtrans( gw2AutomatedNetworkStatnet, mode = "graph" )
paste( output_prefix, "transitivity =", gw2AutomatedTransitivity, sep = " " )
# graph-level density
gw2AutomatedDensity <- sna::gden( gw2AutomatedNetworkStatnet, mode = "graph" )
paste( output_prefix, "density =", gw2AutomatedDensity, sep = " " )
grp_week_2
(gw2) - automated - create node attribute DataFrameIf you want to just work with the traits of the nodes/vertexes, you can combine the attribute vectors into a data frame.
In [22]:
#==============================================================================#
# output attributes to data frame
#==============================================================================#
# if you want to just work with the traits of the nodes/vertexes, you can
# combine the attribute vectors into a data frame.
# first, output network object to see what attributes you have
gw2AutomatedNetworkStatnet
# then, combine them into a data frame.
gw2AutomatedNodeAttrDF <- data.frame( id = gw2AutomatedNetworkStatnet %v% "vertex.names",
person_id = gw2AutomatedNetworkStatnet %v% "person_id",
person_type = gw2AutomatedNetworkStatnet %v% "person_type",
degree = gw2AutomatedNetworkStatnet %v% "degree",
betweenness = gw2AutomatedNetworkStatnet %v% "betweenness" )
grp_week_2
(gw2) - humanNext, we'll analyze the same week from the month of data coded by human coders. Set up some variables to store where data is located:
grp_week_2
(gw2) - human - Read dataRead in the data from tab-delimited data file, then get it in right data structures for use in R SNA.
In [23]:
# initialize variables
gw2HumanDataFolder <- paste( data_directory, "/network/grp_month", sep = "" )
gw2HumanDataFile <- "sourcenet_data-20180326-034401-grp_month-human-week2_subset.tab"
gw2HumanDataPath <- paste( gw2HumanDataFolder, "/", gw2HumanDataFile, sep = "" )
In [24]:
gw2HumanDataPath
Load the data file into memory
In [25]:
# tab-delimited:
gw2HumanDataDF <- read.delim( gw2HumanDataPath, header = TRUE, row.names = 1, check.names = FALSE )
In [26]:
# get count of rows...
gw2HumanRowCount <- nrow( gw2HumanDataDF )
paste( output_prefix, "automated row count =", gw2HumanRowCount, sep = " " )
# ...and columns
gw2HumanColumnCount <- ncol( gw2HumanDataDF )
paste( output_prefix, "automated column count =", gw2HumanColumnCount, sep = " " )
Get just the tie rows and columns for initializing network libraries.
In [27]:
# the below syntax returns only as many columns as there are rows, so
# omitting any trait columns that lie in columns on the right side
# of the file.
gw2HumanNetworkDF <- gw2HumanDataDF[ , 1 : gw2HumanRowCount ]
#str( gw2HumanNetworkDF )
In [28]:
# convert to a matrix
gw2HumanNetworkMatrix <- as.matrix( gw2HumanNetworkDF )
# str( gw2HumanNetworkMatrix )
grp_week_2
(gw2) - human - initialize statnetFirst, load the statnet package, then load the automated grp_month week of data into statnet object and assign attributes to nodes.
Based on context_text/R/sna/statnet/sna-statnet-init.r
.
In [29]:
# make sure you've loaded the statnet library
# install.packages( "statnet" )
library( statnet )
In [30]:
# If you have a data frame of attributes (each attribute is a column, with
# attribute name the column name), you can associate those attributes
# when you create the network.
# attribute help: http://www.inside-r.org/packages/cran/network/docs/loading.attributes
# load attributes from a file:
#tab_attribute_test1 <- read.delim( "tab-test1-attribute_data.txt", header = TRUE, row.names = 1, check.names = FALSE )
# or create DataFrame by just grabbing the attribute columns
#gw2HumanNetworkAttributeDF <- gw2HumanDataDF[ , 1169:1170 ]
gw2HumanNetworkAttributeDF <- gw2HumanDataDF[ , 1168:1169 ]
# convert matrix to statnet network object instance.
gw2HumanNetworkStatnet <- network( gw2HumanNetworkMatrix, matrix.type = "adjacency", directed = FALSE, vertex.attr = gw2HumanNetworkAttributeDF )
# look at information now.
gw2HumanNetworkStatnet
# Network attributes:
# vertices = 314
# directed = FALSE
# hyper = FALSE
# loops = FALSE
# multiple = FALSE
# bipartite = FALSE
# total edges= 309
# missing edges= 0
# non-missing edges= 309
#
# Vertex attribute names:
# person_type vertex.names
#
# No edge attributes
In [31]:
# human - include ties Greater than or equal to 0 (GE0)
gw2HumanMeanTieWeightGE0Vector <- apply( gw2HumanNetworkMatrix, 1, calculateListMean )
gw2HumanDataDF$meanTieWeightGE0 <- gw2HumanMeanTieWeightGE0Vector
# human - include ties Greater than or equal to 1 (GE1)
gw2HumanMeanTieWeightGE1Vector <- apply( gw2HumanNetworkMatrix, 1, calculateListMean, minValueToIncludeIN = 1 )
gw2HumanDataDF$meanTieWeightGE1 <- gw2HumanMeanTieWeightGE1Vector
# human - Max tie weight?
gw2HumanMaxTieWeightVector <- apply( gw2HumanNetworkMatrix, 1, calculateListMax )
gw2HumanDataDF$maxTieWeight <- gw2HumanMaxTieWeightVector
grp_week_2
(gw2) - human - Basic metrics
In [32]:
# assuming that our statnet network object is in reference test1_statnet.
# Use the degree function in the sna package to create vector of degree values
# for each node. Make sure to pass the gmode parameter to tell it that the
# graph is not directed (gmode = "graph", instead of "digraph").
# Doc: http://www.inside-r.org/packages/cran/sna/docs/degree
#degree_vector <- degree( test1_statnet, gmode = "graph" )
# If you have other libraries loaded that also implement a degree function, you
# can also call this with package name:
gw2HumanDegreeVector <- sna::degree( gw2HumanNetworkStatnet, gmode = "graph" )
# output the vector
gw2HumanDegreeVector
# want more info on the degree function? You can get to it eventually through
# the following:
#help( package = "sna" )
#??sna::degree
# what is the average (mean) degree?
gw2HumanAvgDegree <- mean( gw2HumanDegreeVector )
paste( output_prefix, "average degree =", gw2HumanAvgDegree, sep = " " )
# subset vector to get only those that are above mean
gw2HumanAboveMeanVector <- gw2HumanDegreeVector[ gw2HumanDegreeVector > gw2HumanAvgDegree ]
# Take the degree and associate it with each node as a node attribute.
# (%v% is a shortcut for the get.vertex.attribute command)
gw2HumanNetworkStatnet %v% "degree" <- gw2HumanDegreeVector
# also add degree vector to original data frame
gw2HumanDataDF$degree <- gw2HumanDegreeVector
In [33]:
# average author degree (person types 2 and 4)
gw2HumanAverageAuthorDegree2And4 <- calcAuthorMeanDegree( dataFrameIN = gw2HumanDataDF, includeBothIN = TRUE )
paste( output_prefix, "average author degree (2 and 4) = ", gw2HumanAverageAuthorDegree2And4, sep = " " )
# average author degree (person type 2 only)
gw2HumanAverageAuthorDegreeOnly2 <- calcAuthorMeanDegree( dataFrameIN = gw2HumanDataDF, includeBothIN = FALSE )
paste( output_prefix, "average author degree (only 2) = ", gw2HumanAverageAuthorDegreeOnly2, sep = " " )
# average source degree (person types 3 and 4)
gw2HumanAverageSourceDegree3And4 <- calcSourceMeanDegree( dataFrameIN = gw2HumanDataDF, includeBothIN = TRUE )
paste( output_prefix, "average source degree (3 and 4) = ", gw2HumanAverageSourceDegree3And4, sep = " " )
# average source degree (person type 3 only)
gw2HumanAverageSourceDegreeOnly3 <- calcSourceMeanDegree( dataFrameIN = gw2HumanDataDF, includeBothIN = FALSE )
paste( output_prefix, "average source degree (only 3) = ", gw2HumanAverageSourceDegreeOnly3, sep = " " )
grp_week_2
(gw2) - human - More metricsNow that we have the data in statnet object, run the code in the following for more in-depth information:
context_text/R/sna/statnet/sna-statnet-network-stats.r
In [34]:
# Links:
# - manual (PDF): http://cran.r-project.org/web/packages/sna/sna.pdf
# - good notes: http://www.shizukalab.com/toolkits/sna/node-level-calculations
# Also, be advised that statnet and igraph don't really play nice together.
# If you'll be using both, best idea is to have a workspace for each.
#==============================================================================#
# statnet
#==============================================================================#
# make sure you've loaded the statnet library (includes sna)
# install.packages( "statnet" )
#library( statnet )
#==============================================================================#
# NODE level
#==============================================================================#
# what is the standard deviation of the degrees?
gw2HumanDegreeSd <- sd( gw2HumanDegreeVector )
paste( output_prefix, "degree SD =", gw2HumanDegreeSd, sep = " " )
# what is the variance of the degrees?
gw2HumanDegreeVar <- var( gw2HumanDegreeVector )
paste( output_prefix, "degree variance =", gw2HumanDegreeVar, sep = " " )
# what is the max value among the degrees?
gw2HumanDegreeMax <- max( gw2HumanDegreeVector )
paste( output_prefix, "degree max =", gw2HumanDegreeMax, sep = " " )
# calculate and plot degree distributions
gw2HumanDegreeFrequenciesTable <- table( gw2HumanDegreeVector )
paste( output_prefix, "degree frequencies =", gw2HumanDegreeFrequenciesTable, sep = " " )
gw2HumanDegreeFrequenciesTable
# node-level undirected betweenness
gw2HumanBetweenness <- sna::betweenness( gw2HumanNetworkStatnet, gmode = "graph", cmode = "undirected" )
#paste( "betweenness = ", gw2HumanBetweenness, sep = "" )
# associate with each node as a node attribute.
# (%v% is a shortcut for the get.vertex.attribute command)
gw2HumanNetworkStatnet %v% "betweenness" <- gw2HumanBetweenness
# also add degree vector to original data frame
gw2HumanDataDF$betweenness <- gw2HumanBetweenness
#==============================================================================#
# NETWORK level
#==============================================================================#
# graph-level degree centrality
gw2HumanDegreeCentrality <- sna::centralization( gw2HumanNetworkStatnet, sna::degree, mode = "graph" )
paste( output_prefix, "degree centrality =", gw2HumanDegreeCentrality, sep = " " )
# graph-level betweenness centrality
gw2HumanBetweennessCentrality <- sna::centralization( gw2HumanNetworkStatnet, sna::betweenness, mode = "graph", cmode = "undirected" )
paste( output_prefix, "betweenness centrality =", gw2HumanBetweennessCentrality, sep = " " )
# graph-level connectedness
gw2HumanConnectedness <- sna::connectedness( gw2HumanNetworkStatnet )
paste( output_prefix, "connectedness =", gw2HumanConnectedness, sep = " " )
# graph-level transitivity
gw2HumanTransitivity <- sna::gtrans( gw2HumanNetworkStatnet, mode = "graph" )
paste( output_prefix, "transitivity =", gw2HumanTransitivity, sep = " " )
# graph-level density
gw2HumanDensity <- sna::gden( gw2HumanNetworkStatnet, mode = "graph" )
paste( output_prefix, "density =", gw2HumanDensity, sep = " " )
grp_week_2
(gw2) - human - create node attribute DataFrameIf you want to just work with the traits of the nodes/vertexes, you can combine the attribute vectors into a data frame.
In [35]:
#==============================================================================#
# output attributes to data frame
#==============================================================================#
# if you want to just work with the traits of the nodes/vertexes, you can
# combine the attribute vectors into a data frame.
# first, output network object to see what attributes you have
gw2HumanNetworkStatnet
# then, combine them into a data frame.
gw2HumanNodeAttrDF <- data.frame( id = gw2HumanNetworkStatnet %v% "vertex.names",
person_id = gw2HumanNetworkStatnet %v% "person_id",
person_type = gw2HumanNetworkStatnet %v% "person_type",
degree = gw2HumanNetworkStatnet %v% "degree",
betweenness = gw2HumanNetworkStatnet %v% "betweenness" )
grp_week_2
QAP graph correlation between automated and ground truthNow, compare the automated and human-coded networks themselves using graph correlation in QAP.
Based on: context_text/R/sna/statnet/sna-qap.r
In [8]:
outputPrefix <- "grp_week_2 a2b"
In [9]:
grpWeek2a2bOutput <- compareMatricesQAP( gw2HumanNetworkMatrix, gw2AutomatedNetworkMatrix, outputPrefix )
In [ ]:
# also output plots of distributions of QAP values?
displayCompareMatricesQAPOutput( grpWeek2a2bOutput, outputPrefix, TRUE )
Save all the information in the current image, in case we need/want it later.
In [10]:
# help( save.image )
message( paste( "Output workspace to: ", workspace_file_name, sep = "" ) )
save.image( file = workspace_file_name )