Skip to content

Instantly share code, notes, and snippets.

@geofferyzh
Created May 23, 2012 19:28
Show Gist options
  • Save geofferyzh/2777245 to your computer and use it in GitHub Desktop.
Save geofferyzh/2777245 to your computer and use it in GitHub Desktop.
RinAction - Nonparametric Test of Group Difference
########################################################
########################################################
# ---- Nonparametric tests of group differences ---- #
########################################################
########################################################
# NOTE:
# When you have more than 2 groups, you can use ANOVA or Nonparametric approaches
# to test group difference. ANOVA assumes data are independently sampled from normal
# populations. If the parametric assumptions are not met, nonparametric method can
# be used.
# Wilcoxon two group comparison
with(UScrime, by(Prob, So, median))
wilcox.test(Prob ~ So, data=UScrime)
sapply(UScrime[c("U1", "U2")], median)
with(UScrime, wilcox.test(U1, U2, paired = TRUE))
# Kruskal Wallis test
states <- as.data.frame(cbind(state.region, state.x77))
kruskal.test(Illiteracy ~ state.region, data=states)
# Nonparametric multiple comparisons
class <- state.region
var <- state.x77[, c("Illiteracy")]
mydata <- as.data.frame(cbind(class, var))
rm(class,var)
library(npmc)
summary(npmc(mydata), type = "BF")
aggregate(mydata, by = list(mydata$class), median)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment