knitr::opts_chunk$set(echo = TRUE,comment = NA,fig.width=6,fig.height = 5, fig.align='center',out.width="90%")
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.
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")
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.
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 plot(x)
You can show the distribution of t-statistic and p-value in one sample t-test.
t.test(acs$age,mu=63) plot(t.test(acs$age,mu=63))
Before performing a t-test, you have to compare two variances.
x=var.test(age~DM,data=acs) x plot(x)
Based on the result of var.test(), you can perform t.test with default option(var.equal=FALSE).
x=t.test(age~DM,data=acs) x plot(x)
To compare means of body-mass index between male and female patients, perform F test first.
var.test(BMI~sex,data=acs) plot(var.test(BMI~sex,data=acs))
Based on the result of F test, you can perform t-test using pooled variance.
x=t.test(BMI~sex,data=acs,var.equal=TRUE) x plot(x)
You can show the distribution of t-statistic and p-value in paired t-test.
x=t.test(iris$Sepal.Width,iris$Petal.Width,paired=TRUE) plot(x)
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.