Skip to content

Commit

Permalink
Added and abstracted spatial interaction functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dscolby committed Sep 1, 2021
1 parent cb615c4 commit bd29463
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 316 deletions.
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ S3method(summary,NetSim)
S3method(summary,PointSim)
S3method(summary,spacejamr)
export("%>%")
export(APLNetwork)
export(NetSim)
export(PointSim)
export(PowerLawNetwork)
export(as.spacejamr)
export(compare_networks)
importFrom(magrittr,"%>%")
137 changes: 137 additions & 0 deletions R/NetSim-helpers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Author: Darren Colby
# Date: 8/31/2021
# Purpose: To create spatial interaction functions for the NetSim class

# Spatial interaction functions -------------------------------------------


#' Standard power law function
#'
#' @description helper function to estimate tie probability using a standard
#' power law
#'
#' @usage standard(dist, base_prob, scale, power)
#'
#' @details This function should not be called directly
#'
#' @param dist the distance between a pair of points
#'
#' @return A numeric object representing the proability of two nodes sharing a
#' connection
#'
#' @author Darren Colby
#' Email: dscolby17@@gmail.com
#' @noRd
standard <- function(dist, base_prob, scale, power) {

prob <- (base_prob / ((1 + (scale * dist)) ^ abs(power)))

return(prob)

}



#' Attenuated power law function
#'
#' @description helper function to estimate tie probability using an attenuated
#' power law
#'
#' @usage attenuated(dist, base_prob, scale, power)
#'
#' @details This function should not be called directly
#'
#' @param dist the distance between a pair of points
#'
#' @return A numeric object representing the proability of two nodes sharing a
#' connection
#'
#' @author Darren Colby
#' Email: dscolby17@@gmail.com
#' @noRd
attenuated <- function(dist, base_prob, scale, power) {

prob <- (base_prob / (1 + (scale * dist) ^ abs(power)))


return(prob)

}


#' Arctangent probability law
#'
#' @description helper function to estimate tie probability using an arctangent
#' probability law
#'
#' @usage arctan(dist, base_prob, scale, power)
#'
#' @details This function should not be called directly
#'
#' @param dist the distance between a pair of points
#'
#' @return A numeric object representing the proability of two nodes sharing a
#' connection
#'
#' @author Darren Colby
#' Email: dscolby17@@gmail.com
#' @noRd
arctan <- function(dist, base_prob, scale, power) {

prob <- base_prob * (1 - ((2 / pi) * atan((scale * dist))))

return(prob)

}


#' Exponential decay law
#'
#' @description helper function to estimate tie probability using an exponential
#' decay law
#'
#' @usage decay(dist, base_prob, scale, power)
#'
#' @details This function should not be called directly
#'
#' @param dist the distance between a pair of points
#'
#' @return A numeric object representing the proability of two nodes sharing a
#' connection
#'
#' @author Darren Colby
#' Email: dscolby17@@gmail.com
#' @noRd
decay <- function(dist, base_prob, scale, power) {

prob <- base_prob / exp((dist * scale))

return(prob)

}


#' Logistic probability law
#'
#' @description helper function to estimate tie probability using a logistic
#' probability law
#'
#' @usage logistic(dist, base_prob, scale, power)
#'
#' @details This function should not be called directly
#'
#' @param dist the distance between a pair of points
#'
#' @return A numeric object representing the proability of two nodes sharing a
#' connection
#'
#' @author Darren Colby
#' Email: dscolby17@@gmail.com
#' @noRd
logistic <- function(dist, base_prob, scale, power) {

prob <- (2 * base_prob) / (1 + (exp(dist * scale)))

return(prob)
}

Loading

0 comments on commit bd29463

Please sign in to comment.