### Aggregate Multiple Ranked Lists with RRA Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Demonstrates basic usage of aggregateRanks with sample data for aggregating three ranked lists of letters using the default RRA method. Shows how to specify the total number of possible elements (N) and view the aggregated results. ```r library(RobustRankAggreg) # Basic usage with sample data - aggregate three ranked lists of letters glist <- list( list1 = sample(letters, 4), # Top 4 letters from one source list2 = sample(letters, 10), # Top 10 from another source list3 = sample(letters, 12) # Top 12 from a third source ) # Aggregate using default RRA method # N specifies total number of possible elements (26 letters) result <- aggregateRanks(glist = glist, N = length(letters)) head(result) # Name Score # 1 a 0.001234567 # 2 b 0.003456789 # 3 c 0.012345678 ``` -------------------------------- ### Analyze cellCycleKO Dataset Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Demonstrates loading and processing the built-in yeast gene knockout dataset to identify significant genes. ```r library(RobustRankAggreg) # Load the dataset data(cellCycleKO) # Examine structure str(cellCycleKO) # List of 3: # $ gl : list of 12 gene vectors (one per TF knockout) # $ N : total number of yeast genes # $ ref: reference list of known cell cycle genes # Number of transcription factor experiments length(cellCycleKO$gl) # 12 TF knockouts # Total genes in yeast genome cellCycleKO$N # ~6000 genes # View gene lists from first few knockouts head(cellCycleKO$gl[[1]], 10) # Top 10 affected genes in first knockout head(cellCycleKO$gl[[2]], 10) # Top 10 in second knockout # Full analysis pipeline # Step 1: Create rank matrix r <- rankMatrix(cellCycleKO$gl, N = cellCycleKO$N) dim(r) # genes x knockouts # Step 2: Aggregate rankings aggregated <- aggregateRanks(rmat = r) # Step 3: Get significant genes significant <- aggregated[aggregated$Score < 0.05, ] cat("Significant genes found:", nrow(significant), "\n") ``` -------------------------------- ### Aggregate Ranks with Different Methods Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Illustrates using aggregateRanks with various aggregation methods including 'stuart', 'mean', 'median', 'min', and 'geom.mean'. This allows for flexibility in how ranked lists are combined. ```r # Using different aggregation methods result_stuart <- aggregateRanks(glist = glist, N = 26, method = "stuart") result_mean <- aggregateRanks(glist = glist, N = 26, method = "mean") result_median <- aggregateRanks(glist = glist, N = 26, method = "median") result_min <- aggregateRanks(glist = glist, N = 26, method = "min") result_geom <- aggregateRanks(glist = glist, N = 26, method = "geom.mean") ``` -------------------------------- ### Gene List Analysis with Included Dataset Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Demonstrates a real-world gene list analysis using the `cellCycleKO` dataset included in the package. It shows how to convert the gene lists to a rank matrix and then aggregate them. ```r # Real-world gene list analysis using included dataset data(cellCycleKO) # cellCycleKO contains gene lists from 12 transcription factor knockouts r <- rankMatrix(cellCycleKO$gl, N = cellCycleKO$N) gene_results <- aggregateRanks(rmat = r) # View top aggregated genes head(gene_results) # Name Score # 1 YPL256C 1.234567e-08 # 2 YMR034C 2.345678e-07 # 3 YDL185W 3.456789e-06 # Filter for significantly enriched genes (p < 0.05) significant_genes <- gene_results[gene_results$Score < 0.05, ] nrow(significant_genes) # Number of significant genes ``` -------------------------------- ### Accurate Aggregation with Top Cutoffs Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Shows how to achieve more accurate aggregation results by specifying `topCutoff` when list cutoffs are known in advance. This is useful when the proportion of ranked items is known. ```r # For more accurate results when list cutoffs are known in advance # If lists are limited to 4, 10, and 12 elements out of 26 total: topCutoff <- c(4/26, 10/26, 12/26) result_accurate <- aggregateRanks(glist = glist, N = 26, topCutoff = topCutoff) ``` -------------------------------- ### Rank Matrix for Full Rankings with Non-Overlapping Sets Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Illustrates the creation of a rank matrix for scenarios involving full rankings where the element sets do not overlap. This prepares data for aggregation when different platforms or experiments cover distinct sets of items. ```r # Handle full rankings with non-overlapping element sets # When rankings are complete but cover different elements glist_full <- list( platform1 = sample(letters[4:24]), # Letters d through x platform2 = sample(letters[2:22]), # Letters b through v platform3 = sample(letters[1:20]) # Letters a through t ) ``` -------------------------------- ### Create Rank Matrix Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Converts lists of ranked elements into a matrix of normalized ranks. Use full=TRUE to represent missing elements as NA. ```r # Use full=TRUE to mark truly missing elements as NA (not just unranked) r_full <- rankMatrix(glist_full, full = TRUE) head(r_full) # platform1 platform2 platform3 # a NA NA 0.050 # b NA 0.045 0.100 # c NA 0.091 0.150 # d 0.048 0.136 0.200 # Real-world usage with gene lists data(cellCycleKO) r_genes <- rankMatrix(cellCycleKO$gl, N = cellCycleKO$N) dim(r_genes) # Shows matrix dimensions: genes x experiments ``` -------------------------------- ### Rank Matrix with Explicit Total Elements Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Demonstrates specifying the total number of rankable elements (N) when creating a rank matrix. This is crucial for accurate p-value calculations, especially when N is different from the number of unique elements found in the lists. ```r # Specify total number of rankable elements explicitly # Important for accurate p-values when N differs from unique elements r <- rankMatrix(glist, N = 26) ``` -------------------------------- ### Convert Ranked Lists to Rank Matrix Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Shows the basic conversion of partial rankings from a list of experiments into a normalized rank matrix using the `rankMatrix` function. Missing elements are assigned a rank of 1 (lowest). ```r library(RobustRankAggreg) # Basic conversion of partial rankings glist <- list( experiment1 = sample(letters, 4), experiment2 = sample(letters, 10), experiment3 = sample(letters, 12) ) # Convert to rank matrix - missing elements get rank 1 (lowest) r <- rankMatrix(glist) dim(r) # rows = unique elements, cols = number of lists #[1] 16 3 head(r) # experiment1 experiment2 experiment3 # a 0.250 0.100 0.083 # b 1.000 0.200 0.167 # c 0.500 1.000 0.250 ``` -------------------------------- ### aggregateRanks - Aggregate Multiple Ranked Lists Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Combines multiple ranked lists into a single consensus ranking using the Robust Rank Aggregation algorithm and other methods. It handles partial rankings and returns a dataframe with aggregated scores or p-values. ```APIDOC ## aggregateRanks - Aggregate Multiple Ranked Lists ### Description The main function for combining multiple ranked lists into a single consensus ranking. It implements the Robust Rank Aggregation algorithm along with several alternative methods. The function accepts either a list of ranked elements or a pre-computed rank matrix, handles partial rankings by assuming missing values equal the maximum rank, and returns a dataframe with element names and their aggregated scores or p-values sorted by significance. ### Method `aggregateRanks` ### Parameters #### Path Parameters None #### Query Parameters - **glist** (list) - A list of ranked elements. - **rmat** (matrix) - A pre-computed rank matrix. - **N** (numeric) - The total number of possible elements. - **method** (character) - The aggregation method to use (e.g., "rra", "stuart", "mean", "median", "min", "geom.mean"). Defaults to "rra". - **topCutoff** (numeric vector) - A vector of top cutoff proportions for each list. ### Request Example ```r library(RobustRankAggreg) # Basic usage with sample data - aggregate three ranked lists of letters glist <- list( list1 = sample(letters, 4), # Top 4 letters from one source list2 = sample(letters, 10), # Top 10 from another source list3 = sample(letters, 12) # Top 12 from a third source ) # Aggregate using default RRA method # N specifies total number of possible elements (26 letters) result <- aggregateRanks(glist = glist, N = length(letters)) head(result) # Using different aggregation methods result_stuart <- aggregateRanks(glist = glist, N = 26, method = "stuart") result_mean <- aggregateRanks(glist = glist, N = 26, method = "mean") result_median <- aggregateRanks(glist = glist, N = 26, method = "median") result_min <- aggregateRanks(glist = glist, N = 26, method = "min") result_geom <- aggregateRanks(glist = glist, N = 26, method = "geom.mean") # For more accurate results when list cutoffs are known in advance # If lists are limited to 4, 10, and 12 elements out of 26 total: topCutoff <- c(4/26, 10/26, 12/26) result_accurate <- aggregateRanks(glist = glist, N = 26, topCutoff = topCutoff) # Real-world gene list analysis using included dataset data(cellCycleKO) # cellCycleKO contains gene lists from 12 transcription factor knockouts r <- rankMatrix(cellCycleKO$gl, N = cellCycleKO$N) gene_results <- aggregateRanks(rmat = r) # View top aggregated genes head(gene_results) # Filter for significantly enriched genes (p < 0.05) significant_genes <- gene_results[gene_results$Score < 0.05, ] nrow(significant_genes) # Number of significant genes ``` ### Response #### Success Response (200) - **Name** (character) - The name of the element. - **Score** (numeric) - The aggregated score or p-value. #### Response Example ```json { "Name": "a", "Score": 0.001234567 } ``` ``` -------------------------------- ### betaScores - Calculate Beta Distribution P-values Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Calculates p-values for each order statistic in a normalized rank vector based on the beta distribution. ```APIDOC ## betaScores ### Description Calculates p-values for each order statistic in a normalized rank vector based on the beta distribution. This is the core statistical component of the RRA algorithm, testing whether observed ranks are smaller than expected under a uniform null distribution. ### Parameters #### Request Body - **ranks** (numeric vector) - Required - A vector of normalized ranks or p-values. ### Response #### Success Response (200) - **p-values** (numeric vector) - A vector of calculated p-values corresponding to the input ranks. ``` -------------------------------- ### rankMatrix - Convert Ranked Lists to Matrix Format Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Transforms a list of ranked elements into a normalized rank matrix. This matrix is suitable for the `aggregateRanks` function, with cell values representing normalized ranks. ```APIDOC ## rankMatrix - Convert Ranked Lists to Matrix Format ### Description Converts a list of ranked elements into a normalized rank matrix suitable for the aggregateRanks function. Each column represents a ranking, each row represents an element, and cell values are normalized ranks in [0, 1]. Missing values for partial rankings are substituted with the maximum rank (1), while structural missing values (when element sets don't overlap) are marked as NA. ### Method `rankMatrix` ### Parameters #### Path Parameters None #### Query Parameters - **glist** (list) - A list of ranked elements. - **N** (numeric) - The total number of rankable elements. ### Request Example ```r library(RobustRankAggreg) # Basic conversion of partial rankings glist <- list( experiment1 = sample(letters, 4), experiment2 = sample(letters, 10), experiment3 = sample(letters, 12) ) # Convert to rank matrix - missing elements get rank 1 (lowest) r <- rankMatrix(glist) dim(r) # rows = unique elements, cols = number of lists head(r) # Specify total number of rankable elements explicitly # Important for accurate p-values when N differs from unique elements r <- rankMatrix(glist, N = 26) # Handle full rankings with non-overlapping element sets # When rankings are complete but cover different elements glist_full <- list( platform1 = sample(letters[4:24]), # Letters d through x platform2 = sample(letters[2:22]), # Letters b through v platform3 = sample(letters[1:20]) # Letters a through t ) ``` ### Response #### Success Response (200) - **Matrix** (matrix) - A normalized rank matrix where rows are elements and columns are rankings. #### Response Example ```json { "matrix": [ ["a", 0.250, 0.100, 0.083], ["b", 1.000, 0.200, 0.167], ["c", 0.500, 1.000, 0.250] ] } ``` ``` -------------------------------- ### Calculate Beta Distribution P-values Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Computes p-values for order statistics based on the beta distribution. Useful for testing enrichment of small values in rank vectors. ```r library(RobustRankAggreg) # Basic usage with uniform random values (null hypothesis) uniform_ranks <- runif(15) beta_pvals <- betaScores(uniform_ranks) print(beta_pvals) # P-values should be roughly uniform under null # Test with enriched small values (alternative hypothesis) # Mix uniform with values drawn from beta(1, 50) which concentrates near 0 enriched_ranks <- c(runif(10), rbeta(5, 1, 50)) beta_pvals_enriched <- betaScores(enriched_ranks) print(beta_pvals_enriched) # Early order statistics should have very small p-values # Visualize the difference par(mfrow = c(1, 2)) hist(betaScores(runif(100)), main = "Null (uniform input)", xlab = "Beta p-values", breaks = 20) hist(betaScores(c(runif(80), rbeta(20, 1, 50))), main = "Enriched small values", xlab = "Beta p-values", breaks = 20) # Apply to actual p-values from multiple tests # Example: combining p-values from multiple differential expression analyses pvalues_study1 <- c(0.001, 0.05, 0.3, 0.8, 0.95) beta_result <- betaScores(pvalues_study1) min(beta_result) # Minimum gives the RRA rho score basis ``` -------------------------------- ### Validate and Calculate Enrichment for Aggregated Ranks Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Compares the top 100 aggregated genes against a reference set and computes the fold enrichment relative to expected random overlap. ```R # Step 4: Validate against known cell cycle genes known_cc_genes <- cellCycleKO$ref top_100 <- head(aggregated$Name, 100) overlap <- sum(top_100 %in% known_cc_genes) cat("Known cell cycle genes in top 100:", overlap, "\n") # Calculate enrichment total_known <- length(known_cc_genes) expected <- 100 * total_known / cellCycleKO$N cat("Expected by chance:", round(expected, 1), "\n") cat("Fold enrichment:", round(overlap / expected, 2), "\n") ``` -------------------------------- ### rhoScores - Calculate RRA Rho Score Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Computes the rho score for the Robust Rank Aggregation algorithm by applying betaScores to a normalized rank vector. ```APIDOC ## rhoScores ### Description Computes the rho score for the Robust Rank Aggregation algorithm by applying betaScores to a normalized rank vector and returning a corrected p-value based on the minimum beta score. ### Parameters #### Request Body - **ranks** (numeric vector) - Required - Normalized rank vector. - **topCutoff** (numeric vector) - Optional - Known cutoffs for each list. - **exact** (boolean) - Optional - Whether to perform exact p-value calculation. ``` -------------------------------- ### Calculate RRA Rho Score Source: https://context7.com/raivokolde/robustrankaggreg/llms.txt Computes the RRA rho score by applying betaScores and correcting for multiple testing. Supports optional topCutoff and exact calculation modes. ```r library(RobustRankAggreg) # Basic rho score calculation with uniform values uniform_input <- runif(15) rho <- rhoScores(uniform_input) print(rho) # Should be roughly uniform under null # Rho score with enriched small values (signal present) signal_input <- c(runif(10), rbeta(5, 1, 50)) rho_signal <- rhoScores(signal_input) print(rho_signal) # Should be very small, indicating significance # Compare multiple samples set.seed(123) rho_null <- replicate(1000, rhoScores(runif(10))) rho_alt <- replicate(1000, rhoScores(c(runif(7), rbeta(3, 1, 50)))) # Visualize distribution difference par(mfrow = c(1, 2)) hist(rho_null, main = "Null distribution", xlab = "Rho scores", breaks = 30) hist(rho_alt, main = "With signal", xlab = "Rho scores", breaks = 30) # Using topCutoff for more accurate scores when list limits are known # Example: 3 lists limited to top 10%, 20%, and 50% of elements ranks <- c(0.05, 0.08, 0.15) # Normalized ranks from 3 lists topCutoff <- c(0.1, 0.2, 0.5) # Known cutoffs for each list rho_accurate <- rhoScores(ranks, topCutoff = topCutoff) # Exact p-value calculation (slower but more precise for small list counts) rho_exact <- rhoScores(signal_input, exact = TRUE) rho_approx <- rhoScores(signal_input, exact = FALSE) cat("Exact:", rho_exact, "Approximate:", rho_approx, "\n") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.