olink_lmer: Function that performs a linear mixed model per protein.

View source: R/olink_lmer.R

olink_lmerR Documentation

Description

Fits a linear mixed effects model for every protein (by OlinkID) in every panel, using lmerTest::lmer and stats::anova. The function handles both factor and numerical variables and potential covariates.

Usage

olink_lmer(
  df,
  variable,
  check_log = NULL,
  outcome = "NPX",
  random,
  covariates = NULL,
  model_formula,
  return.covariates = FALSE,
  verbose = TRUE
)

Arguments

df

NPX data frame in long format with at least protein name (Assay), OlinkID, UniProt, 1-2 variables with at least 2 levels.

variable

Single character value or character array. Variables to test. If length > 1, the included variable names will be used in crossed analyses. Also takes ':' or '*' notation.

check_log

A named list returned by check_npx(). If NULL, check_npx() will be run internally using df.

outcome

Character. The dependent variable. Default: NPX.

random

Single character value or character array.

covariates

Single character value or character array. Default: NULL. Covariates to include. Takes ':' or '*' notation. Crossed analysis will not be inferred from main effects.

model_formula

(optional) Symbolic description of the model to be fitted in standard formula notation (e.g. NPX~A*B + (1|ID)). If provided, this will override the outcome, variable and covariates. arguments. Can be a string or of class stats::formula().

return.covariates

Boolean. Default: FALSE. Returns results for the covariates. Note: Adjusted p-values will be NA for the covariates.

verbose

Boolean. Default: TRUE. If information about removed samples, factor conversion and final model formula is to be printed to the console.

Details

Samples that have no variable information or missing factor levels are automatically removed from the analysis (specified in a message if verbose = TRUE). Character columns in the input dataset are automatically converted to factors (specified in a message if verbose = TRUE). Numerical variables are not converted to factors. If a numerical variable is to be used as a factor, this conversion needs to be done on the dataset before the function call.

Crossed analysis, i.e. A*B formula notation, is inferred from the variable argument in the following cases:

  • c('A','B')

  • c('A:B')

  • c('A:B', 'B') or c('A:B', 'A')

Inference is specified in a message if verbose = TRUE.

For covariates, crossed analyses need to be specified explicitly, i.e. two main effects will not be expanded with a c('A','B') notation. Main effects present in the variable takes precedence. The random variable only takes main effects. The formula notation of the final model is specified in a message if verbose = TRUE.

Output p-values are adjusted by stats::p.adjust according to the Benjamini-Hochberg method (“fdr”). Adjusted p-values are logically evaluated towards adjusted p-value<0.05. Model terms specified as covariates are not included in the adjusted p-value calculation and are not evaluated towards the significance threshold, but are included in the output table if return.covariates = TRUE.

If the model_formula argument is used, all model terms will be tested and included in the results. When using a model formula, the covariates argument can be set to specify terms that should be excluded from the adjusted p-value calculation and significance threshold evaluation.

Value

A "tibble" containing the results of fitting the linear mixed effects model to every protein by OlinkID, ordered by ascending p-value. Columns include:

  • Assay: "character" Protein symbol

  • OlinkID: "character" Olink specific ID

  • UniProt: "character" UniProt ID

  • Panel: "character" Name of Olink Panel

  • term: "character" term in model

  • sumsq: "numeric" sum of square

  • meansq: "numeric" mean of square

  • NumDF: "integer" numerator of degrees of freedom

  • DenDF: "numeric" denominator of decrees of freedom

  • statistic: "numeric" value of the statistic

  • p.value: "numeric" nominal p-value

  • Adjusted_pval: "numeric" adjusted p-value for the test (Benjamini&Hochberg)

  • Threshold: "character" if adjusted p-value is significant or not (< 0.05)

Examples


if (rlang::is_installed(pkg = c("lme4", "lmerTest", "broom"))) {
  #data
  npx_df <- OlinkAnalyze::npx_data1 |>
    dplyr::filter(
      !grepl(
        pattern = "control|ctrl",
        x = .data[["SampleID"]],
        ignore.case = TRUE
      )
    )

  # check data
  npx_df_check_log <- OlinkAnalyze::check_npx(
    df = npx_df
  )

  # Results in model NPX ~ Time * Treatment + (1 | Subject) + (1 | Site)
  lmer_results <- OlinkAnalyze::olink_lmer(
    df = npx_df,
    check_log = npx_df_check_log,
    variable = c("Time", "Treatment"),
    random = c("Subject", "Site")
  )
}



OlinkAnalyze documentation built on June 24, 2026, 1:06 a.m.