plotttest {nhstplot}R Documentation

Illustrate a one- or two-tailed t test graphically.

Description

This function plots the density probability distribution of a t statistic, with appropriate vertical cutlines at the t value. The p-value and the observed t value are plotted. Although largely customizable, only two arguments are required (the observed t statistic and the degrees of freedom) for a two-tailed t test. The optional argument tails = "one" plots a one-tailed test plot (the tail is on the left or right, depending on the sign of the t statistic).

Usage

plotttest(
  t,
  df = t$parameter,
  tails = "two",
  blank = FALSE,
  xmax = "auto",
  title = "t Test",
  xlabel = "t",
  ylabel = "Density of probability\nunder the null hypothesis",
  fontfamily = "serif",
  colormiddle = "aliceblue",
  colorsides = "firebrick3",
  colormiddlecurve = "black",
  colorsidescurve = "black",
  colorcut = "black",
  colorplabel = colorsides,
  theme = "default",
  signifdigitst = 3,
  curvelinesize = 0.4,
  cutlinesize = curvelinesize,
  p_value_position = "auto"
)

Arguments

t

A numeric value indicating the observed t statistic. Alternatively, you can pass an object of class htest created by the function t.test() or cor.test().

df

A numeric value indicating the degrees of freedom. This argument is optional if you are using an htest object as the t argument.

tails

A character that indicates whether to plot a one ("one") or two ("two") tailed t-test (optional). By default, a two-tailed test is plotted.

blank

A logical that indicates whether to hide (blank = TRUE) the test statistic value, p value and cutline. The corresponding colors are actually only made transparent when blank = TRUE, so that the output is scaled exactly the same (this is useful and especially intended for step-by-step explanations).

xmax

A numeric including the maximum for the x-axis. Defaults to "auto", which scales the plot automatically (optional).

title

A character or expression indicating a custom title for the plot (optional).

xlabel

A character or expression indicating a custom title for the x axis (optional).

ylabel

A character or expression indicating a custom title for the y axis (optional).

fontfamily

A character indicating the font family of all the titles and labels (e.g. "serif" (default), "sans", "Helvetica", "Palatino", etc.) (optional).

colormiddle

A character indicating the color for the "middle" area under the curve (optional).

colorsides

A character indicating the color for the "side(s)" area(s) under the curve (optional).

colormiddlecurve

A character indicating the color for the "middle" part of the curve (optional).

colorsidescurve

A character indicating the color for the "side(s)" part of the curve (optional).

colorcut

A character indicating the color for the cut line at the observed test statistic (optional).

colorplabel

A character indicating the color for the label of the p-value (optional). By default, for color consistency, this color is the same as color of colorright.

theme

A character indicating one of the predefined color themes. The themes are "default" (light blue and red), "blackandwhite", "whiteandred", "blueandred", "greenandred" and "goldandblue") (optional). Supersedes colormiddle and colorsides if another argument than "default" is provided.

signifdigitst

A numeric indicating the number of desired significant figures reported for the t label (optional).

curvelinesize

A numeric indicating the size of the curve line (optional).

cutlinesize

A numeric indicating the size of the cut line(s) (optional). By default, the size of the curve line is used.

p_value_position

A numeric vector of length 2, indicating the x and y coordinates of the p-value label. By default, the position is set to "auto". Note that the absolute value is used, and the sign is ignored. The position is set to the right if the test statistic value is positive, to the left if the test statistic value is negative, and on both sides if a two tailed test is plotted.

Value

A plot with the density of probability of t under the null hypothesis, annotated with the observed test statistic and the p-value.

Author(s)

Nils Myszkowski <nmyszkowski@pace.edu>

Examples

#Making a t test plot with a t value of 2 and df of 10
plotttest(t = 2, df = 10)

#The same plot without the t or p value
plotttest(2,10, blank = TRUE)

#Plotting a one-tailed test using the "tails" parameter.
plotttest(t = 2, df = 10, tails = "one")

#Using t.test() as an input
test <- t.test(rnorm(10), rnorm(10))
plotttest(test)

#Using cor.test() as an input
test <- cor.test(rnorm(10), rnorm(10))
plotttest(test)


[Package nhstplot version 1.3.0 Index]