olink_ttest: Function which performs a t-test per protein

View source: R/olink_ttest.R

olink_ttestR Documentation

Description

Performs a Welch 2-sample t-test or paired t-test at confidence level 0.95 for every protein (by OlinkID) for a given grouping variable using stats::t.test and corrects for multiple testing by the Benjamini-Hochberg method (“fdr”) using stats::p.adjust. Adjusted p-values are logically evaluated towards adjusted p-value<0.05. The resulting t-test table is arranged by ascending p-values.

Usage

olink_ttest(df, variable, pair_id, check_log = NULL, ...)

Arguments

df

NPX data frame in long format with at least protein name (Assay), OlinkID, UniProt and a factor with 2 levels.

variable

Character value indicating which column should be used as the grouping variable. Needs to have exactly 2 levels.

pair_id

Character value indicating which column indicates the paired sample identifier.

check_log

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

...

Options to be passed to t.test. See ?t.test for more information.

Value

A "tibble" containing the t-test results for every protein. Columns include:

  • Assay: "character" Protein symbol

  • OlinkID: "character" Olink specific ID

  • UniProt: "character" UniProt ID

  • Panel: "character" Name of Olink Panel

  • estimate: "numeric" difference in mean NPX between groups

  • Group 1: "numeric" Column is named first level of variable when converted to factor, contains mean NPX for that group

  • Group 2: "numeric" Column is named second level of variable when converted to factor, contains mean NPX for that group

  • statistic: "named numeric" value of the t-statistic

  • p.value: "numeric" p-value for the test

  • parameter: "named numeric" degrees of freedom for the t-statistic

  • conf.low: "numeric" confidence interval for the mean (lower end)

  • conf.high: "numeric" confidence interval for the mean (upper end)

  • method: "character" which t-test method was used

  • alternative: "character" describes the alternative hypothesis

  • 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("broom"))) {
  npx_df <- OlinkAnalyze::npx_data1 |>
    dplyr::filter(
    !grepl(
      pattern = "control",
      x = .data[["SampleID"]],
      ignore.case = TRUE
    )
  )
  check_log <- OlinkAnalyze::check_npx(df = npx_df)

  ttest_results <- OlinkAnalyze::olink_ttest(
    df = npx_df,
    variable = "Treatment",
    alternative = "two.sided",
    check_log = check_log
  )

  # Paired t-test
  ttest_paired_results <- npx_df |>
    dplyr::filter(
      .data[["Time"]] %in% c("Baseline", "Week.6")
    ) |>
    OlinkAnalyze::olink_ttest(
      variable = "Time",
      pair_id = "Subject",
      check_log = check_log
    )
}



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