Various distances, measures of dissimilarity and similarity, correlations and other metrics are computed to compare the models. Optionally, the weight matrices of the models can be scaled before comparison. The resulting object can be used to produce heatmap plots and scatterplots to further illustrate the differences.
compare(x, ...)# S3 method for tna
compare(x, y, scaling = "none", measures = character(0), network = TRUE, ...)
# S3 method for matrix
compare(x, y, scaling = "none", measures = character(0), network = TRUE, ...)
A tna_comparison object, which is a list containing the
following elements:
matrices: A list containing the scaled matrices of the input tna
objects or the scaled inputs themselves in the case of matrices.
difference_matrix: A matrix of differences x - y.
edge_metrics: A data.frame with one row per pair of states (columns
source and target), the weights weight_x and weight_y, and
edge-level metrics of their difference.
summary_metrics: A data.frame with one row per summary metric of the
differences across all edges, with the columns category, metric,
and value.
network_metrics: A data.frame with one row per network metric and
the columns metric, x, and y.
centrality_differences: A data.frame with one row per state and
centrality measure, with the columns state, centrality, x, y,
and difference. Only present when measures is not empty.
centrality_correlations: A data.frame with one row per centrality
measure and the correlation of the measure between x and y. Only
present when measures is not empty.
A tna object or a matrix of weights. A matrix must have
the state names as row and column names.
Ignored.
A tna object or a matrix of weights, with the same states as
x. The states are matched by name, so their order may differ; an
error of class tna_error_states is raised when the states differ or a
matrix has no state names.
A character string naming a scaling method to
apply to the weights before comparing them. The supported options are:
"none": No scaling is performed. The weights are used as is.
"minmax": Performs min-max normalization, i.e., the minimum value is
subtracted and the differences are scaled by the range.
"max": Max-normalization: the values are divided by the maximum value.
"rank": Applies min-max normalization to the ranks of the weights
(computed with ties.method = "average").
"zscore": Computes the standard score, i.e. the mean weight is
subtracted and the differences are scaled by the standard deviation.
"robust": Computes the robust z-score, i.e. the median weight is
subtracted and the differences are scaled by the median absolute deviation
(using stats::mad).
"log": Simply the natural logarithm of the weights.
"log1p": As above, but adds 1 to the values before taking the logarithm.
Useful for scenarios with zero weights.
"softmax": Performs softmax normalization.
"quantile": Uses the empirical quantiles of the weights
via stats::ecdf.
A character vector indicating which centrality
measures should be computed. See centralities() for the
available measures. No measures are included by default.
A logical value indicating whether network metrics should
be included in the comparison. The default is TRUE.
Model comparison functions
compare.group_tna(),
compare_sequences(),
plot.tna_comparison(),
plot.tna_sequence_comparison(),
plot_compare(),
plot_compare.group_tna(),
print.tna_comparison(),
print.tna_sequence_comparison()
# Comparing TNA models
model_x <- tna(head(group_regulation, 200))
model_y <- tna(tail(group_regulation, 200))
comp1 <- compare(model_x, model_y)
# Comparing weight matrices (with the states as row and column names)
states <- c("A", "B")
mat_x <- matrix(c(0.6, 0.3, 0.4, 0.7), 2, 2, dimnames = list(states, states))
mat_y <- matrix(c(0.5, 0.2, 0.5, 0.8), 2, 2, dimnames = list(states, states))
comp2 <- compare(mat_x, mat_y)
print(comp2)
Run the code above in your browser using DataLab