Saturday, October 27, 2007

Comparing endpoints

x <- rnorm(15,1,1)
y <- rnorm(15,1.2,1.5)

summary(x); summary(y)

fivenum(x); fivenum(y)

boxplot(x, y)

var.test(x, y)

# Test for Zero Correlation
cor.test(x, y, alternative = c("two.sided", "less", "greater"),
method = c("pearson", "kendall", "spearman"),
exact = NULL, conf.level = 0.95, ...)

# Bartlett Test for Homogeneity of Variances
bartlett.test(x, g)

# F Test to Compare Two Variances
var.test(x, y, ratio = 1, alternative = c("two.sided", "less", "greater"), conf.level = 0.95, ...)

# t-test
t.test(x, y = NULL, alternative = c("two.sided", "less", "greater"), mu = 0,
paired = FALSE, var.equal = FALSE, conf.level = 0.95, ...)

ex1) t.test(x, y)
ex2) t.test(x, y, var.equal=T)
ex3) t.test(x, y, paired=T) # paired t-test
ex4) t.test(x, y, alternative="less") # one-sided
ex5) t.test(x, mu=1) # H0: E(x) = 1

# Wilcoxon test
wilcox.test(x, y = NULL, alternative = c("two.sided", "less", "greater"), mu = 0, paired = FALSE, exact = NULL, correct = TRUE, conf.int = FALSE, conf.level =0.95, ...)

ex1) wilcox.test(x, y) # Mann-Whitney test
ex2) wilcox.test(x, y, paired = T) # Wilcoxon Signed Rank Sum test

# two-sample Kolmogrov-Smirnov test
ks.test(x, y)

# Friedman rank sum test with unreplicated blocked data
friedman.test(y, groups, blocks)

# Kruskal-Wallis rank sum test (one-way anova)
kruskal.test(x, g)

# Mood's two-sample test for a difference in scale parameters
mood.test(x, y, alternative = c("two.sided", "less", "greater"), ...)

# Ansari-Bradley two-sample test for a difference in scale parameters
ansari.test(x, y, alternative = c("two.sided", "less", "greater"),
exact = NULL, conf.int = FALSE, conf.level = 0.95, ...)

### Normality Test

#Shapiro-Wilk test of normality
shapiro.test(x)

No comments: