panel.pvalue: Calculate and draw p-values in lattice plots

View source: R/panel_pvalue.R

panel.pvalueR Documentation

Calculate and draw p-values in lattice plots

Description

This panel function allows to overlay p-values obtained from a statistical significance test on plots, together with "significance" symbols such as stars as it is often in encountered in the scientific literature. It supports Student's t-test and Wilcoxon rank sum test (also called Mann-Whitney U-test for two-sample comparisons). The Wilcoxon test is used for non-parametric (non normally distributed data). Different input options for the tests can be specified.

Usage

panel.pvalue(
  x,
  y,
  method = "t.test",
  alternative = "two.sided",
  paired = FALSE,
  two_sample = TRUE,
  mu = 0,
  std = NULL,
  symbol = TRUE,
  pvalue = FALSE,
  pval_digits = 2,
  cex = 0.8,
  offset = NULL,
  fixed_pos = NULL,
  verbose = FALSE,
  col = trellis.par.get()$plot.symbol$col,
  ...
)

Arguments

x, y

(numeric, character) variables to be plotted. The x variable is treated as a grouping variable, i.e. p-values are calculated between groups of unique x values.

method

(character) "t.test" for Student's t-test, or "wilcox.test" for Wilcoxon ranked sum test. The latter is also called Mann-Whitney U-test for two-sample comparisons (the default).

alternative

(character) passed to t.test(), one of "two.sided", "less", or "greater"

paired

(logical) if the different groups of y values are paired (default: FALSE)

two_sample

(logical) if TRUE a two-sample is made, else a one-sample comparison (default: TRUE)

mu

(numeric) a number indicating the true value of the mean (or difference in means if you are performing a two sample test). Passed to the test indicated by 'method'

std

(character, numeric) the value of x that is used as standard. If NULL, the first value is used as standard. If a numeric scalar i, std is determined as the i'th element of unique(x). If character, it must match one of x. If std = 'all_values', each unique group of x is compared to the total population. Ignored for one sample tests, that are compared against 'mu'

symbol

(logical) if '*' symbols should be drawn for significance

pvalue

(logical) if numeric p-values should be drawn for significance

pval_digits

(numeric) how many p-value digits should be printed (default is 2)

cex

(numeric) character size of the symbol

offset

(numeric) offset in native plot units used to adjust the position of text labels. If offset is length 1, only the vertical position is adjusted; if it is length 2 the horizontal and vertical position is adjusted

fixed_pos

(numeric) fixed vertical position of the p-value, if NULL determined from the data (the default)

verbose

(logical) if a summary of the p-value calculation should be printed to the terminal

col

(character) the color to be used

...

other arguments passed to the function

Examples

library(lattice)
data(mtcars)

# p-values are calculated between groups of x, grouping is ignored
xyplot(mpg ~ factor(cyl), mtcars, groups = cyl, pch = 19, cex = 0.7,
  panel = function(x, y, ...) {
    panel.stripplot(x, y, jitter.data = TRUE, 
      horizontal = FALSE, amount = 0.15, ...)
    panel.pvalue(x, y, std = 1, symbol = TRUE,
      pvalue = TRUE, offset = 6)
})


m-jahn/lattice-tools documentation built on Dec. 3, 2023, 11:14 p.m.