Title: | Plot Null Hypothesis Significance Tests |
---|---|
Description: | Illustrate graphically the most common Null Hypothesis Significance Testing procedures. More specifically, this package provides functions to plot Chi-Squared, F, t (one- and two-tailed) and z (one- and two-tailed) tests, by plotting the probability density under the null hypothesis as a function of the different test statistic values. Although highly flexible (color theme, fonts, etc.), only the minimal number of arguments (observed test statistic, degrees of freedom) are necessary for a clear and useful graph to be plotted, with the observed test statistic and the p value, as well as their corresponding value labels. The axes are automatically scaled to present the relevant part and the overall shape of the probability density function. This package is especially intended for education purposes, as it provides a helpful support to help explain the Null Hypothesis Significance Testing process, its use and/or shortcomings. |
Authors: | Nils Myszkowski [aut, cre] |
Maintainer: | Nils Myszkowski <[email protected]> |
License: | GPL-3 |
Version: | 1.3.0 |
Built: | 2024-10-30 04:45:35 UTC |
Source: | https://github.com/cran/nhstplot |
test graphically.This function plots the density probability distribution of a statistic, with a vertical cutline at the observed
value specified. The p-value and the observed
value are plotted. Although largely customizable, only two arguments are required (the observed
and the degrees of freedom).
plotchisqtest( chisq, df = chisq$parameter, blank = FALSE, xmax = "auto", title = parse(text = expression(chi^2 ~ "Test")), xlabel = parse(text = expression(chi^2)), ylabel = "Density of probability\nunder the null hypothesis", fontfamily = "serif", colorleft = "aliceblue", colorright = "firebrick3", colorleftcurve = "black", colorrightcurve = "black", colorcut = "black", colorplabel = colorright, theme = "default", signifdigitschisq = 3, curvelinesize = 0.4, cutlinesize = curvelinesize, p_value_position = "auto" )
plotchisqtest( chisq, df = chisq$parameter, blank = FALSE, xmax = "auto", title = parse(text = expression(chi^2 ~ "Test")), xlabel = parse(text = expression(chi^2)), ylabel = "Density of probability\nunder the null hypothesis", fontfamily = "serif", colorleft = "aliceblue", colorright = "firebrick3", colorleftcurve = "black", colorrightcurve = "black", colorcut = "black", colorplabel = colorright, theme = "default", signifdigitschisq = 3, curvelinesize = 0.4, cutlinesize = curvelinesize, p_value_position = "auto" )
chisq |
A numeric value indicating the observed |
df |
A numeric value indicating the degrees of freedom. This argument is optional if you are using an |
blank |
A logical that indicates whether to hide ( |
xmax |
A numeric including the maximum for the x-axis. Defaults to |
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. |
colorleft |
A character indicating the color for the "left" area under the curve (optional). |
colorright |
A character indicating the color for the "right" area under the curve (optional). |
colorleftcurve |
A character indicating the color for the "left" part of the curve (optional). |
colorrightcurve |
A character indicating the color for the "right" part of the curve (optional). By default, for color consistency, this color is also passed to the label, but this can be changed by providing an argument for the |
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 |
theme |
A character indicating one of the predefined color themes. The themes are |
signifdigitschisq |
A numeric indicating the number of desired significant figures reported for the |
curvelinesize |
A numeric indicating the size of the curve line (optional). |
cutlinesize |
A numeric indicating the size of the cut line (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 |
A plot with the density of probability of under the null hypothesis, annotated with the observed test statistic and the p-value.
Nils Myszkowski <[email protected]>
#Making a chi-squared plot with Chi-squared of 8 and df of 4 plotchisqtest(chisq = 8, df = 4) #The same plot without the Chi-Squared or p value plotchisqtest(8,4, blank = TRUE) #Plot using a chisq.test() test <- chisq.test(c(A = 37, B = 18, C = 25)) plotchisqtest(test) #Plot from anova() model comparison set.seed(1) y <- rbinom(10, 1, .4) ; x <- 2*y + rnorm(10) fit1 <- glm(y ~ 1, family = binomial) fit2 <- glm(y ~ x, family = binomial) comp <- anova(fit1, fit2, test = "Chisq") plotchisqtest(comp)
#Making a chi-squared plot with Chi-squared of 8 and df of 4 plotchisqtest(chisq = 8, df = 4) #The same plot without the Chi-Squared or p value plotchisqtest(8,4, blank = TRUE) #Plot using a chisq.test() test <- chisq.test(c(A = 37, B = 18, C = 25)) plotchisqtest(test) #Plot from anova() model comparison set.seed(1) y <- rbinom(10, 1, .4) ; x <- 2*y + rnorm(10) fit1 <- glm(y ~ 1, family = binomial) fit2 <- glm(y ~ x, family = binomial) comp <- anova(fit1, fit2, test = "Chisq") plotchisqtest(comp)
This function plots the density probability distribution of an F statistic, with a vertical cutline at the observed F value specified. A p-value and the observed F value are plotted. Although largely customizable, only three arguments are required (the observed F and the degrees of freedom).
plotftest( f, dfnum = f$fstatistic[2], dfdenom = f$fstatistic[3], blank = FALSE, xmax = "auto", title = "F Test", xlabel = "F", ylabel = "Density of probability\nunder the null hypothesis", fontfamily = "serif", colorleft = "aliceblue", colorright = "firebrick3", colorleftcurve = "black", colorrightcurve = "black", colorcut = "black", colorplabel = colorright, theme = "default", signifdigitsf = 3, curvelinesize = 0.4, cutlinesize = curvelinesize, p_value_position = "auto" )
plotftest( f, dfnum = f$fstatistic[2], dfdenom = f$fstatistic[3], blank = FALSE, xmax = "auto", title = "F Test", xlabel = "F", ylabel = "Density of probability\nunder the null hypothesis", fontfamily = "serif", colorleft = "aliceblue", colorright = "firebrick3", colorleftcurve = "black", colorrightcurve = "black", colorcut = "black", colorplabel = colorright, theme = "default", signifdigitsf = 3, curvelinesize = 0.4, cutlinesize = curvelinesize, p_value_position = "auto" )
f |
A numeric value indicating the observed F statistic. Alternatively, you can pass an object of class |
dfnum |
A numeric value indicating the degrees of freedom of the numerator. This argument is optional if you are using an |
dfdenom |
A numeric value indicating the degrees of freedom of the denominator. This argument is optional if you are using an |
blank |
A logical that indicates whether to hide ( |
xmax |
A numeric including the maximum for the x-axis. Defaults to |
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. |
colorleft |
A character indicating the color for the "left" area under the curve (optional). |
colorright |
A character indicating the color for the "right" area under the curve (optional). |
colorleftcurve |
A character indicating the color for the "left" part of the curve (optional). |
colorrightcurve |
A character indicating the color for the "right" part of the curve (optional). By default, for color consistency, this color is also passed to the label, but this can be changed by providing an argument for the |
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 |
theme |
A character indicating one of the predefined color themes. The themes are |
signifdigitsf |
A numeric indicating the number of desired significant figures reported for the F (optional). |
curvelinesize |
A numeric indicating the size of the curve line (optional). |
cutlinesize |
A numeric indicating the size of the cut line (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 |
A plot with the density of probability of F under the null hypothesis, annotated with the observed test statistic and the p-value.
Nils Myszkowski <[email protected]>
#Making an F plot with an F of 3, and degrees of freedom of 1 and 5. plotftest(f = 4, dfnum = 3, dfdenom = 5) #The same plot without the f or p value plotftest(4,3,5, blank = TRUE) #Passing an "lm" object set.seed(1) x <- rnorm(10) ; y <- x + rnorm(10) fit <- lm(y ~ x) plotftest(fit) plotftest(summary(fit)) # also works #Passing an "anova" F-change test set.seed(1) x <- rnorm(10) ; y <- x + rnorm(10) fit1 <- lm(y ~ x) fit2 <- lm(y ~ poly(x, 2)) comp <- anova(fit1, fit2) plotftest(comp)
#Making an F plot with an F of 3, and degrees of freedom of 1 and 5. plotftest(f = 4, dfnum = 3, dfdenom = 5) #The same plot without the f or p value plotftest(4,3,5, blank = TRUE) #Passing an "lm" object set.seed(1) x <- rnorm(10) ; y <- x + rnorm(10) fit <- lm(y ~ x) plotftest(fit) plotftest(summary(fit)) # also works #Passing an "anova" F-change test set.seed(1) x <- rnorm(10) ; y <- x + rnorm(10) fit1 <- lm(y ~ x) fit2 <- lm(y ~ poly(x, 2)) comp <- anova(fit1, fit2) plotftest(comp)
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).
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" )
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" )
t |
A numeric value indicating the observed t statistic. Alternatively, you can pass an object of class |
df |
A numeric value indicating the degrees of freedom. This argument is optional if you are using an |
tails |
A character that indicates whether to plot a one ( |
blank |
A logical that indicates whether to hide ( |
xmax |
A numeric including the maximum for the x-axis. Defaults to |
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. |
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 |
theme |
A character indicating one of the predefined color themes. The themes are |
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 |
A plot with the density of probability of t under the null hypothesis, annotated with the observed test statistic and the p-value.
Nils Myszkowski <[email protected]>
#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)
#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)
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).
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" )
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" )
z |
A numeric value indicating the observed z statistic. |
tails |
A character that indicates whether to plot a one ( |
blank |
A logical that indicates whether to hide ( |
xmax |
A numeric including the maximum for the x-axis. Defaults to |
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. |
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 |
theme |
A character indicating one of the predefined color themes. The themes are |
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 |
Returns a plot with the density of probability of z under the null hypothesis, annotated with the observed z statistic and the p-value.
Nils Myszkowski <[email protected]>
#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")
#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")