Last active
June 30, 2017 18:24
-
-
Save shv38339/b47a8d796d9b5fa0a9a6667e990414fc to your computer and use it in GitHub Desktop.
Statistical Testing in R including groupings in dplyr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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