Executes [pagerank()] for each entry in a named parameter grid, returning a single combined data frame with a `model_id` column identifying which configuration produced each row.
Usage
pagerank_grid(
edge_list_df,
params_grid,
redirects_df = NULL,
...,
edge_from_col = "from",
edge_to_col = "to"
)Arguments
- edge_list_df
A data frame representing the edge list (passed to every [pagerank()] call).
- params_grid
A named list of named lists. Each inner list contains parameter overrides for [pagerank()]. The top-level names become the `model_id` values in the output.
- redirects_df
An optional redirect data frame (passed to every call). Default `NULL`.
- ...
Common parameters shared across all models (e.g., `clean_edge_urls`, `rurl_params`, `damping`). These are passed to every [pagerank()] call and can be overridden by entries in `params_grid`.
- edge_from_col, edge_to_col
Names of from/to columns in `edge_list_df`. Default `"from"` / `"to"`.
Value
A data frame with columns `model_id`, `node_name`, and `pagerank` (or the column names returned by [pagerank()]). Rows from different models are stacked via [rbind()].
Examples
edges <- data.frame(
from = c("A", "B", "C", "A"),
to = c("B", "C", "A", "C")
)
params <- list(
baseline = list(damping = 0.85, self_loops = "drop"),
high_damp = list(damping = 0.95, self_loops = "drop"),
keep_loops = list(damping = 0.85, self_loops = "keep")
)
grid <- pagerank_grid(edges, params, clean_edge_urls = FALSE)
print(grid)
#> model_id node_name pagerank
#> 1 baseline A 0.3877897
#> 2 baseline B 0.2148106
#> 3 baseline C 0.3973997
#> 4 high_damp A 0.3959743
#> 5 high_damp B 0.2047545
#> 6 high_damp C 0.3992712
#> 7 keep_loops A 0.3877897
#> 8 keep_loops B 0.2148106
#> 9 keep_loops C 0.3973997
# Compare two models from the grid
baseline <- grid[grid$model_id == "baseline", ]
high_damp <- grid[grid$model_id == "high_damp", ]
compare_pagerank(baseline, high_damp)
#> node_name pagerank_a pagerank_b delta pct_change rank_a rank_b
#> 1 B 0.2148106 0.2047545 -0.010056159 -4.6814068 3 3
#> 2 A 0.3877897 0.3959743 0.008184607 2.1105787 2 2
#> 3 C 0.3973997 0.3992712 0.001871552 0.4709496 1 1
#> rank_delta
#> 1 0
#> 2 0
#> 3 0