rp.t_test: Graphical display for inference in comparing the means of one...

View source: R/rp_t_test.R

rp.t_testR Documentation

Graphical display for inference in comparing the means of one or two samples

Description

The sample(s) of data are plotted along with a graphical display which indicates the uncertainty in the location of the true means and in their difference. This is done by plotting a shaded representation of a normal distribution in 'violin plot' style. This can also be compared with a reference mean, representing the null hypothesis in a t-test.

Usage

rp.t_test(x, y = NULL, panel = TRUE, mu = NULL, data.display = 'density',
          display = c(distribution = FALSE, detail = FALSE),
          ruler.position = 'none', candidate, print = FALSE,
          cols, xlab, ylab, vlab, hscale = 1, vscale = hscale, ...)

Arguments

x

a vector of data on a continuous scale or a formula with a response variable and a single predictor variable which is a factor with two levels.

y

an optional second vector of data on a continuous scale, to allow two-sample or paired-sample analyses. Alternatively, y may be a character vector or a factor with two levels, defining the groups. If x is a formula then y is ignored.

panel

a logical value which determines whether the function runs in interactive mode.

mu

a numerical value representing a reference mean of interest, for example a null hypothesis in a formal test. This is the same parameter as mu in t.test but its default value is NULL so that a reference value will be display only if requested.

data.display

a character value which controls the form of the data and display. Valid options are 'histogram', 'density' or 'violin'.

display

a named logical vector which controls the form of uncertainty to be displayed. The named elements are 'distribution' for display of the reference distribution and 'detail' for the display of further details.

ruler.position

a character value which determines whether a standard error scale is added to the plot and its location, 'candidate' or 'sample mean'.

candidate

a numeric value controlling where the standard error ruler is located when ruler.position is set to 'candidate'.

print

a logical value which controls whether the results are printed on the console.

cols

the colours to be used in constructing the display. The default values are set by the rp.colours function whose help file give the details.

xlab, ylab, vlab

character values providing labels for the group(s) to be analysed and for the measurement scale (vlab).

hscale, vscale

scaling parameters for the size of the plot when panel is set to TRUE. The default values are 1.

...

further named argument, which will be passed on to the t.test function. Useful arguments include paired and var.equal which both take logical values.

Details

The graphics are created through the ggplot2 package so this needs to be installed.

The function aims to follow the general pattern of the t.test function and the arguments of t.test described in its help file can also be passed to rp.t_test.

Value

A ggplot object is returned. This allows further alterations and annotations to be made.

References

Bowman, A.W. (2019). Graphics for uncertainty (with discussion). Journal of the Royal Statistics Society, Series A, Statistics & Society, 182, 403-418.

Examples

## Not run: 
x <- rnorm(50)
rp.t_test(x)
rp.t_test(x, mu = 0)
rp.t_test(x, uncertainty = 'sample mean')
rp.t_test(x, uncertainty = 'reference')

g <- factor(rep(1:2, each = 25))
plt <- rp.t_test(x ~ g)
plt + ggplot2::ggtitle("Two-sample inference")

## End(Not run)

rpanel documentation built on March 12, 2026, 9:07 a.m.

Related to rp.t_test in rpanel...