### Start ReferenceRangeR with Docker Source: https://github.com/gubruol/referenceranger/blob/main/README.md Command to pull and run the latest ReferenceRangeR container on x64 systems. Maps the container to local port 80. ```bash docker run -d -p 80:3838 --name referenceranger gubruol/referenceranger:latest ``` -------------------------------- ### Run ReferenceRangeR Docker Container (Bash) Source: https://context7.com/gubruol/referenceranger/llms.txt Commands to pull, run, stop, and remove the ReferenceRangeR Docker container. Ensure you are on an x64 platform. ```bash # Pull and run the Docker container docker run -d -p 80:3838 --name referenceranger gubruol/referenceranger:latest # Access the application # Open browser to: http://localhost # Stop the container docker stop referenceranger # Remove the container docker rm referenceranger # Note: Only supported on x64 (Intel/AMD) platforms # Not compatible with ARM-based systems like Raspberry Pi ``` -------------------------------- ### Data Table Configuration and Preprocessing Source: https://context7.com/gubruol/referenceranger/llms.txt Initializes the input dataframe and standardizes laboratory data formats, including regex validation for numeric results. ```r # Data frame structure for input # Supports up to 200,000 rows (tablesize) tablesize <- 200000 # Define accepted sex labels (multi-language support) malelist <- c('male', 'männlich', 'Mann', 'M', 'm') femalelist <- c('female', 'weiblich', 'Frau', 'F', 'f', 'W', 'w') diverselist <- c("D", "d", "diverse", "Diverse") sexlist <- c(malelist, femalelist, diverselist) # Initialize data frame dataframe <- data.frame( result = rep(NA, tablesize), age = rep(NA, tablesize), sex = factor(rep(NA, tablesize), levels = sexlist) ) # Data validation regex (accepts decimals with . or , separator) # Also accepts values starting with "<" for below detection limit resultvalidator <- "function(value, callback) { setTimeout(function() { if (value === null || value === '') { callback(true); } else { var regex = /^ 0 & !is.na(dataframe$result), ] # Standardize sex labels to M/F/D dataframe <- dataframe %>% mutate(sex = ifelse( sex %in% femalelist, 'F', ifelse(sex %in% malelist, 'M', ifelse(sex %in% diverselist, 'D', 'X')) )) ``` -------------------------------- ### refineR: Basic Reference Interval Estimation Source: https://context7.com/gubruol/referenceranger/llms.txt Estimates reference intervals using the refineR method with Box-Cox transformation. Set NBootstrap > 0 for confidence intervals. Requires the 'refineR' library. ```r library(refineR) # Basic reference interval estimation with refineR data <- na.omit(dataframe$result) # Standard estimation without bootstrapping resri <- findRI( Data = data, model = "BoxCox", # or "modBoxCox" for modified Box-Cox NBootstrap = 0 # Set >0 for confidence intervals (e.g., 50) ) # Get reference interval limits ri_limits <- getRI(resri) # Returns: 2.5th percentile (lower RL) and 97.5th percentile (upper RL) lower_limit <- ri_limits[1, 2] # Lower reference limit upper_limit <- ri_limits[2, 2] # Upper reference limit # With bootstrapping for 95% CI resri_with_ci <- findRI( Data = data, model = "BoxCox", NBootstrap = 50 ) # Access confidence intervals lower_ci_low <- getRI(resri_with_ci)[1, 3] # Lower limit CI low lower_ci_high <- getRI(resri_with_ci)[1, 4] # Lower limit CI high upper_ci_low <- getRI(resri_with_ci)[2, 3] # Upper limit CI low upper_ci_high <- getRI(resri_with_ci)[2, 4] # Upper limit CI high # Plot the result plot(resri) ``` -------------------------------- ### Visualize Group Distributions Source: https://context7.com/gubruol/referenceranger/llms.txt Generates violin and box plots with custom y-axis limits based on quantiles. ```r q10 <- quantile(dataframe$result, probs = 0.1) q90 <- quantile(dataframe$result, probs = 0.9) ylim.min <- q10 - (q90 - q10) / 1.3 ylim.max <- q90 + (q90 - q10) / 1.3 ggplot(dataframe, aes(sex, result)) + ylim(ylim.min, ylim.max) + labs(x = NULL) + theme_minimal() + theme(axis.text = element_text(size = 16), axis.title = element_text(size = 18)) + geom_violin(fill = "#40668d", alpha = 0.2) + geom_boxplot(fill = "#40668d", outlier.shape = NA, width = 0.1) ``` -------------------------------- ### Kernel Density Estimation with kosmic Source: https://context7.com/gubruol/referenceranger/llms.txt Performs reference interval estimation using kernel density methods, requiring data with at least one decimal place. ```r library(tidykosmic) # Data must have at least one decimal place data <- na.omit(dataframe$result) # Check for decimal values (kosmic requirement) if (any((data %% 1) > 0)) { # Run kosmic estimation with 1 decimal precision result <- kosmic(data, decimals = 1) # Extract reference limits from summary summary_result <- summary(result) lower_limit <- summary_result[1] # Lower reference limit upper_limit <- summary_result[3] # Upper reference limit # Plot the distribution and estimated limits plot(result) } else { # kosmic requires decimal data warning("kosmic requires at least one decimal place in data") } ``` -------------------------------- ### Reference Limit Estimation with reflimR Source: https://context7.com/gubruol/referenceranger/llms.txt Estimates reference intervals and validates them against permissible uncertainty guidelines. ```r library(reflimR) # Basic reference interval estimation data <- dataframe$result result <- reflim(data) # Extract reference limits lower_limit <- result$limits[1] # Lower reference limit upper_limit <- result$limits[2] # Upper reference limit # Plot without comparison targets reflim(data, targets = NULL) # Plot with comparison against existing reference limits # Visualizes whether estimated limits fall within permissible uncertainty reflim(data, targets = c(35.0, 125.0)) # Compare with known limits # Calculate permissible uncertainty for validation # Based on CLSI EP28-A3c guidelines pU <- permissible_uncertainty( referencelimits.low = 35.0, referencelimits.high = 125.0 ) # Returns: [lower_limit_low, lower_limit_high, upper_limit_low, upper_limit_high] ``` -------------------------------- ### Plot Comparison Limits on Histogram (R) Source: https://context7.com/gubruol/referenceranger/llms.txt Plots estimated and reference limits on a histogram, highlighting permissible uncertainty bounds. Requires pre-calculated limits and a reference to permissible_uncertainty function. ```r plotcomparisonlimits <- function(estimatedlimits.low, estimatedlimits.high, referencelimits.low, referencelimits.high) { # Calculate permissible uncertainty bounds pU <- permissible_uncertainty(referencelimits.low, referencelimits.high) # Determine colors based on whether estimates fall within bounds col1 <- if (estimatedlimits.low > pU[1] && estimatedlimits.low < pU[2]) '#10D010' else 'red' col2 <- if (estimatedlimits.high > pU[3] && estimatedlimits.high < pU[4]) '#10D010' else 'red' # Draw permissible uncertainty regions rect(pU[1], 0, pU[2], 99999, col = adjustcolor(col1, alpha.f = 0.05), border = FALSE) rect(pU[3], 0, pU[4], 99999, col = adjustcolor(col2, alpha.f = 0.05), border = FALSE) # Draw reference limit lines (dashed) abline(v = referencelimits.low, col = adjustcolor(col1, alpha.f = 0.40), lwd = 2, lty = 3) abline(v = referencelimits.high, col = adjustcolor(col2, alpha.f = 0.40), lwd = 2, lty = 3) # Draw estimated limit lines (solid) abline(v = estimatedlimits.low, col = "#10D010", lwd = 3) abline(v = estimatedlimits.high, col = "#10D010", lwd = 3) } ``` ```r plot(refiner_result) plotcomparisonlimits( estimatedlimits.low = 35.2, estimatedlimits.high = 127.5, referencelimits.low = 35.0, referencelimits.high = 125.0 ) ``` -------------------------------- ### TML: Truncated Maximum Likelihood Estimation Source: https://context7.com/gubruol/referenceranger/llms.txt Estimates reference intervals using the TML method with a power-normal distribution. Automatically determines truncation points. Requires sourcing TML functions. ```r # Source TML functions source("TML.R") # Prepare data data <- na.omit(dataframe$result) # Determine truncation direction based on data distribution # Compare estimated pathological values on left vs right side reflim_estimates <- reflim(data)$limits estimate_left <- length(data[data < reflim_estimates[1]]) estimate_right <- length(data[data > reflim_estimates[2]]) pathright <- estimate_right > estimate_left # Run TML estimation # pathright = TRUE: pathological values predominantly on right side # pathright = FALSE: pathological values predominantly on left side result <- tml(data, pathright) # Extract reference limits lower_limit <- result$DL25 # 2.5th percentile (lower RL) upper_limit <- result$DL975 # 97.5th percentile (upper RL) # Display the plot replayPlot(result$myplot) # TML internal parameters (configured in function): # Q1 <- 0.10 # Lower quantile for truncation search # Q2 <- 0.90 # Upper quantile for truncation search # low_RL <- 0.025 # Lower reference limit percentile ``` -------------------------------- ### Perform Dynamic Age Stratification Source: https://context7.com/gubruol/referenceranger/llms.txt Merges age groups iteratively based on median deviation and permissible uncertainty thresholds. ```r library(mgcv) library(qgam) library(reflimR) # Prepare data with age limits agell <- 18 ageul <- 99 dataframe <- dataframe[(dataframe$age >= agell) & (dataframe$age <= ageul), ] # Subsample for large datasets (>10,000) if (nrow(dataframe) > 10000) { dataframe <- dataframe[sample(1:nrow(dataframe), 10000), ] } # Calculate permissible uncertainty pu_percent <- 2.39 * (-0.25 + 100 * (-1 + exp((( log(reflim(dataframe$result)$limits[2]) - log(reflim(dataframe$result)$limits[1])) / 3.92)^2))^0.5)^0.5 pu_absolute <- pu_percent * median(dataframe$result) / 100 # Create age groups based on data resolution agedigits <- 3 - floor(log10(max(dataframe$age))) agegroups <- data.frame( from = seq( round(min(dataframe$age), agedigits), round(max(dataframe$age), agedigits), by = 10^-agedigits ) ) %>% mutate(to = from + 10^-agedigits) # Fit quantile regression for median prediction pred <- predict( qgam(result ~ s(age), data = dataframe, qu = 0.5), newdata = data.frame(age = (agegroups$from + agegroups$to) / 2), se = TRUE ) agegroups <- agegroups %>% mutate( median = pred$fit, ci.low = pred$fit - 1.96 * pred$se.fit, ci.high = pred$fit + 1.96 * pred$se.fit ) %>% rowwise() %>% mutate(count = sum(dataframe$age >= from & dataframe$age < to)) %>% ungroup() # Remove empty groups agegroups <- agegroups[agegroups$count > 0, ] # Iterative merging algorithm stratnum <- 3 # Maximum number of age groups (user setting) while (TRUE) { if (length(agegroups$median) <= 1) break diffs <- diff(agegroups$median) idx <- which.min(diffs) # Stop conditions based on permissible uncertainty if ((length(agegroups$median) > stratnum) && (diffs[idx] >= 0.5 * pu_absolute)) break if ((length(agegroups$median) <= stratnum) && (diffs[idx] >= 0.25 * pu_absolute)) break # Merge adjacent groups agegroups$to[idx] <- agegroups$to[idx + 1] agegroups$count[idx] <- agegroups$count[idx] + agegroups$count[idx + 1] agegroups$median[idx] <- median( dataframe[dataframe$age >= agegroups$from[idx] & dataframe$age <= agegroups$to[idx], ]$result ) agegroups <- agegroups[-(idx + 1), ] } # Remove groups with insufficient data agegroups <- agegroups[agegroups$count >= 50, ] ``` -------------------------------- ### Perform Statistical Group Comparison Source: https://context7.com/gubruol/referenceranger/llms.txt Determines the appropriate statistical test based on the number of groups and calculates median differences. ```r n_groups <- length(unique(dataframe$sex)) if (n_groups == 2) { # Wilcoxon rank-sum test for 2 groups pvalue <- wilcox.test(result ~ sex, data = dataframe)$p.value test_used <- "Wilcoxon rank-sum test" } else if (n_groups > 2) { # Kruskal-Wallis test for 3+ groups pvalue <- kruskal.test(result ~ sex, data = dataframe)$p.value test_used <- "Kruskal-Wallis test" } # Calculate median differences mediantable <- dataframe %>% group_by(sex) %>% summarise( count = n(), median = median(result, na.rm = TRUE) ) mediandiff <- round( (max(mediantable$median) - min(mediantable$median)) / min(mediantable$median) * 100, digits = 2 ) ``` -------------------------------- ### Statistical Sex Difference Analysis Source: https://context7.com/gubruol/referenceranger/llms.txt Filters data by age and group size to perform statistical comparisons between sexes. ```r library(ggplot2) library(reflimR) # Filter data by age range agell <- 18 # Lower age limit ageul <- 65 # Upper age limit dataframe <- dataframe[(dataframe$age >= agell) & (dataframe$age <= ageul), ] # Remove groups with insufficient data (n < 100) dataframe <- dataframe %>% group_by(sex) %>% filter(n() >= 100) # Calculate permissible uncertainty percentage pu_percent <- 2.39 * (-0.25 + 100 * (-1 + exp((( log(reflim(dataframe$result)$limits[2]) - log(reflim(dataframe$result)$limits[1])) / 3.92)^2))^0.5)^0.5 ``` -------------------------------- ### TMC: Truncated Minimum Chi-Square Estimation Source: https://context7.com/gubruol/referenceranger/llms.txt Estimates reference intervals using the TMC method, which handles detection limits and pathological values. Requires sourcing TMC functions and settings. ```r # Source the TMC functions and settings source("TMC.settings.R") source("TMC.functions.R") # Prepare data - TMC can handle values marked with "<" for below detection limit data <- na.omit(dataframe$result) # Run TMC estimation # The function automatically: # - Processes detection limits (values starting with "<") # - Sorts data and calculates appropriate histogram bins # - Finds optimal truncation interval # - Estimates reference limits using chi-square minimization result <- tmc(data) # Extract reference limits from result lower_reference_limit <- result$RL1 # 2.5th percentile estimate upper_reference_limit <- result$RL2 # 97.5th percentile estimate # Access the plot replayPlot(result$myplot) # TMC settings can be customized in TMC.settings.R: # RL1.p <- 0.025 # Lower percentile (default 2.5%) # RL2.p <- 0.975 # Upper percentile (default 97.5%) # n.per.bin.min <- 10 # Minimum observations per histogram bin # alpha <- 0.05 # Significance level ``` -------------------------------- ### Pregnancy Trimester Stratification Source: https://context7.com/gubruol/referenceranger/llms.txt Adds and filters data based on pregnancy trimester categories. ```r # Add trimester column to existing dataframe dataframe$trimester <- factor(rep(NA, nrow(dataframe)), levels = c(0, 1, 2, 3)) # Filter by trimester for analysis trimester_selected <- 2 # 1, 2, or 3 if (!all(dataframe$trimester == 0, na.rm = TRUE)) { dataframe_filtered <- dataframe[dataframe$trimester == trimester_selected, ] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.