Skip to content

Instantly share code, notes, and snippets.

@shv38339
Last active June 30, 2017 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shv38339/b47a8d796d9b5fa0a9a6667e990414fc to your computer and use it in GitHub Desktop.
Save shv38339/b47a8d796d9b5fa0a9a6667e990414fc to your computer and use it in GitHub Desktop.
Statistical Testing in R including groupings in dplyr
# ANOVA testing by group
data %>%
group_by(your_group) %>%
do(tidy(aov(y ~ factor(x), data = .))) %>%
select(your_group, p.value)
# CHISQUARE testing by group
data %>%
group_by(your_group) %>%
summarise(pvalue = chisq.test(x, y)$p.value) %>%
mutate(pvalue = ifelse(pvalue > 0.001, sprintf("%.3f", pvalue), ">.001"))
# TRENDS testing for repeated measures
library(lmer)
library(lmerTest)
mod1 <- lmer(y ~ group*time + (1|group_id), data = your_data, REML = FALSE)
# note that time here is categorical.
# for continuous time, please do not use this model
# note that group and group_id are not the same
# group_id is the repeated measure id
# group_ids will be a subset of the 2 or more groups
anova(mod1)
# output should say:
# "Analysis of Variance Table of type III w/ Satterthwaite..."
# extract p-value from interaction term
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment