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". When, there are two samples, it does the test under different assumptions such as the whether the variances are equal or not.
> x_c(-1.7,-1.3,-5.0,0.2,6.0,1.5,2.3, 2.7)
> t.test(x, y=NULL, alternative="two.sided", mu=0)
One-sample t-Test
data: x
t = 0.4988, df = 7, p-value = 0.6332
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-2.197641 3.372641
sample estimates:
mean of x
0.5875
> y_c(12,4,5,12,6,7,2,3,4, 5,2)
> t.test(x, y, alternative="two.sided", mu=2)
Standard Two-Sample t-Test
data: x and y
t = -4.4202, df = 17, p-value = 0.0004
alternative hypothesis: true difference in means is not equal to 2
95 percent confidence interval:
-8.413395 -1.684332
sample estimates:
mean of x mean of y
0.5875 5.636364
> t.test(x, y, alternative="two.sided", mu=2,var.equal=F)
Welch Modified Two-Sample t-Test
data: x and y
t = -4.4569, df = 15.679, p-value = 0.0004
alternative hypothesis: true difference in means is not equal to 2
95 percent confidence interval:
-8.407220 -1.690507
sample estimates:
mean of x mean of y
0.5875 5.636364
var.test(x, y, alternative="two.sided", conf.level=.95) performs an F test to compare variances of two samples from normal populations.
> var.test(x, y, alternative="two.sided")
F test for variance equality
data: x and y
F = 0.9057, num df = 7, denom df = 10, p-value = 0.9235
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.22929 4.31193
sample estimates:
variance of x variance of y
11.09839 12.25455
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)
For example,
> binom.test(40,100, p=0.45, alternative="two.sided") Exact binomial test data: 40 out of 100 number of successes = 40, n = 100, p-value = 0.3658 alternative hypothesis: true p is not equal to 0.45Since, in the asymptotic tests, we use normal approximations, the levels are only approximations. For example, the following program finds the levels of a test of proportions for n=20 and p=0.05,0.10, ... ,0.90,0.95
p_c(1:19)/20
z.alpha_qnorm(0.95)
n_20
level_1
for (i in 1:19)
{
x.alpha_(n*p[i]+z.alpha*sqrt(p[i]*(1-p[i])*n))
level[i]_(1-pbinom(x.alpha,size=n,prob=p[i]))
}
p.levels_cbind(p,level)
p.levels
p level
[1,] 0.05 0.07548367
[2,] 0.10 0.04317450
[3,] 0.15 0.06730797
[4,] 0.20 0.08669251
[5,] 0.25 0.04092517
[6,] 0.30 0.04796190
[7,] 0.35 0.05316661
[8,] 0.40 0.05652637
[9,] 0.45 0.05803410
[10,] 0.50 0.05765915
[11,] 0.55 0.05533419
[12,] 0.60 0.05095195
[13,] 0.65 0.04437560
[14,] 0.70 0.03548313
[15,] 0.75 0.02431262
[16,] 0.80 0.06917529
[17,] 0.85 0.03875953
[18,] 0.90 0.00000000
[19,] 0.95 0.00000000