R - statnet - grp_month - week 3
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 third full week of articles runs from 2009-12-20 to 2009-12-26.
Files:
sourcenet_data-20180326-040736-grp_month-automated-week3_subset.tab
sourcenet_data-20180326-034548-grp_month-human-week3_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 )
grp_week_3
analysisLook at the third full week of articles from the month of data.
In [6]:
output_prefix <- "grp_week_3"
grp_week_3
(gw3) - automated - OpenCalaisFirst, we'll analyze the month of data coded by OpenCalais. Set up some variables to store where data is located:
grp_week_3
(gw3) - automated - Read dataRead in the data from tab-delimited data file, then get it in right data structures for use in R SNA.
In [7]:
# initialize variables
gw3AutomatedDataFolder <- paste( data_directory, "/network/grp_month", sep = "" )
gw3AutomatedDataFile <- "sourcenet_data-20180326-040736-grp_month-automated-week3_subset.tab"
gw3AutomatedDataPath <- paste( gw3AutomatedDataFolder, "/", gw3AutomatedDataFile, sep = "" )
In [8]:
gw3AutomatedDataPath
Load the data file into memory
In [9]:
# tab-delimited:
gw3AutomatedDataDF <- read.delim( gw3AutomatedDataPath, header = TRUE, row.names = 1, check.names = FALSE )
In [10]:
# get count of rows...
gw3AutomatedRowCount <- nrow( gw3AutomatedDataDF )
paste( output_prefix, "automated row count =", gw3AutomatedRowCount, sep = " " )
# ...and columns
gw3AutomatedColumnCount <- ncol( gw3AutomatedDataDF )
paste( output_prefix, "automated column count =", gw3AutomatedColumnCount, sep = " " )
Get just the tie rows and columns for initializing network libraries.
In [11]:
# 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.
gw3AutomatedNetworkDF <- gw3AutomatedDataDF[ , 1 : gw3AutomatedRowCount ]
#str( gw3AutomatedNetworkDF )
In [12]:
# convert to a matrix
gw3AutomatedNetworkMatrix <- as.matrix( gw3AutomatedNetworkDF )
# str( gw3AutomatedNetworkMatrix )
grp_week_3
(gw3) - automated - initialize statnetFirst, load the statnet package, then load the automated grp_month week 3 subset data into statnet object and assign attributes to nodes.
Based on context_text/R/sna/statnet/sna-statnet-init.r
.
In [13]:
# make sure you've loaded the statnet library
# install.packages( "statnet" )
library( statnet )
In [14]:
# 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
gw3AutomatedNetworkAttributeDF <- gw3AutomatedDataDF[ , 1168:1169 ]
# convert matrix to statnet network object instance.
gw3AutomatedNetworkStatnet <- network( gw3AutomatedNetworkMatrix, matrix.type = "adjacency", directed = FALSE, vertex.attr = gw3AutomatedNetworkAttributeDF )
# look at information now.
gw3AutomatedNetworkStatnet
# 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 [15]:
# calais - include ties Greater than or equal to 0 (GE0)
gw3AutomatedMeanTieWeightGE0Vector <- apply( gw3AutomatedNetworkMatrix, 1, calculateListMean )
gw3AutomatedDataDF$meanTieWeightGE0 <- gw3AutomatedMeanTieWeightGE0Vector
# calais - include ties Greater than or equal to 1 (GE1)
gw3AutomatedMeanTieWeightGE1Vector <- apply( gw3AutomatedNetworkMatrix, 1, calculateListMean, minValueToIncludeIN = 1 )
gw3AutomatedDataDF$meanTieWeightGE1 <- gw3AutomatedMeanTieWeightGE1Vector
# automated - Max tie weight?
gw3AutomatedMaxTieWeightVector <- apply( gw3AutomatedNetworkMatrix, 1, calculateListMax )
gw3AutomatedDataDF$maxTieWeight <- gw3AutomatedMaxTieWeightVector
grp_week_3
(gw3) - automated - Basic metrics
In [16]:
# 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 gw3ode parameter to tell it that the
# graph is not directed (gw3ode = "graph", instead of "digraph").
# Doc: http://www.inside-r.org/packages/cran/sna/docs/degree
#degree_vector <- degree( test1_statnet, gw3ode = "graph" )
# If you have other libraries loaded that also implement a degree function, you
# can also call this with package name:
gw3AutomatedDegreeVector <- sna::degree( gw3AutomatedNetworkStatnet, gmode = "graph" )
# output the vector
gw3AutomatedDegreeVector
# 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?
gw3AutomatedAvgDegree <- mean( gw3AutomatedDegreeVector )
paste( output_prefix, "average degree =", gw3AutomatedAvgDegree, sep = " " )
# subset vector to get only those that are above mean
gw3AutomatedAboveMeanVector <- gw3AutomatedDegreeVector[ gw3AutomatedDegreeVector > gw3AutomatedAvgDegree ]
# Take the degree and associate it with each node as a node attribute.
# (%v% is a shortcut for the get.vertex.attribute command)
gw3AutomatedNetworkStatnet %v% "degree" <- gw3AutomatedDegreeVector
# also add degree vector to original data frame
gw3AutomatedDataDF$degree <- gw3AutomatedDegreeVector
In [17]:
# average author degree (person types 2 and 4)
gw3AutomatedAverageAuthorDegree2And4 <- calcAuthorMeanDegree( dataFrameIN = gw3AutomatedDataDF, includeBothIN = TRUE )
paste( output_prefix, "average author degree (2 and 4) =", gw3AutomatedAverageAuthorDegree2And4, sep = " " )
# average author degree (person type 2 only)
gw3AutomatedAverageAuthorDegreeOnly2 <- calcAuthorMeanDegree( dataFrameIN = gw3AutomatedDataDF, includeBothIN = FALSE )
paste( output_prefix, "average author degree (only 2) =", gw3AutomatedAverageAuthorDegreeOnly2, sep = " " )
# average source degree (person types 3 and 4)
gw3AutomatedAverageSourceDegree3And4 <- calcSourceMeanDegree( dataFrameIN = gw3AutomatedDataDF, includeBothIN = TRUE )
paste( output_prefix, "average source degree (3 and 4) =", gw3AutomatedAverageSourceDegree3And4, sep = " " )
# average source degree (person type 3 only)
gw3AutomatedAverageSourceDegreeOnly3 <- calcSourceMeanDegree( dataFrameIN = gw3AutomatedDataDF, includeBothIN = FALSE )
paste( output_prefix, "average source degree (only 3) =", gw3AutomatedAverageSourceDegreeOnly3, sep = " " )
grp_week_3
(gw3) - 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 [18]:
# 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?
gw3AutomatedDegreeSd <- sd( gw3AutomatedDegreeVector )
paste( output_prefix, "degree SD =", gw3AutomatedDegreeSd, sep = " " )
# what is the variance of the degrees?
gw3AutomatedDegreeVar <- var( gw3AutomatedDegreeVector )
paste( output_prefix, "degree variance =", gw3AutomatedDegreeVar, sep = " " )
# what is the max value among the degrees?
gw3AutomatedDegreeMax <- max( gw3AutomatedDegreeVector )
paste( output_prefix, "degree max =", gw3AutomatedDegreeMax, sep = " " )
# calculate and plot degree distributions
gw3AutomatedDegreeFrequenciesTable <- table( gw3AutomatedDegreeVector )
paste( output_prefix, "degree frequencies =", gw3AutomatedDegreeFrequenciesTable, sep = " " )
gw3AutomatedDegreeFrequenciesTable
# node-level undirected betweenness
gw3AutomatedBetweenness <- sna::betweenness( gw3AutomatedNetworkStatnet, gmode = "graph", cmode = "undirected" )
#paste( "betweenness = ", gw3AutomatedBetweenness, sep = "" )
# associate with each node as a node attribute.
# (%v% is a shortcut for the get.vertex.attribute command)
gw3AutomatedNetworkStatnet %v% "betweenness" <- gw3AutomatedBetweenness
# also add degree vector to original data frame
gw3AutomatedDataDF$betweenness <- gw3AutomatedBetweenness
#==============================================================================#
# NETWORK level
#==============================================================================#
# graph-level degree centrality
gw3AutomatedDegreeCentrality <- sna::centralization( gw3AutomatedNetworkStatnet, sna::degree, mode = "graph" )
paste( output_prefix, "degree centrality =", gw3AutomatedDegreeCentrality, sep = " " )
# graph-level betweenness centrality
gw3AutomatedBetweennessCentrality <- sna::centralization( gw3AutomatedNetworkStatnet, sna::betweenness, mode = "graph", cmode = "undirected" )
paste( output_prefix, "betweenness centrality =", gw3AutomatedBetweennessCentrality, sep = " " )
# graph-level connectedness
gw3AutomatedConnectedness <- sna::connectedness( gw3AutomatedNetworkStatnet )
paste( output_prefix, "connectedness =", gw3AutomatedConnectedness, sep = " " )
# graph-level transitivity
gw3AutomatedTransitivity <- sna::gtrans( gw3AutomatedNetworkStatnet, mode = "graph" )
paste( output_prefix, "transitivity =", gw3AutomatedTransitivity, sep = " " )
# graph-level density
gw3AutomatedDensity <- sna::gden( gw3AutomatedNetworkStatnet, mode = "graph" )
paste( output_prefix, "density =", gw3AutomatedDensity, sep = " " )
grp_week_3
(gw3) - 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 [19]:
#==============================================================================#
# 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
gw3AutomatedNetworkStatnet
# then, combine them into a data frame.
gw3AutomatedNodeAttrDF <- data.frame( id = gw3AutomatedNetworkStatnet %v% "vertex.names",
person_id = gw3AutomatedNetworkStatnet %v% "person_id",
person_type = gw3AutomatedNetworkStatnet %v% "person_type",
degree = gw3AutomatedNetworkStatnet %v% "degree",
betweenness = gw3AutomatedNetworkStatnet %v% "betweenness" )
grp_week_3
(gw3) - 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_3
(gw3) - human - Read dataRead in the data from tab-delimited data file, then get it in right data structures for use in R SNA.
In [20]:
# initialize variables
gw3HumanDataFolder <- paste( data_directory, "/network/grp_month", sep = "" )
gw3HumanDataFile <- "sourcenet_data-20180326-034548-grp_month-human-week3_subset.tab"
gw3HumanDataPath <- paste( gw3HumanDataFolder, "/", gw3HumanDataFile, sep = "" )
In [21]:
gw3HumanDataPath
Load the data file into memory
In [22]:
# tab-delimited:
gw3HumanDataDF <- read.delim( gw3HumanDataPath, header = TRUE, row.names = 1, check.names = FALSE )
In [23]:
# get count of rows...
gw3HumanRowCount <- nrow( gw3HumanDataDF )
paste( output_prefix, "automated row count =", gw3HumanRowCount, sep = " " )
# ...and columns
gw3HumanColumnCount <- ncol( gw3HumanDataDF )
paste( output_prefix, "automated column count =", gw3HumanColumnCount, sep = " " )
Get just the tie rows and columns for initializing network libraries.
In [24]:
# 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.
gw3HumanNetworkDF <- gw3HumanDataDF[ , 1 : gw3HumanRowCount ]
#str( gw3HumanNetworkDF )
In [25]:
# convert to a matrix
gw3HumanNetworkMatrix <- as.matrix( gw3HumanNetworkDF )
# str( gw3HumanNetworkMatrix )
grp_week_3
(gw3) - human - initialize statnetFirst, load the statnet package, then load the automated grp_month week 3 of data into statnet object and assign attributes to nodes.
Based on context_text/R/sna/statnet/sna-statnet-init.r
.
In [26]:
# make sure you've loaded the statnet library
# install.packages( "statnet" )
library( statnet )
In [27]:
# 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
#gw3HumanNetworkAttributeDF <- gw3HumanDataDF[ , 1169:1170 ]
gw3HumanNetworkAttributeDF <- gw3HumanDataDF[ , 1168:1169 ]
# convert matrix to statnet network object instance.
gw3HumanNetworkStatnet <- network( gw3HumanNetworkMatrix, matrix.type = "adjacency", directed = FALSE, vertex.attr = gw3HumanNetworkAttributeDF )
# look at information now.
gw3HumanNetworkStatnet
# 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 [28]:
# human - include ties Greater than or equal to 0 (GE0)
gw3HumanMeanTieWeightGE0Vector <- apply( gw3HumanNetworkMatrix, 1, calculateListMean )
gw3HumanDataDF$meanTieWeightGE0 <- gw3HumanMeanTieWeightGE0Vector
# human - include ties Greater than or equal to 1 (GE1)
gw3HumanMeanTieWeightGE1Vector <- apply( gw3HumanNetworkMatrix, 1, calculateListMean, minValueToIncludeIN = 1 )
gw3HumanDataDF$meanTieWeightGE1 <- gw3HumanMeanTieWeightGE1Vector
# human - Max tie weight?
gw3HumanMaxTieWeightVector <- apply( gw3HumanNetworkMatrix, 1, calculateListMax )
gw3HumanDataDF$maxTieWeight <- gw3HumanMaxTieWeightVector
grp_week_3
(gw3) - human - Basic metrics
In [29]:
# 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:
gw3HumanDegreeVector <- sna::degree( gw3HumanNetworkStatnet, gmode = "graph" )
# output the vector
gw3HumanDegreeVector
# 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?
gw3HumanAvgDegree <- mean( gw3HumanDegreeVector )
paste( output_prefix, "average degree =", gw3HumanAvgDegree, sep = " " )
# subset vector to get only those that are above mean
gw3HumanAboveMeanVector <- gw3HumanDegreeVector[ gw3HumanDegreeVector > gw3HumanAvgDegree ]
# Take the degree and associate it with each node as a node attribute.
# (%v% is a shortcut for the get.vertex.attribute command)
gw3HumanNetworkStatnet %v% "degree" <- gw3HumanDegreeVector
# also add degree vector to original data frame
gw3HumanDataDF$degree <- gw3HumanDegreeVector
In [30]:
# average author degree (person types 2 and 4)
gw3HumanAverageAuthorDegree2And4 <- calcAuthorMeanDegree( dataFrameIN = gw3HumanDataDF, includeBothIN = TRUE )
paste( output_prefix, "average author degree (2 and 4) = ", gw3HumanAverageAuthorDegree2And4, sep = " " )
# average author degree (person type 2 only)
gw3HumanAverageAuthorDegreeOnly2 <- calcAuthorMeanDegree( dataFrameIN = gw3HumanDataDF, includeBothIN = FALSE )
paste( output_prefix, "average author degree (only 2) = ", gw3HumanAverageAuthorDegreeOnly2, sep = " " )
# average source degree (person types 3 and 4)
gw3HumanAverageSourceDegree3And4 <- calcSourceMeanDegree( dataFrameIN = gw3HumanDataDF, includeBothIN = TRUE )
paste( output_prefix, "average source degree (3 and 4) = ", gw3HumanAverageSourceDegree3And4, sep = " " )
# average source degree (person type 3 only)
gw3HumanAverageSourceDegreeOnly3 <- calcSourceMeanDegree( dataFrameIN = gw3HumanDataDF, includeBothIN = FALSE )
paste( output_prefix, "average source degree (only 3) = ", gw3HumanAverageSourceDegreeOnly3, sep = " " )
grp_week_3
(gw3) - 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 [31]:
# 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?
gw3HumanDegreeSd <- sd( gw3HumanDegreeVector )
paste( output_prefix, "degree SD =", gw3HumanDegreeSd, sep = " " )
# what is the variance of the degrees?
gw3HumanDegreeVar <- var( gw3HumanDegreeVector )
paste( output_prefix, "degree variance =", gw3HumanDegreeVar, sep = " " )
# what is the max value among the degrees?
gw3HumanDegreeMax <- max( gw3HumanDegreeVector )
paste( output_prefix, "degree max =", gw3HumanDegreeMax, sep = " " )
# calculate and plot degree distributions
gw3HumanDegreeFrequenciesTable <- table( gw3HumanDegreeVector )
paste( output_prefix, "degree frequencies =", gw3HumanDegreeFrequenciesTable, sep = " " )
gw3HumanDegreeFrequenciesTable
# node-level undirected betweenness
gw3HumanBetweenness <- sna::betweenness( gw3HumanNetworkStatnet, gmode = "graph", cmode = "undirected" )
#paste( "betweenness = ", gw3HumanBetweenness, sep = "" )
# associate with each node as a node attribute.
# (%v% is a shortcut for the get.vertex.attribute command)
gw3HumanNetworkStatnet %v% "betweenness" <- gw3HumanBetweenness
# also add degree vector to original data frame
gw3HumanDataDF$betweenness <- gw3HumanBetweenness
#==============================================================================#
# NETWORK level
#==============================================================================#
# graph-level degree centrality
gw3HumanDegreeCentrality <- sna::centralization( gw3HumanNetworkStatnet, sna::degree, mode = "graph" )
paste( output_prefix, "degree centrality =", gw3HumanDegreeCentrality, sep = " " )
# graph-level betweenness centrality
gw3HumanBetweennessCentrality <- sna::centralization( gw3HumanNetworkStatnet, sna::betweenness, mode = "graph", cmode = "undirected" )
paste( output_prefix, "betweenness centrality =", gw3HumanBetweennessCentrality, sep = " " )
# graph-level connectedness
gw3HumanConnectedness <- sna::connectedness( gw3HumanNetworkStatnet )
paste( output_prefix, "connectedness =", gw3HumanConnectedness, sep = " " )
# graph-level transitivity
gw3HumanTransitivity <- sna::gtrans( gw3HumanNetworkStatnet, mode = "graph" )
paste( output_prefix, "transitivity =", gw3HumanTransitivity, sep = " " )
# graph-level density
gw3HumanDensity <- sna::gden( gw3HumanNetworkStatnet, mode = "graph" )
paste( output_prefix, "density =", gw3HumanDensity, sep = " " )
grp_week_3
(gw3) - 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 [32]:
#==============================================================================#
# 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
gw3HumanNetworkStatnet
# then, combine them into a data frame.
gw3HumanNodeAttrDF <- data.frame( id = gw3HumanNetworkStatnet %v% "vertex.names",
person_id = gw3HumanNetworkStatnet %v% "person_id",
person_type = gw3HumanNetworkStatnet %v% "person_type",
degree = gw3HumanNetworkStatnet %v% "degree",
betweenness = gw3HumanNetworkStatnet %v% "betweenness" )
grp_week_3
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_3 a2b"
In [9]:
grpWeek3a2bOutput <- compareMatricesQAP( gw3HumanNetworkMatrix, gw3AutomatedNetworkMatrix, outputPrefix )
In [ ]:
# also output plots of distributions of QAP values?
displayCompareMatricesQAPOutput( grpWeek3a2bOutput, 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 )