#
# The following are equivalent ways to compute differential
# homophily.
#
data(sampson)
(groups <- sort(unique(samplike%v%"group"))) # Sorted list of groups.
# The "normal" way:
summary(samplike ~ nodematch("group", diff=TRUE))
# One element at a time, specifying a list:
summary(samplike ~ For(~nodematch("group", levels=., diff=TRUE),
. = groups))
# One element at a time, specifying a function that returns a list:
summary(samplike ~ For(~nodematch("group", levels=., diff=TRUE),
. = function(nw) sort(unique(nw%v%"group"))))
# One element at a time, specifying a formula whose RHS expression
# returns a list:
summary(samplike ~ For(~nodematch("group", levels=., diff=TRUE),
. = ~sort(unique(.%v%"group"))))
#
# Multiple iterators are possible, in any order. Here, absdiff() is
# being computed for each combination of attribute and power.
#
data(florentine)
# The "normal" way:
summary(flomarriage ~ absdiff("wealth", pow=1) + absdiff("priorates", pow=1) +
absdiff("wealth", pow=2) + absdiff("priorates", pow=2) +
absdiff("wealth", pow=3) + absdiff("priorates", pow=3))
# With a loop; note that the attribute (a) is being iterated within
# power (.):
summary(flomarriage ~ For(. = 1:3, a = c("wealth", "priorates"), ~absdiff(a, pow=.)))
Run the code above in your browser using DataLab