Last active
April 6, 2018 10:42
-
-
Save guoguo12/c1158b03ae4f091b4abe5d79abe7c579 to your computer and use it in GitHub Desktop.
R script for performing ANCOVA with post-hoc tests and showing adjusted group means.
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
# Based on https://stats.stackexchange.com/a/57254 | |
# Before running, look at all comments starting with XXX below | |
library('car') | |
library('compute.es') | |
library('effects') | |
library('emmeans') | |
library('ggplot2') | |
library('multcomp') | |
library('pastecs') | |
library('WRS2') | |
# XXX Update this with the data file location | |
df <- read.csv('C:\\Users\\guogu_000\\Documents\\Research\\R\\data.csv') | |
# XXX Update this with the number of levels for the categorical factor | |
contrasts(df$factor) = contr.sum(2) | |
model = aov(dv ~ factor + covariate + factor:covariate, data=df) | |
# Using 'II' should give more-or-less the same output as statsmodels | |
Anova(model, type='III') | |
posth = glht(model, linfct=mcp(factor='Tukey')) | |
summary(posth) | |
emmeans(model, ~ factor:covariate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment