plot.htest: Plots test statistic and p-value area for z-, t-, and...

Description Usage Arguments Details Value Note See Also Examples

View source: R/testsPostHoc-utils.R

Description

Plots test statistic and p-value area for z-, t-, and chi-square tests.

Usage

1
2
## S3 method for class 'htest'
plot(x, smoothness = 1000, shade.col = "red", shade.col2 = "red3", ...)

Arguments

x

an object saved from z.test, t.test, or chisq.test

smoothness

a single-length numeric indicating the number of points for which to construct the plot. The larger the number the smoother the plot will appear

shade.col

a string indicating the color to use for the (primary) shaded area. If the alternative is two.sided then this area is in the same tail as the test statistic

shade.col2

a string indicating the color to use for the (secondary) shaded area. If the alternative is two.sided then this area is in the opposite tail as the test statistic

...

optional arguments that are not implemented in this version

Details

This produces a plot of the named sampling distribution with the test statistic and p-value areas shown. This plot is used primarily for students to visualize the calcualtion of the p-value in the z.test, t.test, and chisq.test functions. The results from those functions must be saved to an object.

Value

None. However, a plot is constructed.

Note

Newbie students can benefit greatly from visualizing the position of the test statistic and the “area” of the p-value for common statistical tests using the z-, t-, and chi-square tests. This function produces a graphic from the results of z.test, t.test, and chisq.test to show these values. An additional benefit of this function is that newbie students make fewer mistakes in choosing the alternative hypothesis when they can visualize the final result.

See Also

z.test, t.test, and chisq.test.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## 1-sample z-test example 
z.ex <- z.test(rnorm(25,100,5),99,5)
z.ex
plot(z.ex)

## 1-sample t-test example from t.test
t1.ex <- t.test(1:10,y=c(7:20))
t1.ex
plot(t1.ex)

## 2-sample t-test example from t.test
t2.ex <- t.test(extra~group,data=sleep)
t2.ex
plot(t2.ex)

## same but with one-tailed alternative (for illustration)
t3.ex <- t.test(extra~group,data=sleep,alt="less")
t3.ex
plot(t3.ex)

## Chi-square test example from chisq.test
chi1.ex <- chisq.test(InsectSprays$count > 7, InsectSprays$spray)
chi1.ex
plot(chi1.ex)

## Another Chi-square test example from chisq.test
x <- matrix(c(12, 5, 7, 7), ncol = 2)
chi2.ex <- chisq.test(x)
chi2.ex
plot(chi2.ex)

## Another Chi-square test example from chisq.test
x <- c(89,37,30,28,2)
p <- c(40,20,20,15,5)
chi3.ex <- chisq.test(x, p = p, rescale.p = TRUE)
chi3.ex
plot(chi3.ex)

droglenc/NCStats documentation built on June 5, 2021, 2:06 p.m.