Groupwise comparison for continuous variables
Load BONEDEN.DAT.txt as bone. Create a difference variable from fn1 and fn2
bone <- read.csv("BONEDEN.DAT.txt", quote = "'")
bone$fn.diff <- bone$fn1 - bone$fn2
One-sample t-test for the difference variable
t.test(bone$fn.diff, mu = 0)
One Sample t-test
data: bone$fn.diff
t = 0.0503, df = 40, p-value = 0.9601
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-0.02866 0.03013
sample estimates:
mean of x
0.0007317
Paired t-test for the variable pair is the same thing
t.test(bone$fn1, bone$fn2, paired = TRUE)
Paired t-test
data: bone$fn1 and bone$fn2
t = 0.0503, df = 40, p-value = 0.9601
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.02866 0.03013
sample estimates:
mean of the differences
0.0007317
Independent two group comparison
t.test(age ~ zyg, data = bone, var.equal = TRUE)
Two Sample t-test
data: age by zyg
t = 1.427, df = 39, p-value = 0.1615
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-2.163 12.525
sample estimates:
mean in group 1 mean in group 2
51.38 46.20
Independent two group comparison using summary data
library(BSDA)
tsum.test(mean.x = 51.38, s.x = 10.74, n.x = 21, mean.y = 46.20, s.y = 12.48, n.y = 20, var.equal = TRUE)
Standard Two-Sample t-Test
data: Summarized x and y
t = 1.427, df = 39, p-value = 0.1616
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-2.164 12.524
sample estimates:
mean of x mean of y
51.38 46.20
To compare variance
var.test(age ~ zyg, data = bone)
F test to compare two variances
data: age by zyg
F = 0.7406, num df = 20, denom df = 19, p-value = 0.5106
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.2952 1.8382
sample estimates:
ratio of variances
0.7406
One-sample Wilcoxon signed rank test (no continuity correction). Symmetry required.
wilcox.test(bone$fn.diff, mu = 0, correct = FALSE)
Wilcoxon signed rank test
data: bone$fn.diff
V = 403.5, p-value = 0.8505
alternative hypothesis: true location is not equal to 0
One-sample Wilcoxon signed rank test (no continuity correction). No assumption of normality or symmetry.
library(BSDA)
SIGN.test(bone$fn.diff, md = 0)
One-sample Sign-Test
data: bone$fn.diff
s = 22, p-value = 0.5224
alternative hypothesis: true median is not equal to 0
95 percent confidence interval:
-0.04 0.04
sample estimates:
median of x
0.02
Conf.Level L.E.pt U.E.pt
Lower Achieved CI 0.9404 -0.04 0.04
Interpolated CI 0.9500 -0.04 0.04
Upper Achieved CI 0.9725 -0.04 0.04
Wilcoxon signed rank test for paired data (no continuity correction)
wilcox.test(bone$fn1, bone$fn2, paired = TRUE, correct = FALSE)
Wilcoxon signed rank test
data: bone$fn1 and bone$fn2
V = 403.5, p-value = 0.8505
alternative hypothesis: true location shift is not equal to 0
Independent two group comparison (Wilcoxon rank sum test)
wilcox.test(age ~ zyg, data = bone, correct = FALSE)
Wilcoxon rank sum test
data: age by zyg
W = 280, p-value = 0.06747
alternative hypothesis: true location shift is not equal to 0
Load BETACAR.DAT.txt as vitA (4-types of beta-carotene supplements and plasma carotene concentration)
vitA <- read.csv("BETACAR.DAT.txt", quote = "'")
Independent three or more group comparison
anova(lm(Base1lvl ~ factor(Prepar), data = vitA))
Analysis of Variance Table
Response: Base1lvl
Df Sum Sq Mean Sq F value Pr(>F)
factor(Prepar) 3 8379 2793 0.73 0.55
Residuals 19 73051 3845
Independent three or more group comparison (distribution-free)
kruskal.test(Base1lvl ~ factor(Prepar), data = vitA)
Kruskal-Wallis rank sum test
data: Base1lvl by factor(Prepar)
Kruskal-Wallis chi-squared = 2.268, df = 3, p-value = 0.5187