View source: R/power_selection_utils.R
| select_soft_power | R Documentation |
Analyze scale-free topology fit across candidate powers and choose the
soft-thresholding power \beta.
select_soft_power(
data_matrix,
r2_threshold = 0.8,
make_plots = FALSE,
output_dir = tempdir()
)
data_matrix |
Numeric matrix/data frame (rows = samples, cols = features). |
r2_threshold |
Target |
make_plots |
Logical; if |
output_dir |
Output directory for plots when |
The function uses a two-stage heuristic:
Choose the smallest \beta whose scale-free fit R^2
exceeds r2_threshold.
If no power reaches the target R^2, select the smallest power
at the elbow of the curve, approximated by the discrete second
derivative
\Delta^2 f(p_i) = f(p_{i+1}) - 2 f(p_i) + f(p_{i-1}),
and pick the p_i with the largest |\Delta^2 f(p_i)|.
Integer scalar: the selected soft-thresholding power.
# --- 1. Create a small synthetic data matrix ---
set.seed(123)
example_data <- matrix(rnorm(50 * 100), nrow = 50, ncol = 100)
# --- 2. Run the function to get the selected power ---
best_power <- select_soft_power(example_data)
print(paste("Best soft power:", best_power))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.