View source: R/interpretation.R
marginalplot | R Documentation |
Plot marginal effects for two-way interactions in (T)ERGMs.
marginalplot(
model,
var1,
var2,
inter,
ci = 0.95,
rug = FALSE,
point = FALSE,
structzeromat = NULL,
zeroline = TRUE,
color = "black",
xlab = NULL,
ylab = NULL
)
model |
An |
var1 |
Name of the first main variable. This is the focal variable. |
var2 |
Name of the second main variable. This is the conditioning variable. |
inter |
Name of the interaction effect. |
ci |
Significance level. |
rug |
Display the distribution of the conditioning variable at the bottom of the plot? |
point |
Display error bars for the levels of the conditioning variable (instead of a continuous curve)? |
structzeromat |
An optional matrix object which indicates dyads that should be deleted prior to the calculation of the confidence interval for the marginal effect curve. This is useful when such a matrix was used to indicate structural zeros during estimation. In this event, the dyads characterized by structural zeros are not allowed to be tied, therefore they should be removed from the set of dyads used for the calculation of marginal effects. The matrix should contain ones for structural zeros and zeros for entries that should be used. |
zeroline |
Draw a horizontal line to indicate zero for the first main variable? |
color |
Color of the curve, confidence interval, and distribution. |
xlab |
Axis label for the second (conditioning) variable. |
ylab |
Axis label for the first (focal) variable. |
The marginalplot
function creates marginal effects plots for ERGMs
with interaction effects. The user has to supply the ergm
object and
the coefficient names of the first main variable, the second main variable,
and the interaction term as stored in the coefficients vector inside the
ergm
object. It is possible to draw continuous curves or discrete
error bars depending on the nature of the data (using the point
argument). The distribution of the second (conditioning) variable can be
plotted at the bottom of the viewport using the rug
argument.
The resulting marginal effects plot is a ggplot2
plot. This means it
can be extended by plotting additional elements and using themes.
Other interpretation:
edgeprob()
,
interpret()
## Not run:
# data preparation
data("florentine")
n <- network.size(flobusiness)
wealth <- get.vertex.attribute(flobusiness, "wealth")
priorates <- get.vertex.attribute(flobusiness, "priorates")
wealth.icov <- matrix(rep(wealth, n), ncol = n, byrow = TRUE)
priorates.icov <- matrix(rep(priorates, n), ncol = n, byrow = TRUE)
interac <- wealth.icov * priorates.icov
# estimate model with interaction effect
model <- ergm(flobusiness ~ edges + esp(1) + edgecov(wealth.icov)
+ edgecov(priorates.icov) + edgecov(interac))
# plot the interaction (note the additional optional ggplot2 elements)
marginalplot(model, var1 = "edgecov.wealth.icov",
var2 = "edgecov.priorates.icov", inter = "edgecov.interac",
color = "darkred", rug = TRUE, point = FALSE,
xlab = "Priorates", ylab = "Wealth") +
ggplot2::theme_bw() +
ggplot2::ggtitle("Interaction effect")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.