triadStat {rem} | R Documentation |
Calculate triad statistics
Description
Calculate the endogenous network statistic triads
that measures the tendency for events to close open triads.
Usage
triadStat(data, time, sender, target, halflife,
weight = NULL,
eventtypevar = NULL,
eventtypevalues = NULL,
eventfiltervar = NULL,
eventfilterAI = NULL,
eventfilterBI = NULL,
eventfilterAB = NULL,
eventvar = NULL,
variablename = 'triad',
returnData = FALSE,
showprogressbar = FALSE,
inParallel = FALSE, cluster = NULL
)
Arguments
data |
A data frame containing all the variables. |
time |
Numeric variable that represents the event sequence. The variable has to be sorted in ascending order. |
sender |
A string (or factor or numeric) variable that represents the sender of the event. |
target |
A string (or factor or numeric) variable that represents the target of the event. |
halflife |
A numeric value that is used in the decay function. The vector of past events is weighted by an exponential decay function using the specified halflife. The halflife parameter determins after how long a period the event weight should be halved. E.g. if |
weight |
An optional numeric variable that represents the weight of each event. If |
eventtypevar |
An optional dummy variable that represents the type of the event. Use |
eventtypevalues |
Two string values that represent the type of the past events. The first string value represents the eventtype that exists for all past events that include the current sender (either as sender or target) and a third actor. The second value represents the eventtype for all past events that include the target (either as sender or target) as well as the third actor.
An example: Let the |
eventfiltervar |
An optional string (or factor or numeric) variable that can be used to filter past and current events. Use |
eventfilterAI |
An optional value used to specify how paste events should be filtered depending on their attribute. Each distinct edge that form a triad can be filtered. |
eventfilterBI |
see |
eventfilterAB |
see |
eventvar |
An optional dummy variable with 0 values for null-events and 1 values for true events. If the |
variablename |
An optional value (or values) with the name the triad
statistic variable should be given. To be used if |
returnData |
|
showprogressbar |
|
inParallel |
|
cluster |
An optional numeric or character value that defines the cluster. By specifying a single number, the cluster option uses the provided number of nodes to parallellize. By specifying a cluster using the |
Details
The triadStat()
-function calculates an endogenous statistic that measures whether events have a tendency to form closing triads.
The effect is calculated as follows:
represents the network of past events and includes all events
. These events consist
each of a sender
and a target
and a weight function
:
where is the event weight (usually a constant set to 1 for each event),
is the current event time,
is the past event time and
is a halflife parameter.
For the triad effect, the past events are filtered to include only events
where the current event closes an open triad in the past.
An exponential decay function is used to model the effect of time on the endogenous statistics. The further apart the past event is from the present event, the less weight is given to this event. The halflife parameter in the triadStat()
-function determines at which rate the weights of past events should be reduced. Therefore, if the one (or more) of the two events in the triad have occurred further in the past, less weight is given to this triad because it becomes less likely that the sender and target actors reacted to each other in the way the triad assumes.
The eventtypevar
- and eventattributevar
-options help filter the past events more specifically. How they are filtered depends on the eventtypevalue
- and eventattributevalue
-option.
Author(s)
Laurence Brandenberger laurence.brandenberger@eawag.ch
See Also
Examples
# create some data with 'sender', 'target' and a 'time'-variable
# (Note: Data used here are random events from the Correlates of War Project)
sender <- c('TUN', 'UNK', 'NIR', 'TUR', 'TUR', 'USA', 'URU',
'IRQ', 'MOR', 'BEL', 'EEC', 'USA', 'IRN', 'IRN',
'USA', 'AFG', 'ETH', 'USA', 'SAU', 'IRN', 'IRN',
'ROM', 'USA', 'USA', 'PAN', 'USA', 'USA', 'YEM',
'SYR', 'AFG', 'NAT', 'UNK', 'IRN')
target <- c('BNG', 'RUS', 'JAM', 'SAU', 'MOM', 'CHN', 'IRQ',
'AFG', 'AFG', 'EEC', 'BEL', 'ITA', 'RUS', 'UNK',
'IRN', 'RUS', 'AFG', 'ISR', 'ARB', 'USA', 'USA',
'USA', 'AFG', 'IRN', 'IRN', 'IRN', 'AFG', 'PAL',
'ARB', 'USA', 'EEC', 'IRN', 'CHN')
time <- c('800107', '800107', '800107', '800109', '800109',
'800109', '800111', '800111', '800111', '800113',
'800113', '800113', '800114', '800114', '800114',
'800116', '800116', '800116', '800119', '800119',
'800119', '800122', '800122', '800122', '800124',
'800125', '800125', '800127', '800127', '800127',
'800204', '800204', '800204')
type <- sample(c('cooperation', 'conflict'), 33,
replace = TRUE)
important <- sample(c('important', 'not important'), 33,
replace = TRUE)
# combine them into a data.frame
dt <- data.frame(sender, target, time, type, important)
# create event sequence and order the data
dt <- eventSequence(datevar = dt$time, dateformat = "%y%m%d",
data = dt, type = "continuous",
byTime = "daily", returnData = TRUE,
sortData = TRUE)
# create counting process data set (with null-events) - conditional logit setting
dts <- createRemDataset(dt, dt$sender, dt$target, dt$event.seq.cont,
eventAttribute = dt$type,
atEventTimesOnly = TRUE, untilEventOccurrs = TRUE,
returnInputData = TRUE)
dtrem <- dts[[1]]
dt <- dts[[2]]
# manually sort the data set
dtrem <- dtrem[order(dtrem$eventTime), ]
# merge type-variable back in
dtrem$type <- dt$type[match(dtrem$eventID, dt$eventID)]
# calculate triad statistic
dtrem$triad <- triadStat(data = dtrem, time = dtrem$eventTime,
sender = dtrem$sender, target = dtrem$target,
eventvar = dtrem$eventDummy,
halflife = 2)
# calculate friend-of-friend statistic
dtrem$triad.fof <- triadStat(data = dtrem, time = dtrem$eventTime,
sender = dtrem$sender, target = dtrem$target,
halflife = 2, eventtypevar = dtrem$type,
eventtypevalues = c("cooperation",
"cooperation"),
eventvar = dtrem$eventDummy)
# calculate friend-of-enemy statistic
dtrem$triad.foe <- triadStat(data = dtrem, time = dtrem$eventTime,
sender = dtrem$sender, target = dtrem$target,
halflife = 2, eventtypevar = dtrem$type,
eventtypevalues = c("conflict",
"cooperation"),
eventvar = dtrem$eventDummy)
# calculate enemy-of-friend statistic
dtrem$triad.eof <- triadStat(data = dtrem, time = dtrem$eventTime,
sender = dtrem$sender, target = dtrem$target,
halflife = 2, eventtypevar = dtrem$type,
eventtypevalues = c("cooperation",
"conflict"),
eventvar = dtrem$eventDummy)
# calculate enemy-of-enemy statistic
dtrem$triad.eoe <- triadStat(data = dtrem, time = dtrem$eventTime,
sender = dtrem$sender, target = dtrem$target,
halflife = 2, eventtypevar = dtrem$type,
eventtypevalues = c("conflict",
"conflict"),
eventvar = dtrem$eventDummy)