Learn R Programming

nhstplot (version 1.3.0)

plotztest: Illustrate a one- or two-tailed z test graphically.

Description

This function plots the density probability distribution of a z statistic, with appropriate vertical cutlines at the z value. The p-value and the observed z value are plotted. Although largely customizable, only one argument is required (the observed z statistic) for a two-tailed z 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 z statistic).

Usage

plotztest(
  z,
  tails = "two",
  blank = FALSE,
  xmax = "auto",
  title = "z test",
  xlabel = "z",
  ylabel = "Density of probability\nunder the null hypothesis",
  fontfamily = "serif",
  colormiddle = "aliceblue",
  colorsides = "firebrick3",
  colormiddlecurve = "black",
  colorsidescurve = "black",
  colorcut = "black",
  colorplabel = colorsides,
  theme = "default",
  signifdigitsz = 3,
  curvelinesize = 0.4,
  cutlinesize = curvelinesize,
  p_value_position = "auto"
)

Value

Returns a plot with the density of probability of z under the null hypothesis, annotated with the observed z statistic and the p-value.

Arguments

z

A numeric value indicating the observed z statistic.

tails

A character that indicates whether to plot a one ("one") or two ("two") tailed z-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.

signifdigitsz

A numeric indicating the number of desired significant figures reported for the z 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.

Author

Nils Myszkowski <nmyszkowski@pace.edu>

Examples

Run this code
#Making a z test plot with a z value of 2.
plotztest(2)

#The same plot without the z or p value
plotztest(2, blank = TRUE)

#Plotting a one-tailed test using the "tails" parameter.
plotztest(z = 2, tails = "one")

Run the code above in your browser using DataLab