Skip to content

Commit

Permalink
version 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Per Block authored and cran-robot committed Feb 6, 2024
1 parent cb56842 commit ef3be9d
Show file tree
Hide file tree
Showing 39 changed files with 1,919 additions and 207 deletions.
14 changes: 8 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Package: MoNAn
Type: Package
Title: Mobility Network Analysis
Version: 0.1.2
Date: 2023-08-15
Version: 0.1.3
Date: 2024-02-04
Authors@R: c(person("Per", "Block", role = c("cre", "aut", "cph"), email = "block@soziologie.uzh.ch",
comment = c(ORCID = "0000-0002-7583-2392")),
person("Christoph", "Stadtfeld", role = "aut", comment = c(ORCID = "0000-0002-2704-2134")),
person("Nico", "Keiser", role = "aut"))
person("Nico", "Keiser", role = "aut"),
person("Marion", "Hoffman", role = "aut"))
Description: Implements the method to analyse weighted mobility networks or distribution networks as outlined in:
Block, P., Stadtfeld, C., & Robins, G. (2022) <doi:10.1016/j.socnet.2021.08.003>.
The purpose of the model is to analyse the structure of mobility,
Expand All @@ -21,10 +22,11 @@ Imports: snowfall (>= 1.84-6.2), methods
RoxygenNote: 7.2.3
Suggests: knitr, rmarkdown
NeedsCompilation: no
Packaged: 2023-08-29 13:50:32 UTC; per
Packaged: 2024-02-05 12:19:42 UTC; per
Author: Per Block [cre, aut, cph] (<https://orcid.org/0000-0002-7583-2392>),
Christoph Stadtfeld [aut] (<https://orcid.org/0000-0002-2704-2134>),
Nico Keiser [aut]
Nico Keiser [aut],
Marion Hoffman [aut]
Maintainer: Per Block <block@soziologie.uzh.ch>
Repository: CRAN
Date/Publication: 2023-08-29 17:00:08 UTC
Date/Publication: 2024-02-05 12:40:12 UTC
58 changes: 38 additions & 20 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
fc078fa4019abf074f3f5d77a1918e44 *DESCRIPTION
e0f77c1cd8d2c6306d0677ff89feadf5 *NAMESPACE
a21acc25ca4e47f9fc820f067b149768 *R/1_hiddenFunctions.R
7a0ed1249bf2f93013de03eadc84d993 *R/2_effectFunctions.R
896856b7e6c7053c5fe48bb2de816a81 *DESCRIPTION
0e69fc2c485b85fcd508877e1b940cec *NAMESPACE
b950660784725f27005ec74d3e56e2ac *NEWS.md
68e8f76910e9b70cd6026c20dda15244 *R/1_hiddenFunctions.R
5ab2511df4b86a54287715c40e8e7727 *R/2_effectFunctions.R
a2e222be5db7297c706e674938bcca89 *R/2a_effectFunctions_exogenous.R
84bbcacfa2e0eaab6bc71fde5f282951 *R/2b_effectFunctions_loops.R
fc5efafac87b9f1e93ba64d65a945938 *R/2c_effectFunctions_concentration.R
afa6bdaee40ce855b7c81e571ad65521 *R/2d_effectFunctions_reciprocity.R
c518774df6cb70018cd8333464ce7af6 *R/2e_effectFunctions_transitivity.R
1028dfdaf16404caa12e65883543eb00 *R/3_coreFunctions.R
04bf437debe88e63c5dd9606e768d263 *R/2b_effectFunctions_loops.R
350c0536d963b1b30dd55c936867c2c2 *R/2c_effectFunctions_concentration.R
abf1640e2f7f20cabb87a7a03dc6ad3b *R/2d_effectFunctions_reciprocity.R
7658e04ecb52a355ef522c65ef1a04dc *R/2e_effectFunctions_transitivity.R
d01d45efebe6b5b573880d248f04b805 *R/2x_effects_test.R
da76cafa4371887f6f7d9dff38394e80 *R/3_coreFunctions.R
42ce187a6b6027774b4f180c6b77ee1a *R/4_auxiliaryFunctions.R
318289e507330a4bacd3f5dc5123d7e7 *R/5_gofParamFunctions.R
df6cc46bc7fae1a55b713f3d5065b35a *R/MoNAn-package.R
0c76cf98c9d13a9e6a469d70cd7f0010 *R/mobilityData.R
b4f2bcdbfc04b12a3bac3cd07a4847de *R/mobilityData.R
91c8dfa9876f8f4247561ecb872911cd *R/myOutcomeObjects.R
61ccbe3e6eab83b74cda42289218dc26 *README.md
fc6e4e4b7be3187a56b64c5e09d31587 *R/sysdata.rda
1f8ed71a4a25d55a9c0a19d817b50732 *README.md
7080893e02c49cd296d4424b9be55069 *build/partial.rdb
74e2806b571377c74369affeb0b4b149 *data/indSex.rda
f379efcd7e512d40b027ccaadc5b1983 *data/mobilityEdgelist.rda
Expand All @@ -25,13 +28,16 @@ fc30b8ed48dcd66634d78479e8adf970 *data/myEffects.rda
2bfc06a2c2bc24f3dfb19464115499c1 *data/myState.rda
cc4c941ce67f5462b75b56e576622dfe *data/orgRegion.rda
9998a893c2dbbf2b20d493d5d3e7a74a *data/orgSize.rda
f5ba16545263b150575c5b060c3dc9ec *man/MoNAn-package.Rd
24dbc7408aa89a472de89181b3fb62fa *man/MoNAn-package.Rd
948a67ef03577108a0548250fe02e4f5 *man/alter_covariate.Rd
17681a2df2c541a87b63a2bc9f60af4b *man/autoCorrelationTest.Rd
7105fdd78873eec2cb4d877b3f565938 *man/concentration_GW.Rd
64026dae76b04962a7b65aa3989aae07 *man/concentration_GW_dyad_covar_bin.Rd
bdc34929ad931b9824f6409765576d96 *man/concentration_GW.Rd
04651f93aad6ee892c6d9a413f4fe5c2 *man/concentration_GW_dyad_covar.Rd
c5238d0d84ce7ae8757fa9b6bff671ec *man/concentration_basic.Rd
e9f9810d2cdc1a9cb407e4aa8a028ae9 *man/createAlgorithm.Rd
ec854ae92d1ebfa885e31f1c3e56bb13 *man/concentration_prop.Rd
3c88a3fe15a9669030c77fa3ae60dde7 *man/concentration_prop_orig_cov.Rd
7790bcc6c3a8c16c1597738d3a1c40b1 *man/concentration_rankGW.Rd
00932f6d22b4793ad4e00f1cda0326ed *man/createAlgorithm.Rd
47c8c502b16c67ce5fed6b75f01a470f *man/createEdgelist.Rd
8eba45cedeffecc4eac432efd8d968e9 *man/createEffectsObject.Rd
0275629e8b72cd30c34c6c09c91879ce *man/createNetwork.Rd
Expand All @@ -42,7 +48,7 @@ a18cf408cb2aa724aa523f7695915a08 *man/createNodeVariable.Rd
51b10fc6e703fb35fafd5ad43696931b *man/crowding_out_prop_covar_bin.Rd
bcafba8d085f97364cfd46c81aee7e06 *man/dyadic_covariate.Rd
c7e5d98fbac6b1198e0b094c26c9729b *man/dyadic_covariate_resource_attribute.Rd
9f7e76362fbaec48605a543a76ac06d7 *man/estimateMobilityNetwork.Rd
fbe597727af8c8de158854e3aac0536f *man/estimateMobilityNetwork.Rd
5f3dbb5e6c2f200c1dc005ab421b9cc7 *man/extractTraces.Rd
0e3a0c5de1e1b9736e04f659dde1feda *man/figures/README-unnamed-chunk-15-1.png
354b1982c7e6a0d53948930b339a52c1 *man/figures/README-unnamed-chunk-15-2.png
Expand All @@ -67,25 +73,37 @@ af5800f5e3cc905d65ebf777a707f59f *man/figures/README-unnamed-chunk-18-3.png
d4ce37c9f4b8e5ae5754ad7b93d1be74 *man/getTieWeights.Rd
8bdee67010eb4fc559ed2c55ccb22507 *man/gofMobilityNetwork.Rd
d9f6d5e83092d8bfedbc62de1eab7195 *man/in_ties_loops.Rd
96b99fd039be44e1a163c1b4c9e3773e *man/in_weights_GW.Rd
eae7a0ef9e2683ee4dc8408ee74e3878 *man/in_weights_exponent.Rd
3ba8523207b373ced583c7284986e8dc *man/loops.Rd
35e5b2feca34845664f39e8676558271 *man/loops_GW.Rd
51fc2912c75d5a1f0781e7e3a875af90 *man/loops_additional_origin.Rd
6570e832b484404826d4a08797d807c5 *man/loops_node_covar.Rd
64f1d507404fc4819fb6dae20e073f4a *man/loops_resource_covar.Rd
79af17244b3b1935708d5fae1e0f071d *man/loops_resource_covar_node_covar.Rd
05a1b254285d1fddcaa6c46c3d05c602 *man/mobilityData.Rd
c2faf6ee2b138131bada61ffea8803d4 *man/loops_x_loops_additional_origin.Rd
5fa07cd7c9404980524652fce343db09 *man/mobilityData.Rd
6c9fb9d8b48e04f3e15844bd94e224f2 *man/myOutcomeObjects.Rd
673bf084277e6655b7251e340aab089e *man/present_relations.Rd
badabd77cf7bfbb058cb8bbfa2becb8d *man/reciprocity_GW.Rd
859a0148163717d6a2f0468d9ce0290b *man/reciprocity_GW_dyad_covar_bin.Rd
5320a60bd9667efccc900b7085d6241e *man/reciprocity_GW.Rd
2d4793ae09c09261779ad4cb3874b7f2 *man/reciprocity_GW_dyad_covar.Rd
af9b3703978315b0681398455cf93935 *man/reciprocity_GW_dyad_covar_bin.Rd
d80c09233e44e50782145d19ff4bedec *man/reciprocity_basic.Rd
bf6fb147777801c31f03d6750c1a05ab *man/reciprocity_min.Rd
c2fb499b2fe8269fbe8a17cb77f029d0 *man/reciprocity_min_dyad_covar.Rd
9d36a4752db8d79f468d760a6094d306 *man/reciprocity_min_resource_covar.Rd
82aa8005716e5243047201be37872e5f *man/resource_covar_to_node_covar.Rd
18a29720c9c0c4c9cc1fed6483f06287 *man/same_covariate.Rd
f44c9d205621de2be0e28c13f7f78099 *man/scoreTest.Rd
2c94679f25fd339dabb377e032465bf8 *man/sim_covariate.Rd
d5d0c3633f840bd15d9e4f4c8b483402 *man/simulateMobilityNetworks.Rd
0522da2f247c2b135be3ed7c8a27c8b3 *man/simulateMobilityNetworks.Rd
e3fda95b9366212b682d2479af1ded62 *man/staying_by_prop_bin_inflow.Rd
38c78c1991c8354722f814cfa1953bb1 *man/target_change_match.Rd
c67407e0df2c1d4bc1d16539788f5e7a *man/test_effect.Rd
fabd94e5e3be125b7bf4848f0c7b8181 *man/transitivity_GW.Rd
fa68fd0196bc899db04b80b5050d9cdb *man/transitivity_basic.Rd
651adf24f829b5d0313d7199c797f283 *man/transitivity_min.Rd
ab9d6c92a364b82ef1de83930e01cb13 *man/transitivity_netflow.Rd
ec415f029ef856edcaf9db8b125ff3ce *man/triad120C.Rd
c3bfc3bc42c8c442cbf3c3b1dd1a1cd9 *man/triad120D.Rd
8a8301e9a72153a68a11d5f72a4e64cb *man/triad120U.Rd
19 changes: 14 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export(
plot.gof.stats.monan,
plot.traces.monan, print.result.monan, print.scoretest.monan, scoreTest,

# test functions
target_change_match,
test_effect,

# effect functions: exogenous
alter_covariate, dyadic_covariate,
dyadic_covariate_resource_attribute,
Expand All @@ -21,22 +25,27 @@ export(

# effect functions: loops
loops, loops_GW, loops_node_covar,
loops_resource_covar_node_covar, loops_resource_covar,
loops_resource_covar_node_covar, loops_resource_covar,
loops_additional_origin,
loops_x_loops_additional_origin,

# effect functions: concentration
concentration_basic, concentration_GW, concentration_GW_dyad_covar_bin,
concentration_basic, concentration_GW, concentration_GW_dyad_covar,
concentration_prop, concentration_prop_orig_cov, concentration_rankGW,

# effect functions: reciprocity
reciprocity_basic,
reciprocity_min, reciprocity_min_resource_covar,
reciprocity_GW, reciprocity_GW_dyad_covar_bin,
reciprocity_min, reciprocity_min_resource_covar, reciprocity_min_dyad_covar,
reciprocity_GW, reciprocity_GW_dyad_covar_bin, reciprocity_GW_dyad_covar,

# effect functions: transitivity
transitivity_min, transitivity_netflow,
transitivity_basic, transitivity_min, transitivity_netflow, transitivity_GW,
triad120D, triad120U, triad120C,

# effect functions: other
crowding_out_prop_covar_bin,
in_ties_loops, in_weights_exponent,
in_weights_GW,
present_relations, staying_by_prop_bin_inflow,

# gof param functions
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# MoNAn 0.1.3

# MoNAn 0.1.2

* Added a `NEWS.md` file to track changes to the package.
67 changes: 67 additions & 0 deletions R/1_hiddenFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,73 @@ binarizeNetwork <- function(network) {
}


# checkProcessState
checkProcessState <- function(state) {

# extract dependent variable
dep.var <- state$dep.var

# make sure that dependent variable has corresponding edgelist
if (!(dep.var %in% names(state))) {
stop("Dependent variable has no corresponding edgelist in the state object.")
}

# is edgelist of class 'edgelist.monan'?
if (!(inherits(state[[dep.var]], "edgelist.monan"))) {
stop("Dependent variable is not of class 'edgelist.monan'.")
}


# extract nodeset names defined in edgelist
nodesets <- c()
nodesets[1] <- state[[dep.var]]$nodeSet[1]
nodesets[2] <- state[[dep.var]]$nodeSet[2]
nodesets[3] <- state[[dep.var]]$nodeSet[3]

# do nodeset names from edgelist have a corresponding nodeset and are they of class 'nodeset.monan'?
for (i in 1:length(nodesets)) {
if (!(nodesets[i] %in% names(state))) {
stop(paste(nodesets[i], "has no corresponding object.",
"Nodesets specified in the edgelist must have a corresponding object with the same name."))
}
if (!(inherits(state[[nodesets[i]]], "nodeSet.monan"))) {
stop(paste(nodesets[i], "is not of class 'nodeSet.monan'."))
}
}

# do dependent variable and individual nodeset have the same number of observations?
if (!(dim(state[[dep.var]]$data)[1] == length(state[[nodesets[3]]]$ids))) {
stop("Dependent variable and individual nodeset do not have the same number of observations.")
}

# extract covar names
covars <- names(state)[!(names(state) %in% c(dep.var, nodesets, "dep.var"))]

# if there are covars, check them
if (length(covars) != 0) {

# are covars of class 'nodeVar.monan' or 'network.monan'? do they have correctly
# specified nodeset names and are these nodesets of the correct size?
for (i in 1:length(covars)) {
#class
if (!(inherits(state[[covars[i]]], "nodeVar.monan") ||
inherits(state[[covars[i]]], "network.monan"))) {
stop(paste(covars[i], "must either be of class 'nodeVar.monan' or 'network.monan'."))
}
# nodeset names
if (!(all(state[[covars[i]]]$nodeSet %in% names(state)))) {
stop(paste("The nodeset of covar '", covars[i], "' has no corresponding object.",
"Nodesets assigned when creating covars must have a corresponding object with the same name." ))
}
# nodeset sizes
if (!(state[[covars[i]]]$size[1] == length(state[[state[[covars[i]]]$nodeSet[1]]]$ids))) {
stop(paste("The covar '", covars[i], "' is not of the same size as its assigned nodeset."))
}
}
}
}


# getCovarianceMatrix
getCovarianceMatrix <- function(statistics) {
meanStatistics <- colMeans(statistics)
Expand Down
64 changes: 64 additions & 0 deletions R/2_effectFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,70 @@ in_weights_exponent <-
}


#' in_weights_GW
#'
#' Is there a preferential attachment in the mobility network, i.e., do individuals
#' move particularly to popular destinations?
#' The geometrically weighted version avoids degeneracy.
#'
#' @param dep.var
#' @param state
#' @param cache
#' @param i
#' @param j
#' @param edge
#' @param update
#' @param getTargetContribution
#' @param alpha
#'
#' @return Returns the change statistic or target statistic of the effect for
#' internal use by the estimation algorithm.
#' @keywords internal
in_weights_GW <-
function(dep.var = 1,
state,
cache,
i,
j,
edge,
update,
getTargetContribution = FALSE,
alpha = 2) {
if (alpha <= 0) {
stop("Alpha parameter in in_weights_GW weights function must be positive")
}

in_weight <- (sum(cache[[dep.var]]$valuedNetwork[,j]))

# a target contribution is calculated even for unconnected i-j pairs
if (getTargetContribution) {
g_cum <- function(y, a){
contr <- 0
for(k in 0:y){
contr <- contr + (y-k) * exp(-log(a)*k)
}
contr - y
}

return(g_cum(y = in_weight, a = alpha) / (length(cache[[dep.var]]$valuedNetwork[, j])))
}

g_mar <- function(y, a){
contr <- 0
for(k in 0:y){
contr <- contr + exp(-log(a)*k)
}
contr - 1
}

if(update < 0){
return(update * g_mar(y = (in_weight + update), a = alpha))
}
if(update > 0){
return(update * g_mar(y = in_weight, a = alpha))
}
}

#' present_relations
#'
#' Do individuals move along many or few paths out of their origin? This models
Expand Down

0 comments on commit ef3be9d

Please sign in to comment.