# Plot for distribution of common statistics and p-value

#### 2020-01-26

To understand the concept of p value is very important. To teach the the distribution of common statistic( $$\chi^2$$ for chisq.test() , t for Student’s t-test , F for F-test) and concept of the p-value, plot.htest() function can be used.

## Package Installation

You can install this package form the github. Currently, package webr is under construction and consists of only one function - plot.htest().

#install.packages("devtools")
devtools::install_github("cardiomoon/webr")

## Coverage of plot.htest()

The plot.htest() function is a S3 method for class “htest”. Currently, this function covers Welch Two Sample t-test, Pearson’s Chi-squared test, Two Sample t-test, One Sample t-test, Paired t-test and F test to compare two variances.

## For Chi-squared Test

You can show the distribution of chi-squre statistic and p-value.

require(moonBook)
require(webr)

# chi-squared test
x=chisq.test(table(acs$sex,acs$DM))
x

Pearson's Chi-squared test with Yates' continuity correction

data:  table(acs$sex, acs$DM)
X-squared = 3.1296, df = 1, p-value = 0.07688
plot(x)

## For one sample t-test

You can show the distribution of t-statistic and p-value in one sample t-test.

t.test(acs$age,mu=63) One Sample t-test data: acs$age
t = 0.77978, df = 856, p-value = 0.4357
alternative hypothesis: true mean is not equal to 63
95 percent confidence interval:
62.52736 64.09574
sample estimates:
mean of x
63.31155
plot(x)

## Options for t-test

You can change the options of t.test.

x=t.test(BMI~sex, data=acs,conf.level=0.99,alternative="greater",var.equal=TRUE)
plot(x)