Title: | Visualize Results of Statistical Hypothesis Tests |
---|---|
Description: | Provides functionality to produce graphs of sampling distributions of test statistics from a variety of common statistical tests. With only a few keystrokes, the user can conduct a hypothesis test and visualize the test statistic and corresponding p-value through the shading of its sampling distribution. Initially created for statistics at Middlebury College. |
Authors: | Michael Czekanski [aut, cre], Alex Lyford [aut] |
Maintainer: | Michael Czekanski <[email protected]> |
License: | GPL-3 |
Version: | 0.1.3 |
Built: | 2024-11-08 04:43:20 UTC |
Source: | https://github.com/mczek/mcstats |
Boostrap using given data and statistic
bootstrap(fun, data, h0, nreps, conf.level = 0.95, verbose = 1)
bootstrap(fun, data, h0, nreps, conf.level = 0.95, verbose = 1)
fun |
function to calculate on each sample. This can be a user-defined function that takes in data as a vector and returns a statistic. |
data |
data to use for bootstrapping. Should be a respresentative sample |
h0 |
null hypothesis value |
nreps |
number of times to bootstrap |
conf.level |
confidence value |
verbose |
default is 1 which will create a graph. To turn this off use verbose = 0. |
results from boostrapping. A vector of length @param nreps containing each statistic calculated
x <- rnorm(100) bootstrap(mean, x, 0.5, 1000, verbose = 0) bootstrap(mean, x, 0.5, 1000)
x <- rnorm(100) bootstrap(mean, x, 0.5, 1000, verbose = 0) bootstrap(mean, x, 0.5, 1000)
print "hello world!"
hello()
hello()
hello()
hello()
labels bootstrapped results. We use this to create colored histograms.
labelBootResults(results, lBound, uBound)
labelBootResults(results, lBound, uBound)
results |
a vector, data from bootstrapping |
lBound |
lower bound of confidence interval |
uBound |
upper bound of confidence interval |
vector of labels corresponding to result values
x <- rnorm(100) labelBootResults(x, -1, 1)
x <- rnorm(100) labelBootResults(x, -1, 1)
labels a discrete pdf
labelPDFDis(x, obsVal, expVal)
labelPDFDis(x, obsVal, expVal)
x |
x value |
obsVal |
observed event |
expVal |
expected value |
vector of labels for x value in relation to observed event
labelPDFDis(0:10, 3, 5)
labelPDFDis(0:10, 3, 5)
Density of Chi-Square distribution
mcDChiSq(x, degFree, ...)
mcDChiSq(x, degFree, ...)
x |
x value |
degFree |
degrees of freedom |
... |
optional additional parameters which are ignored |
density of given Chi-Square dist. at x
Density of F-distribution
mcDF(x, degFree1, degFree2, ...)
mcDF(x, degFree1, degFree2, ...)
x |
x value |
degFree1 |
degrees of freedom 1 |
degFree2 |
degrees of freedom 2 |
... |
optional additional parameters which are ignored |
density of given F-dist. at x
compute density of normal distribution while allowing for more arguments which are ignored
mcDNorm(x, mean = 0, sd = 1, log = FALSE, ...)
mcDNorm(x, mean = 0, sd = 1, log = FALSE, ...)
x |
x value |
mean |
mean of normal distribution |
sd |
std. dev. of noraml distribution |
log |
logical; if TRUE probabilities are given as log(p). See stats::dnorm |
... |
extra parameters which are ignored |
density of normal distribution
Density of t-distribution
mcDT(x, degFree, ...)
mcDT(x, degFree, ...)
x |
x value |
degFree |
degrees of freedom |
... |
optional additional parameters which are ignored |
density of given t-dist. at x
Returns density with extreme event region having NAs
shadePDFCts(x, fun, testStat, ...)
shadePDFCts(x, fun, testStat, ...)
x |
x value |
fun |
density function to use |
testStat |
test statistic value |
... |
optional parameters passed to density function |
density if outside of extreme event region
Visualization of distributional results of ANOVA. Please see aov for more information on parameters
showANOVA(formula, data = NULL, verbose = 1, ...)
showANOVA(formula, data = NULL, verbose = 1, ...)
formula |
formula specifying a model. |
data |
data on which to perform ANOVA |
verbose |
if verbose > 0 the resulting graph is printed |
... |
Arguments passed to lm. See aov for more detail |
output of call to aov
showANOVA(yield ~ N + P + K, npk)
showANOVA(yield ~ N + P + K, npk)
show results of a chi-square test visually using chisq.test
showChiSq.Test( x, y = NULL, p = rep(1/length(x), length(x)), simulate.p.value = FALSE, nreps = 2000, verbose = 1 )
showChiSq.Test( x, y = NULL, p = rep(1/length(x), length(x)), simulate.p.value = FALSE, nreps = 2000, verbose = 1 )
x |
a numeric vector or matrix. x and can also be factors |
y |
a numeric vector |
p |
a vector of proabilities the same length as x. Used for goodness-of-fit tests. Must be a valid distribution |
simulate.p.value |
boolean, if TRUE use simulation to estimate p-value |
nreps |
if simulate.p.value = TRUE number of simulations to complete |
verbose |
level of visual output, 0 = silent |
results of chisq.test call
showChiSq.Test(x = c(1,2,1), y= c(1,2,2))
showChiSq.Test(x = c(1,2,1), y= c(1,2,2))
relevant parameters are passed to mcnemar.test
showMcNemarTest(x, y = NULL, correct = TRUE, verbose = 1)
showMcNemarTest(x, y = NULL, correct = TRUE, verbose = 1)
x |
two dimensional contingency table as a matrix or a factor object |
y |
factor object, ignored if x is a matrix |
correct |
logical indicating whether or not to perform continuity correction |
verbose |
if verbose > 0 the resulting graph is printed |
results of call to mcnemar.test
Mosaic Plot
showMosaicPlot(x)
showMosaicPlot(x)
x |
must be a matrix with each row and column labelled |
mosaic plot showing observed proportions, colored by residuals from chi-sq. test
x <- matrix(runif(9,5,100), ncol = 3, dimnames = list(c("Yes1", "No1", "Maybe1"), c("Yes2", "No2", "Maybe2"))) showMosaicPlot(x)
x <- matrix(runif(9,5,100), ncol = 3, dimnames = list(c("Yes1", "No1", "Maybe1"), c("Yes2", "No2", "Maybe2"))) showMosaicPlot(x)
Show hypothesis tests from OLS
showOLS(formula, data, verbose = 1)
showOLS(formula, data, verbose = 1)
formula |
forumula for regression. Passed to lm |
data |
data for regression. Passed to lm |
verbose |
if verbose > 0 the resulting graph is printed |
model object resulting from the regression
showOLS(mpg ~ cyl + disp, mtcars)
showOLS(mpg ~ cyl + disp, mtcars)
Show results of proportion test using binom.test
showProp.Test(x, n, p = 0.5)
showProp.Test(x, n, p = 0.5)
x |
x value |
n |
number of repetitions |
p |
probability of success in one Bernoulli trial |
output of call to binom.test
showProp.Test(3, 10)
showProp.Test(3, 10)
Runs z-test and outputs graph for interpretation using stats::t.test
showT.Test( group1, group2 = NULL, mu = 0, paired = FALSE, conf.level = 0.9, verbose = 1 )
showT.Test( group1, group2 = NULL, mu = 0, paired = FALSE, conf.level = 0.9, verbose = 1 )
group1 |
continuous data to test |
group2 |
optional: second group to include for two sample t-test |
mu |
optional: mean to test against for one-sample t-test |
paired |
boolean, if TRUE perform matched pairs t-test |
conf.level |
confidence level - passed to t.test |
verbose |
default is 1 which will create a graph. To turn this off use verbose = 0. |
results of call to t.test
x <- rnorm(100) showT.Test(x, verbose = 0) showT.Test(x)
x <- rnorm(100) showT.Test(x, verbose = 0) showT.Test(x)
Make graph highlighting events more extreme than observed sample
showXtremeEventsCts( testID, testStat, densFun, degFree = NULL, degFree1 = NULL, degFree2 = NULL, xlims, verbose = 1, ... )
showXtremeEventsCts( testID, testStat, densFun, degFree = NULL, degFree1 = NULL, degFree2 = NULL, xlims, verbose = 1, ... )
testID |
name of hypothesis test |
testStat |
test statistic |
densFun |
function that computes appropriate density |
degFree |
degrees of freedom when only one is needed. This gets passed into densFun |
degFree1 |
first degrees of freedom parameter when more than one is needed |
degFree2 |
second degrees of freedom parameter when more than one is needed |
xlims |
x limits of the graph to be used. This is passed to ggplot |
verbose |
if verbose > 0 the resulting graph is printed |
... |
extra arguments passed to density function |
results of call testFun
x <- rnorm(100) showT.Test(x, verbose = 0) showT.Test(x)
x <- rnorm(100) showT.Test(x, verbose = 0) showT.Test(x)
Show Extreme Events from a Discrete Distribution
showXtremeEventsDis(testID, obsVal, expVal, xVals, probFun, ...)
showXtremeEventsDis(testID, obsVal, expVal, xVals, probFun, ...)
testID |
name of test being performed. This is used to title the graph |
obsVal |
observed x value |
expVal |
expected x value |
xVals |
domain of x (possible values) |
probFun |
probability mass function for the given distribution |
... |
addition arguments passed to probFun |
graph coloring events by how extreme they are under the null hypothesis
showXtremeEventsDis("Prop. Test", 3, 5, 0:10, probFun = dbinom, size = 10, prob = 0.5)
showXtremeEventsDis("Prop. Test", 3, 5, 0:10, probFun = dbinom, size = 10, prob = 0.5)