Learn R Programming

OlinkAnalyze (version 3.8.2)

olink_anova: Function which performs an ANOVA per protein

Description

Performs an ANOVA F-test for each assay (by OlinkID) in every panel using car::Anova and Type III sum of squares. The function handles both factor and numerical variables and/or covariates.

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 dataframe 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 dataframe 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 formula notation of the final model is specified in a message if verbose = TRUE.

Adjusted p-values are calculated by stats::p.adjust according to the Benjamini & Hochberg (1995) method (“fdr”). The threshold is determined by logic evaluation of Adjusted_pval < 0.05. Covariates are not included in the p-value adjustment.

Usage

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

Value

A "tibble" containing the ANOVA results for every protein. The tibble is arranged by ascending p-values. 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

  • df: "numeric" degrees of freedom

  • sumsq: "numeric" sum of square

  • meansq: "numeric" mean of square

  • 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)

Arguments

df

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

variable

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

outcome

Character. The dependent variable. Default: NPX.

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"). 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 F-test 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.

Examples

Run this code
# \donttest{

library(dplyr)

npx_df <- npx_data1 %>% filter(!grepl('control',SampleID, ignore.case = TRUE))

#One-way ANOVA, no covariates.
#Results in a model NPX~Time
anova_results <- olink_anova(df = npx_df, variable = "Time")

#Two-way ANOVA, one main effect covariate.
#Results in model NPX~Treatment*Time+Site.
anova_results <- olink_anova(df = npx_df,
                             variable=c("Treatment:Time"),
                             covariates="Site")

#One-way ANOVA, interaction effect covariate.
#Results in model NPX~Treatment+Site:Time+Site+Time.
anova_results <- olink_anova(df = npx_df,
                             variable="Treatment",
                             covariates="Site:Time")# }

Run the code above in your browser using DataLab