Description Usage Arguments Details Value Author(s) References See Also Examples
View source: R/stats.R View source: R/stats.R
Calculates exposure to adoption over time via multiple different types of weight matrices. The basic model is exposure to adoption by immediate neighbors (outdegree) at the time period prior to ego’s adoption. This exposure can also be based on (1) incoming ties, (2) structural equivalence, (3) indirect ties, (4) attribute weighted (5) networkmetric weighted (e.g., central nodes have more influence), and attributeweighted (e.g., based on homophily or tie strength).
1 2 3 4 
graph 
A dynamic graph (see 
cumadopt 
n * T matrix. Cumulative adoption matrix obtained from

attrs 
Either a character scalar (if 
alt.graph 
Either a graph that should be used instead of 
outgoing 
Logical scalar. When 
valued 
Logical scalar. When 
normalized 
Logical scalar. When 
groupvar 
Passed to 
self 
Logical scalar. When 
lags 
Integer scalar. When different from 0, the resulting exposure matrix will be the lagged exposure as specified (see examples). 
... 
Further arguments passed to 
Exposure is calculated as follows:
E(t) = (S(t) %*% [x(t) * A(t)]) / [S(t) %*% x(t)]
Where S(t) is the graph in time t, x(t) is an attribute vector of size n at time t, A(t) is the tth column of the cumulative adopters matrix (a vector of length n with a(t,i)=1 if i has adopted at or prior to t), * is the kronecker product (elementwise), and %*% is the matrix product.
By default the graph used for this calculation, S, is the social network. Alternatively,
in the case of diffnet
objects, the user can provide an alternative
graph using alt.graph
. An example of this would be using 1/SE,
the elementwise inverse of the structural equivalence matrix (see example below).
Furthermore, if alt.graph="se"
, the inverse of the structural equivalence
is computed via struct_equiv
and used instead of the provided
graph. Notice that when using a valued graph the option valued
should
be equal to TRUE
, this check is run automatically when running the
model using structural equivalence.
If the alt.graph
is static, then the function will warn about it
and will recycle the graph to compute exposure at each time point.
An important remark is that when calculating structural equivalence the
function assumes that this is to be done to the entire graph regardless of
disconnected communities (as in the case of the medical innovations
data set). Hence, structural equivalence for individuals for two different
communites may not be zero. If the user wants to calculate structural
equivalence separately by community, he should create different diffnet
objects and do so (see example below). Alternatively, for the case of
diffnet objects, by using the option groupvar
(see struct_equiv
), the user can provide
the function with the name of a grouping variable–which should one in the
set of static vertex attributes–so that the algorithm is done by group
(or community) instead of in an aggregated way.
If the user does not specifies a particular weighting attribute in attrs
,
the function sets this as a matrix of ones. Otherwise the function will return
an attribute weighted exposure. When graph
is of class diffnet
,
attrs
can be a character scalar specifying the name of any of the graph's
attributes, both dynamic and static. See the examples section for a demonstration using
degree.
When outgoing=FALSE
, S is replaced by its transposed, so in the
case of a social network exposure will be computed based on the incoming ties.
If normalize=FALSE
then denominator, S(t) %*% x(t),
is not included. This can be useful when, for example, exposure needs to be
computed as a count instead of a proportion. A good example of this can be
found at the examples section of the function rdiffnet
.
A matrix of size n * T with exposure for each node.
George G. Vega Yon, Stephanie R. Dyal, Timothy B. Hayes & Thomas W. Valente
Burt, R. S. (1987). "Social Contagion and Innovation: Cohesion versus Structural Equivalence". American Journal of Sociology, 92(6), 1287. http://doi.org/10.1086/228667
Valente, T. W. (1995). "Network models of the diffusion of innovations" (2nd ed.). Cresskill N.J.: Hampton Press.
Other statistics: bass
,
classify_adopters
,
cumulative_adopt_count
, dgr
,
ego_variance
, hazard_rate
,
infection
, moran
,
struct_equiv
, threshold
,
vertex_covariate_dist
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109  # Calculating lagged exposure 
set.seed(8)
graph < rdiffnet(20, 4)
expo0 < exposure(graph)
expo1 < exposure(graph, lags = 1)
# These should be equivalent
stopifnot(all(expo0[, 4] == expo1[, 1])) # No stop!
# Calculating the exposure based on Structural Equivalence 
set.seed(113132)
graph < rdiffnet(100, 10)
SE < lapply(struct_equiv(graph), "[[", "SE")
SE < lapply(SE, function(x) {
x < 1/x
x[!is.finite(x)] < 0
x
})
# Recall setting valued equal to TRUE!
expo_se < exposure(graph, alt.graph=SE , valued=TRUE)
# These three lines are equivalent to:
expo_se2 < exposure(graph, alt.graph="se", valued=TRUE)
# Notice that we are setting valued=TRUE, but this is not necesary since when
# alt.graph = "se" the function checks this to be setted equal to TRUE
# Weighted Exposure using degree 
eDE < exposure(graph, attrs=dgr(graph))
# Which is equivalent to
graph[["deg"]] < dgr(graph)
eDE2 < exposure(graph, attrs="deg")
# Comparing using incoming edges 
eIN < exposure(graph, outgoing=FALSE)
# Structral equivalence for different communities 
data(medInnovationsDiffNet)
# METHOD 1: Using the c.diffnet method:
# Creating subsets by city
cities < unique(medInnovationsDiffNet[["city"]])
diffnet < medInnovationsDiffNet[medInnovationsDiffNet[["city"]] == cities[1]]
diffnet[["expo_se"]] < exposure(diffnet, alt.graph="se", valued=TRUE)
for (v in cities[1]) {
diffnet_v < medInnovationsDiffNet[medInnovationsDiffNet[["city"]] == v]
diffnet_v[["expo_se"]] < exposure(diffnet_v, alt.graph="se", valued=TRUE)
diffnet < c(diffnet, diffnet_v)
}
# We can set the original order (just in case) of the data
diffnet < diffnet[medInnovationsDiffNet$meta$ids]
diffnet
# Checking everything is equal
test < summary(medInnovationsDiffNet, no.print=TRUE) ==
summary(diffnet, no.print=TRUE)
stopifnot(all(test[!is.na(test)]))
# METHOD 2: Using the 'groupvar' argument
# Further, we can compare this with using the groupvar
diffnet[["expo_se2"]] < exposure(diffnet, alt.graph="se",
groupvar="city", valued=TRUE)
# These should be equivalent
test < diffnet[["expo_se", as.df=TRUE]] == diffnet[["expo_se2", as.df=TRUE]]
stopifnot(all(test[!is.na(test)]))
# METHOD 3: Computing exposure, rbind and then adding it to the diffnet object
expo_se3 < NULL
for (v in unique(cities))
expo_se3 < rbind(
expo_se3,
exposure(
diffnet[diffnet[["city"]] == v],
alt.graph = "se", valued=TRUE
))
# Just to make sure, we sort the rows
expo_se3 < expo_se3[diffnet$meta$ids,]
diffnet[["expo_se3"]] < expo_se3
test < diffnet[["expo_se", as.df=TRUE]] == diffnet[["expo_se3", as.df=TRUE]]
stopifnot(all(test[!is.na(test)]))
# METHOD 4: Using the groupvar in struct_equiv
se < struct_equiv(diffnet, groupvar="city")
se < lapply(se, "[[", "SE")
se < lapply(se, function(x) {
x < 1/x
x[!is.finite(x)] < 0
x
})
diffnet[["expo_se4"]] < exposure(diffnet, alt.graph=se, valued=TRUE)
test < diffnet[["expo_se", as.df=TRUE]] == diffnet[["expo_se4", as.df=TRUE]]
stopifnot(all(test[!is.na(test)]))

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.