View source: R/transform_weights.R
| transform_weights | R Documentation |
Applies a transformation strategy to a numeric vector of edge
weights before passing them to pagerank. Useful for
converting link positions, click counts, or other raw signals into weights
suitable for the PageRank random surfer model.
transform_weights(
x,
method = c("none", "log", "percentile", "minmax", "zipf", "rank_linear"),
alpha = 1,
offset = 1,
floor_value = 0.01,
descending = TRUE
)
x |
Numeric vector of raw weights (e.g., link positions on a page, GA4 click counts, or any positive numeric signal). |
method |
Character, the transformation strategy. One of:
|
alpha |
Numeric, exponent for the |
offset |
Numeric, added to |
floor_value |
Numeric, minimum weight for the |
descending |
Logical. For rank-based methods ( |
Numeric vector of the same length as x with transformed
weights. NA values in x are preserved as NA in
the output.
# Link positions on a page (1 = top, most valuable)
positions <- c(1, 2, 3, 4, 5)
transform_weights(positions, "rank_linear", descending = FALSE)
transform_weights(positions, "zipf", alpha = 1, descending = FALSE)
transform_weights(positions, "zipf", alpha = 2, descending = FALSE)
# GA4 click counts (wide range)
clicks <- c(50000, 12000, 800, 150, 3)
transform_weights(clicks, "log")
transform_weights(clicks, "minmax")
transform_weights(clicks, "zipf")
# Use with pagerank()
edges <- data.frame(
from = c("Home", "Home", "Home"),
to = c("About", "Blog", "Contact"),
position = c(1, 2, 5)
)
edges$weight <- transform_weights(edges$position, "zipf",
descending = FALSE
)
# pagerank(edges, weight_col = "weight", clean_edge_urls = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.