Performs simple linear regression (one predictor) for each row (or column)
of a tidymatrix. For multiple predictors, use compute_lm() instead.
Usage
compute_lm_simple(
.data,
predictor,
adjust = "fdr",
add_to_data = FALSE,
prefix = NULL,
return_tibble = TRUE
)Arguments
- .data
A tidymatrix object with rows or columns active
- predictor
Character. Name of predictor variable in metadata
- adjust
Character. Method for p-value adjustment. Default "fdr". Use "none" for no adjustment
- add_to_data
Logical. If TRUE, adds results to row_data/col_data and returns modified tidymatrix. If FALSE (default), returns data.frame
- prefix
Character. Optional prefix for result column names when
add_to_data = TRUE- return_tibble
Logical. If TRUE (default), returns tibble. If FALSE, returns data.frame. Only applies when
add_to_data = FALSE
Value
A data.frame/tibble with columns: identifiers, slope, intercept, r.squared, p.value, and p.adj (if adjustment applied)
Examples
mat <- matrix(rnorm(100), nrow = 10, ncol = 10)
col_data <- data.frame(
sample = paste0("S", 1:10),
age = rnorm(10, 50, 10)
)
row_data <- data.frame(gene = paste0("Gene", 1:10))
tm <- tidymatrix(mat, row_data, col_data)
# Simple linear regression
results <- tm |>
activate(rows) |>
compute_lm_simple(predictor = "age")