comparePvalues: Draw a scatter plot and histograms to compare p-values from...

View source: R/func__visualisation__comparePvalues.R

comparePvaluesR Documentation

Draw a scatter plot and histograms to compare p-values from linear mixed models (LMMs) and penalised logistic models (PLMs).

Description

This function only works at the pattern level. There are two ways to group p-values: (1) grouping by p-values when L.weak <= 0 (default); and (2) grouping by log10 lambda0 of X and Y when parameter L.weak > 0. Each way results in four groups, which by default are coloured coded as red (group 0), purple (group 1), blue (group 2) and grey (group 3). Note that this function assumes that the number of hypothesis tests equals the number of rows in the input data frames p.lmm and p.plm, which must have the same number of rows as well.

Dependencies: ggplot2, grid, gridExtra, and reshape2.

Usage

comparePvalues(
  p.lmm,
  p.plm,
  lmm.h0 = NULL,
  p.min = 2.2e-16,
  p.adj.max = 0.05,
  L.weak = 0,
  bks = seq(0, 16, by = 2),
  show.p.adj.max = TRUE,
  cols = c(`0` = "grey50", `1` = "blue", `2` = "red", `3` = "purple"),
  panel.num = 3,
  panel.titles = c("a", "b", "c"),
  boxplot.show.group = TRUE,
  boxplot.default.fill = "grey80",
  plot.title.size = 10,
  axis.title.size = 10,
  axis.title.size.panelB = 3,
  axis.text.size = 8,
  img = "pvalue_comparison.png",
  img.w = 150,
  img.h = 150,
  img.r = 300,
  img.u = "mm",
  img.oma = c(0.1, 0.1, 0.1, 0.1),
  img.mar = c(3, 2.6, 1, 0.5),
  img.mgp = c(1.8, 0.6, -0.2),
  p.prev = NULL
)

Arguments

p.lmm

A data frame from the function lmm for association status between patterns. Assuming assoc = lmm(...), then p.lmm = assoc$lmms.pat$dif$h1.

p.plm

A data frame from the function plr for association status between patterns. Assuming assoc = plr(...), then p.plm = assoc$pat. Pattern orders for association tests must match to those in p.lmm. Otherwise, both data frames cannot merge correctly.

lmm.h0

A data frame from the function lmm for null models. lmm.h0 = assoc$lmms.pat$dif$h0.

p.min

Minimum of raw p-values that can be represented in users' computers precisely. Default: 2.2e-16. Any p-value that is smaller than this cut-off will be substituted by it in this function.

p.adj.max

Maximum of Bonferroni-corrected p-values for concluding significance. Default: 0.05.

L.weak

Maximum of estimate lambda0 for defining weak structural random effects (default: 1, whose log10 equals zero). This parameter is used for grouping data points when L.weak > 0.

bks

Breaks for X and Y axes in the plot. They correspond to -log10 transformed raw p-values. Default value: c(0, 2, 4, 6, ..., 16).

show.p.adj.max

A logical argument determine whether to draw a grey dashed line on each axis to indicate the cutoff for significance. Default: TRUE.

cols

A character vector with names "0", "1", "2" and "3" for definition of colours for all four groups. When data points are grouped by p-values, 0: not significant in either LMMs or PLMs; 1: only significant in PLMs; 2: only significant in LMMs; and 3: significant in both LMMs and PLMs. When data points are grouped by lambda0, 0: weak structural random effects in both X and Y; 1: strong structural random effects only in X; 2: strong structural random effects only in Y; 3: strong structural random effects in both X and Y.

panel.num

An integer argument specifying how many panels are to be drawn in the figure. By default, three panels (panel.num = 3: two box plots and one scatter plot) are created. Otherwise, two panels (one scatter plot and one box plot with groups names LMM and PLM) are drawn.

panel.titles

A vector of two (panel.num = 2) or three (panel.num = 3) characters for titles of figure panels. Default: c("a", "b", "c").

boxplot.show.group

Whether to draw box plots showing every group of data points. Default: TRUE. Two box plots each has a single box will be drawn if this parameter is FALSE.

boxplot.default.fill

Fill colour when boxplot.group = FALSE. Default: grey80.

plot.title.size

Size of the title of each panel.

axis.title.size

Size of axis titles.

axis.title.size.panelB

Title sizes for panel b, which should be much smaller than axis.title.size and controls the alignment of panels.

axis.text.size

Size of axis labels.

img

Name and path for the output PNG file. Default: comp_pvals.png.

img.w

Image width.

img.h

Image height.

img.r

Image resolution.

img.u

Unit for the image width and height.

img.oma

The argument oma for the function par during plotting.

img.mar

The argument mar for the function par.

img.mgp

The argument mgp for the function par.

p.prev

Output of this function from a previous run. Other inputs will be ignored if p.prev is specified.

Value

A data frame underlying the output plot.

Author(s)

Yu Wan (wanyuac@126.com)


wanyuac/GeneMates documentation built on Aug. 12, 2022, 7:37 a.m.