View source: R/ergm_response.R
ergm_preprocess_response | R Documentation |
Update the network and the response argument.
ergm_preprocess_response(nw, response)
nw |
a |
response |
Either a character string, a formula, or
|
If response
is NULL
or logical
, drop all edge attributes except for na
and return the network and the response as they are.
If response
is a character vector of length 1, drop all edge attributes in nw
except for the one corresponding to response
.
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 set attr(response,'valued')
to FALSE
, otherwise to TRUE
.
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.