Skip to contents

Compares PageRank before and after proposed changes to the link graph. Useful for SEOs who want to predict the impact of adding or removing internal links, or implementing redirects, before making changes in production.

Usage

simulate_changes(
  edge_list_df,
  add_links_df = NULL,
  remove_links_df = NULL,
  add_redirects_df = NULL,
  redirects_df = NULL,
  ...,
  edge_from_col = "from",
  edge_to_col = "to",
  label_baseline = "baseline",
  label_proposed = "proposed"
)

Arguments

edge_list_df

A data frame representing the current link edge list.

Optional data frame of links to add. Must have the same from/to column names as edge_list_df. Default NULL.

Optional data frame of links to remove. Matching is by exact from+to pair. Must have the same from/to column names as edge_list_df. Default NULL.

add_redirects_df

Optional data frame of new redirects to add. Must have from/to columns (names controlled by pagerank()'s redirect_from_col / redirect_to_col defaults). Default NULL.

redirects_df

Optional data frame of existing redirects (baseline). Default NULL.

...

Additional arguments passed to both pagerank() calls (e.g., clean_edge_urls, damping, nofollow_col, indexability_df, etc.).

edge_from_col

Name of the from column in edge list data frames. Default "from".

edge_to_col

Name of the to column in edge list data frames. Default "to".

label_baseline

Label for the baseline model in the comparison output. Default "baseline".

label_proposed

Label for the proposed model in the comparison output. Default "proposed".

Value

The output of compare_pagerank: a data frame with per-node deltas, percentage changes, and rank changes between baseline and proposed. A "summary" attribute contains aggregate statistics (Spearman rho, mean absolute delta, nodes gained/lost).

Examples

# Current site links
edges <- data.frame(
  from = c("Home", "Home", "About", "Blog"),
  to = c("About", "Blog", "Home", "Home")
)

# Propose adding a link from Blog to About
new_links <- data.frame(
  from = "Blog", to = "About"
)
result <- simulate_changes(edges,
  add_links_df = new_links,
  clean_edge_urls = FALSE
)
print(result)
#>   node_name pagerank_baseline pagerank_proposed       delta pct_change
#> 1     About         0.2567568         0.3333333  0.07657658  29.824561
#> 2      Home         0.4864865         0.4327485 -0.05373795 -11.046134
#> 3      Blog         0.2567568         0.2339181 -0.02283863  -8.895045
#>   rank_baseline rank_proposed rank_delta
#> 1             2             2          0
#> 2             1             1          0
#> 3             2             3         -1
attr(result, "summary")
#> $spearman_rho
#> [1] 0.8660254
#> 
#> $mean_abs_delta
#> [1] 0.05105105
#> 
#> $nodes_gained
#> [1] 0
#> 
#> $nodes_lost
#> [1] 0
#>