ergm_preprocess_response {ergm} | R Documentation |
Update the network and the response argument.
Description
Update the network and the response argument.
Usage
ergm_preprocess_response(nw, response)
Arguments
nw |
a |
response |
Either a character string, a formula, or
|
Details
If
response
isNULL
orlogical
, drop all edge attributes except forna
and return the network and the response as they are.If
response
is a character vector of length 1, drop all edge attributes innw
except for the one corresponding toresponse
.If
response
is a formula, construct a name for it and assign to that name (as an edge attribute) the result of evaluating the formula environment; drop all other edge attributes. Return as response the name (possibly with the attribute for the formula attached). If the formula's RHS is of the form a|b use the logicalness of b in Step 4.Test if the resulting edge attribute is of mode
logical
. If so setattr(response,'valued')
toFALSE
, otherwise toTRUE
.
If both nw
and response
are ordinary variables (i.e., not expressions) in the parent frame, nw
(whatever it was named) is overwritten with the updated network and response
(again, whatever it was named) is deleted. This is for convenience and for making outdated code that relies on response
fail immediately rather than introduce subtle bugs. Otherwise, the updated network is returned.
Examples
preproc_check_print <- function(nw, response){
ergm_preprocess_response(nw, response)
str(list(
valued = is.valued(nw),
el = head(as.edgelist(nw, attrname=nw%ergmlhs%"response", output="tibble"),3)
))
}
data(florentine)
preproc_check_print(flomarriage, NULL)
flomarriage %e% "w" <- runif(network.edgecount(flomarriage))
flomarriage %e% "s" <- rep(c(-1,1), length.out=network.edgecount(flomarriage))
# Edge attribute expression
preproc_check_print(flomarriage, ~w*s)
# Named
preproc_check_print(flomarriage, wsprod~w*s)
# Binary from valued
preproc_check_print(flomarriage, ~s>0)
# Default edge attribute mode is valued
flomarriage[,] <- 0 # Empty network
preproc_check_print(flomarriage, ~w*s)
# Force default edge attribute mode to binary
preproc_check_print(flomarriage, ~w|TRUE)