R - statnet - grp_month - week 1
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 first full week of articles is from 2009-12-06 to 2009-12-12.
Files:
sourcenet_data-20171206-031358-grp_month-automated-week1_subset.tab
sourcenet_data-20171206-031319-grp_month-human-week1_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_1
analysisLook at a single week from the shiny new month of data.
In [6]:
output_prefix <- "grp_week_1"
grp_week_1
(gw1) - automated - OpenCalaisFirst, we'll analyze the month of data coded by OpenCalais. Set up some variables to store where data is located:
grp_week_1
(gw1) - 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
gw1AutomatedDataFolder <- paste( data_directory, "/network/grp_month", sep = "" )
gw1AutomatedDataFile <- "sourcenet_data-20171206-031358-grp_month-automated-week1_subset.tab"
gw1AutomatedDataPath <- paste( gw1AutomatedDataFolder, "/", gw1AutomatedDataFile, sep = "" )
In [8]:
gw1AutomatedDataPath
Load the data file into memory
In [9]:
# tab-delimited:
gw1AutomatedDataDF <- read.delim( gw1AutomatedDataPath, header = TRUE, row.names = 1, check.names = FALSE )
In [10]:
# get count of rows...
gw1AutomatedRowCount <- nrow( gw1AutomatedDataDF )
paste( output_prefix, "automated row count =", gw1AutomatedRowCount, sep = " " )
# ...and columns
gw1AutomatedColumnCount <- ncol( gw1AutomatedDataDF )
paste( output_prefix, "automated column count =", gw1AutomatedColumnCount, 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.
gw1AutomatedNetworkDF <- gw1AutomatedDataDF[ , 1 : gw1AutomatedRowCount ]
#str( gw1AutomatedNetworkDF )
In [12]:
# convert to a matrix
gw1AutomatedNetworkMatrix <- as.matrix( gw1AutomatedNetworkDF )
# str( gw1AutomatedNetworkMatrix )
grp_week_1
(gw1) - automated - initialize statnetFirst, load the statnet package, then load the automated grp_month week 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
gw1AutomatedNetworkAttributeDF <- gw1AutomatedDataDF[ , 1168:1169 ]
# convert matrix to statnet network object instance.
gw1AutomatedNetworkStatnet <- network( gw1AutomatedNetworkMatrix, matrix.type = "adjacency", directed = FALSE, vertex.attr = gw1AutomatedNetworkAttributeDF )
# look at information now.
gw1AutomatedNetworkStatnet
# 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)
gw1AutomatedMeanTieWeightGE0Vector <- apply( gw1AutomatedNetworkMatrix, 1, calculateListMean )
gw1AutomatedDataDF$meanTieWeightGE0 <- gw1AutomatedMeanTieWeightGE0Vector
# calais - include ties Greater than or equal to 1 (GE1)
gw1AutomatedMeanTieWeightGE1Vector <- apply( gw1AutomatedNetworkMatrix, 1, calculateListMean, minValueToIncludeIN = 1 )
gw1AutomatedDataDF$meanTieWeightGE1 <- gw1AutomatedMeanTieWeightGE1Vector
# automated - Max tie weight?
gw1AutomatedMaxTieWeightVector <- apply( gw1AutomatedNetworkMatrix, 1, calculateListMax )
gw1AutomatedDataDF$maxTieWeight <- gw1AutomatedMaxTieWeightVector
grp_week_1
(gw1) - 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 gw1ode parameter to tell it that the
# graph is not directed (gw1ode = "graph", instead of "digraph").
# Doc: http://www.inside-r.org/packages/cran/sna/docs/degree
#degree_vector <- degree( test1_statnet, gw1ode = "graph" )
# If you have other libraries loaded that also implement a degree function, you
# can also call this with package name:
gw1AutomatedDegreeVector <- sna::degree( gw1AutomatedNetworkStatnet, gmode = "graph" )
# output the vector
gw1AutomatedDegreeVector
# 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?
gw1AutomatedAvgDegree <- mean( gw1AutomatedDegreeVector )
paste( output_prefix, "average degree =", gw1AutomatedAvgDegree, sep = " " )
# subset vector to get only those that are above mean
gw1AutomatedAboveMeanVector <- gw1AutomatedDegreeVector[ gw1AutomatedDegreeVector > gw1AutomatedAvgDegree ]
# Take the degree and associate it with each node as a node attribute.
# (%v% is a shortcut for the get.vertex.attribute command)
gw1AutomatedNetworkStatnet %v% "degree" <- gw1AutomatedDegreeVector
# also add degree vector to original data frame
gw1AutomatedDataDF$degree <- gw1AutomatedDegreeVector
In [17]:
# average author degree (person types 2 and 4)
gw1AutomatedAverageAuthorDegree2And4 <- calcAuthorMeanDegree( dataFrameIN = gw1AutomatedDataDF, includeBothIN = TRUE )
paste( output_prefix, "average author degree (2 and 4) =", gw1AutomatedAverageAuthorDegree2And4, sep = " " )
# average author degree (person type 2 only)
gw1AutomatedAverageAuthorDegreeOnly2 <- calcAuthorMeanDegree( dataFrameIN = gw1AutomatedDataDF, includeBothIN = FALSE )
paste( output_prefix, "average author degree (only 2) =", gw1AutomatedAverageAuthorDegreeOnly2, sep = " " )
# average source degree (person types 3 and 4)
gw1AutomatedAverageSourceDegree3And4 <- calcSourceMeanDegree( dataFrameIN = gw1AutomatedDataDF, includeBothIN = TRUE )
paste( output_prefix, "average source degree (3 and 4) =", gw1AutomatedAverageSourceDegree3And4, sep = " " )
# average source degree (person type 3 only)
gw1AutomatedAverageSourceDegreeOnly3 <- calcSourceMeanDegree( dataFrameIN = gw1AutomatedDataDF, includeBothIN = FALSE )
paste( output_prefix, "average source degree (only 3) =", gw1AutomatedAverageSourceDegreeOnly3, sep = " " )
grp_week_1
(gw1) - 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?
gw1AutomatedDegreeSd <- sd( gw1AutomatedDegreeVector )
paste( output_prefix, "degree SD =", gw1AutomatedDegreeSd, sep = " " )
# what is the variance of the degrees?
gw1AutomatedDegreeVar <- var( gw1AutomatedDegreeVector )
paste( output_prefix, "degree variance =", gw1AutomatedDegreeVar, sep = " " )
# what is the max value among the degrees?
gw1AutomatedDegreeMax <- max( gw1AutomatedDegreeVector )
paste( output_prefix, "degree max =", gw1AutomatedDegreeMax, sep = " " )
# calculate and plot degree distributions
gw1AutomatedDegreeFrequenciesTable <- table( gw1AutomatedDegreeVector )
paste( output_prefix, "degree frequencies =", gw1AutomatedDegreeFrequenciesTable, sep = " " )
gw1AutomatedDegreeFrequenciesTable
# node-level undirected betweenness
gw1AutomatedBetweenness <- sna::betweenness( gw1AutomatedNetworkStatnet, gmode = "graph", cmode = "undirected" )
#paste( "betweenness = ", gw1AutomatedBetweenness, sep = "" )
# associate with each node as a node attribute.
# (%v% is a shortcut for the get.vertex.attribute command)
gw1AutomatedNetworkStatnet %v% "betweenness" <- gw1AutomatedBetweenness
# also add degree vector to original data frame
gw1AutomatedDataDF$betweenness <- gw1AutomatedBetweenness
#==============================================================================#
# NETWORK level
#==============================================================================#
# graph-level degree centrality
gw1AutomatedDegreeCentrality <- sna::centralization( gw1AutomatedNetworkStatnet, sna::degree, mode = "graph" )
paste( output_prefix, "degree centrality =", gw1AutomatedDegreeCentrality, sep = " " )
# graph-level betweenness centrality
gw1AutomatedBetweennessCentrality <- sna::centralization( gw1AutomatedNetworkStatnet, sna::betweenness, mode = "graph", cmode = "undirected" )
paste( output_prefix, "betweenness centrality =", gw1AutomatedBetweennessCentrality, sep = " " )
# graph-level connectedness
gw1AutomatedConnectedness <- sna::connectedness( gw1AutomatedNetworkStatnet )
paste( output_prefix, "connectedness =", gw1AutomatedConnectedness, sep = " " )
# graph-level transitivity
gw1AutomatedTransitivity <- sna::gtrans( gw1AutomatedNetworkStatnet, mode = "graph" )
paste( output_prefix, "transitivity =", gw1AutomatedTransitivity, sep = " " )
# graph-level density
gw1AutomatedDensity <- sna::gden( gw1AutomatedNetworkStatnet, mode = "graph" )
paste( output_prefix, "density =", gw1AutomatedDensity, sep = " " )
grp_week_1
(gw1) - 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
gw1AutomatedNetworkStatnet
# then, combine them into a data frame.
gw1AutomatedNodeAttrDF <- data.frame( id = gw1AutomatedNetworkStatnet %v% "vertex.names",
person_id = gw1AutomatedNetworkStatnet %v% "person_id",
person_type = gw1AutomatedNetworkStatnet %v% "person_type",
degree = gw1AutomatedNetworkStatnet %v% "degree",
betweenness = gw1AutomatedNetworkStatnet %v% "betweenness" )
grp_week_1
(gw1) - 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_1
(gw1) - 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
gw1HumanDataFolder <- paste( data_directory, "/network/grp_month", sep = "" )
gw1HumanDataFile <- "sourcenet_data-20171206-031319-grp_month-human-week1_subset.tab"
gw1HumanDataPath <- paste( gw1HumanDataFolder, "/", gw1HumanDataFile, sep = "" )
In [21]:
gw1HumanDataPath
Load the data file into memory
In [22]:
# tab-delimited:
gw1HumanDataDF <- read.delim( gw1HumanDataPath, header = TRUE, row.names = 1, check.names = FALSE )
In [23]:
# get count of rows...
gw1HumanRowCount <- nrow( gw1HumanDataDF )
paste( output_prefix, "automated row count =", gw1HumanRowCount, sep = " " )
# ...and columns
gw1HumanColumnCount <- ncol( gw1HumanDataDF )
paste( output_prefix, "automated column count =", gw1HumanColumnCount, 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.
gw1HumanNetworkDF <- gw1HumanDataDF[ , 1 : gw1HumanRowCount ]
#str( gw1HumanNetworkDF )
In [25]:
# convert to a matrix
gw1HumanNetworkMatrix <- as.matrix( gw1HumanNetworkDF )
# str( gw1HumanNetworkMatrix )
grp_week_1
(gw1) - 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 [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
#gw1HumanNetworkAttributeDF <- gw1HumanDataDF[ , 1169:1170 ]
gw1HumanNetworkAttributeDF <- gw1HumanDataDF[ , 1168:1169 ]
# convert matrix to statnet network object instance.
gw1HumanNetworkStatnet <- network( gw1HumanNetworkMatrix, matrix.type = "adjacency", directed = FALSE, vertex.attr = gw1HumanNetworkAttributeDF )
# look at information now.
gw1HumanNetworkStatnet
# 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)
gw1HumanMeanTieWeightGE0Vector <- apply( gw1HumanNetworkMatrix, 1, calculateListMean )
gw1HumanDataDF$meanTieWeightGE0 <- gw1HumanMeanTieWeightGE0Vector
# human - include ties Greater than or equal to 1 (GE1)
gw1HumanMeanTieWeightGE1Vector <- apply( gw1HumanNetworkMatrix, 1, calculateListMean, minValueToIncludeIN = 1 )
gw1HumanDataDF$meanTieWeightGE1 <- gw1HumanMeanTieWeightGE1Vector
# human - Max tie weight?
gw1HumanMaxTieWeightVector <- apply( gw1HumanNetworkMatrix, 1, calculateListMax )
gw1HumanDataDF$maxTieWeight <- gw1HumanMaxTieWeightVector
grp_week_1
(gw1) - 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:
gw1HumanDegreeVector <- sna::degree( gw1HumanNetworkStatnet, gmode = "graph" )
# output the vector
gw1HumanDegreeVector
# 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?
gw1HumanAvgDegree <- mean( gw1HumanDegreeVector )
paste( output_prefix, "average degree =", gw1HumanAvgDegree, sep = " " )
# subset vector to get only those that are above mean
gw1HumanAboveMeanVector <- gw1HumanDegreeVector[ gw1HumanDegreeVector > gw1HumanAvgDegree ]
# Take the degree and associate it with each node as a node attribute.
# (%v% is a shortcut for the get.vertex.attribute command)
gw1HumanNetworkStatnet %v% "degree" <- gw1HumanDegreeVector
# also add degree vector to original data frame
gw1HumanDataDF$degree <- gw1HumanDegreeVector
In [30]:
# average author degree (person types 2 and 4)
gw1HumanAverageAuthorDegree2And4 <- calcAuthorMeanDegree( dataFrameIN = gw1HumanDataDF, includeBothIN = TRUE )
paste( output_prefix, "average author degree (2 and 4) = ", gw1HumanAverageAuthorDegree2And4, sep = " " )
# average author degree (person type 2 only)
gw1HumanAverageAuthorDegreeOnly2 <- calcAuthorMeanDegree( dataFrameIN = gw1HumanDataDF, includeBothIN = FALSE )
paste( output_prefix, "average author degree (only 2) = ", gw1HumanAverageAuthorDegreeOnly2, sep = " " )
# average source degree (person types 3 and 4)
gw1HumanAverageSourceDegree3And4 <- calcSourceMeanDegree( dataFrameIN = gw1HumanDataDF, includeBothIN = TRUE )
paste( output_prefix, "average source degree (3 and 4) = ", gw1HumanAverageSourceDegree3And4, sep = " " )
# average source degree (person type 3 only)
gw1HumanAverageSourceDegreeOnly3 <- calcSourceMeanDegree( dataFrameIN = gw1HumanDataDF, includeBothIN = FALSE )
paste( output_prefix, "average source degree (only 3) = ", gw1HumanAverageSourceDegreeOnly3, sep = " " )
grp_week_1
(gw1) - 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?
gw1HumanDegreeSd <- sd( gw1HumanDegreeVector )
paste( output_prefix, "degree SD =", gw1HumanDegreeSd, sep = " " )
# what is the variance of the degrees?
gw1HumanDegreeVar <- var( gw1HumanDegreeVector )
paste( output_prefix, "degree variance =", gw1HumanDegreeVar, sep = " " )
# what is the max value among the degrees?
gw1HumanDegreeMax <- max( gw1HumanDegreeVector )
paste( output_prefix, "degree max =", gw1HumanDegreeMax, sep = " " )
# calculate and plot degree distributions
gw1HumanDegreeFrequenciesTable <- table( gw1HumanDegreeVector )
paste( output_prefix, "degree frequencies =", gw1HumanDegreeFrequenciesTable, sep = " " )
gw1HumanDegreeFrequenciesTable
# node-level undirected betweenness
gw1HumanBetweenness <- sna::betweenness( gw1HumanNetworkStatnet, gmode = "graph", cmode = "undirected" )
#paste( "betweenness = ", gw1HumanBetweenness, sep = "" )
# associate with each node as a node attribute.
# (%v% is a shortcut for the get.vertex.attribute command)
gw1HumanNetworkStatnet %v% "betweenness" <- gw1HumanBetweenness
# also add degree vector to original data frame
gw1HumanDataDF$betweenness <- gw1HumanBetweenness
#==============================================================================#
# NETWORK level
#==============================================================================#
# graph-level degree centrality
gw1HumanDegreeCentrality <- sna::centralization( gw1HumanNetworkStatnet, sna::degree, mode = "graph" )
paste( output_prefix, "degree centrality =", gw1HumanDegreeCentrality, sep = " " )
# graph-level betweenness centrality
gw1HumanBetweennessCentrality <- sna::centralization( gw1HumanNetworkStatnet, sna::betweenness, mode = "graph", cmode = "undirected" )
paste( output_prefix, "betweenness centrality =", gw1HumanBetweennessCentrality, sep = " " )
# graph-level connectedness
gw1HumanConnectedness <- sna::connectedness( gw1HumanNetworkStatnet )
paste( output_prefix, "connectedness =", gw1HumanConnectedness, sep = " " )
# graph-level transitivity
gw1HumanTransitivity <- sna::gtrans( gw1HumanNetworkStatnet, mode = "graph" )
paste( output_prefix, "transitivity =", gw1HumanTransitivity, sep = " " )
# graph-level density
gw1HumanDensity <- sna::gden( gw1HumanNetworkStatnet, mode = "graph" )
paste( output_prefix, "density =", gw1HumanDensity, sep = " " )
grp_week_1
(gw1) - 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
gw1HumanNetworkStatnet
# then, combine them into a data frame.
gw1HumanNodeAttrDF <- data.frame( id = gw1HumanNetworkStatnet %v% "vertex.names",
person_id = gw1HumanNetworkStatnet %v% "person_id",
person_type = gw1HumanNetworkStatnet %v% "person_type",
degree = gw1HumanNetworkStatnet %v% "degree",
betweenness = gw1HumanNetworkStatnet %v% "betweenness" )
grp_week_1
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_1 a2b"
In [9]:
grpWeek1a2bOutput <- compareMatricesQAP( gw1HumanNetworkMatrix, gw1AutomatedNetworkMatrix, outputPrefix )
In [ ]:
# also output plots of distributions of QAP values?
displayCompareMatricesQAPOutput( grpWeek1a2bOutput, 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 )
In [ ]: