Tests and confidence intervals
We can do z-test, t-test and find confidence intervals for the mean
of a normal distribution and do the elementary statistical inference.
- binom.test(x, n, p=0.5, alternative="two.sided")
Test hypothesises about the parameter p in a Binomial(n,p)
model given x, the number of successes out of n trials.
The argument alternative has 3 options:
"two.sided" (not equal to p), "less" (less than p) or
"greater" (greater than p)
- chisq.test(x, y=NULL, correct=T )
Performs a Pearson's chi-square test on a two-dimensional
contingency table.
-
chisq.gof(x, n.classes=ceiling(2 * (length(x)^(2/5))),
cut.points=NULL, distribution="normal", n.param.est=0, ...)
performs a chi square goodness-of-fit test.
- cor.test(x, y, alternative="two.sided", method="pearson")
tests whether two vectors are uncorrelated using Pearson's product moment
correlation coefficient, Kendall's tau-statistic, or Spearman's rank
correlation. The options of method
are "pearson", "kendall", or "spearman", depending on what
coefficient of correlation should be used in the test statistic.
Only the first character is necessary.
- fisher.test(x, y=NULL, node.stack.dim=1001, value.stack.dim=10000,
hybrid=F)
performs a Fisher's exact test on a two-dimensional contingency table.
- friedman.test(y, groups, blocks)
performs a Friedman rank sum test with unreplicated blocked data.
- kruskal.test(y, groups)
performs a Kruskal-Wallis rank sum test on data following a one-way
layout.
- ks.gof(x, y = NULL, alternative = "two.sided",
distribution = "normal", ...) performs a one or two sample
Kolmogorov-Smirnov test, which tests the relationship between two
distributions.
- mcnemar.test(x, y=NULL, correct=T)
performs a McNemar's chi-square test on a two-dimensional contingency table.
- prop.test(x, n, p=<>, alternative="two.sided",
conf.level=.95, correct=T)
compares proportions against hypothesized values. Alternately,
tests whether underlying proportions are equal.
- t.test(x, y=NULL, alternative="two.sided", mu=0, paired=F,
var.equal=T, conf.level=.95) does the z-test and t-test.
If y is not indicated, we get the one sample case.
The argument alternative has the options: "greater", "less" or "two.sided".
- var.test(x, y, alternative="two.sided", conf.level=.95)
Performs an F test to compare variances of two samples from normal
populations.
- wilcox.test(x, y, alternative="two.sided", mu=0, paired=F, exact=T,
correct=T)
computes Wilcoxon rank sum test for two sample data (equivalent to the
Mann-Whitney test) or the Wilcoxon signed rank test for paired or one
sample data.
For example,
> x
[1] -1.7 -1.3 -5.0 0.2 6.0 1.5 2.3 2.7
> y
[1] 12 34 5 12 6 7 2345 2
> t.test(x,mu=23,var=2)
One-sample t-Test
data: x
t = -19.0285, df = 7, p-value = 0
alternative hypothesis: true mean is not equal to 23
95 percent confidence interval:
-2.197641 3.372641
sample estimates:
mean of x
0.5875
> t.test(x,mu=2,alternative="greater")
One-sample t-Test
data: x
t = -1.1992, df = 7, p-value = 0.8653
alternative hypothesis: true mean is greater than 2
95 percent confidence interval:
-1.644004 NA
sample estimates:
mean of x
0.5875
> t.test(x,mu=10)
One-sample t-Test
data: x
t = -7.9913, df = 7, p-value = 1e-04
alternative hypothesis: true mean is not equal to 10
95 percent confidence interval:
-2.197641 3.372641
sample estimates:
mean of x
0.5875
> t.test(x,y)
Standard Two-Sample t-Test
data: x and y
t = -1.0361, df = 14, p-value = 0.3177
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-928.041 323.466
sample estimates:
mean of x mean of y
0.5875 302.875
> t.test(x,y,var.equal=F)
Welch Modified Two-Sample t-Test
data: x and y
t = -1.0361, df = 7, p-value = 0.3346
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-992.1753 387.6003
sample estimates:
mean of x mean of y
0.5875 302.875
> t.test(x,y,var.equal=T)
Standard Two-Sample t-Test
data: x and y
t = -1.0361, df = 14, p-value = 0.3177
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-928.041 323.466
sample estimates:
mean of x mean of y
0.5875 302.875
> t.test(x,y,paired=T)
Paired t-Test
data: x and y
t = -1.037, df = 7, p-value = 0.3342
alternative hypothesis: true mean of differences is not equal to 0
95 percent confidence interval:
-991.6102 387.0352
sample estimates:
mean of x - y
-302.2875