R/Trace_Plot.R

Defines functions Trace_Plot

Documented in Trace_Plot

#' Generate trace plot of network density from a GERGM object.
#'
#' @param GERGM_Object The object returned by the estimation procedure using the
#' GERGM function.
#' @return A trace plot of network density.
#' @export
Trace_Plot <- function(GERGM_Object){
  UMASS_BLUE <- rgb(51,51,153,255,maxColorValue = 255)
  stbcent <- NULL #edges <- NULL
  stats <- GERGM_Object@simulated_statistics_for_GOF
  # get the total number of indices
  indexes <- 1:length(stats[,1])

  iteration_number <- seq(1,GERGM_Object@number_of_simulations,
                          length.out = length(indexes))
  nr <- nrow(GERGM_Object@network)
  normalizer <- nr * (nr - 1)
  # stats <- cbind(stats/normalizer,iteration_number) # <--- this normalizes the edge weight sum

  col_index <- which(colnames(GERGM_Object@stats) == "stbcent")[1] #originally == "edges"
  # actual_density <- GERGM_Object@stats[2,col_index]/normalizer
  print(col_index)
  actual_density <- GERGM_Object@stats[2,col_index]
  p <- ggplot2::ggplot(stats, ggplot2::aes(x = iteration_number, y = stbcent))
  p  <- p + ggplot2::geom_line(color = UMASS_BLUE) +
    ggplot2::xlab("Iteration") +
    ggplot2::ylab("Stable Betweenness Statistic of Simulated Networks") +
    ggplot2::ggtitle("Trace Plot of Stable Betweenness Statistic") +
    ggplot2::geom_abline(intercept = actual_density, slope = 0) +
    ggplot2::scale_x_continuous(labels = scales::comma)
  print(p)
}
cduron1/STBTWN_GERGM documentation built on Aug. 19, 2019, 4:16 p.m.