library("modules")
library("lme4")
library("emmeans")
library("pbkrtest")
library("lmerTest")
library("ggplot2")
library("gridExtra")
library("repr")
setwd("~/projects")
lib <- modules::use("./rock-no-rock/src")
dat <- read.csv("./rock-no-rock/data/rock_no_rock_ergo.csv")
lm <- lmer(power ~ factor(condition) + (1 + factor(condition) | subject),
data = dat)
emm <- emmeans(lm, ~condition)
emm
pairs(emm, infer = TRUE)
eff_size(emm, sigma = sigma(lm), edf = 18)
pnorm(1.493)
pnorm(0.264)
pnorm(1.757)
dat$condition <- factor(dat$condition,
labels = c("ad libitum", "Minimal", "Locked"))
by_subject <- aggregate(power ~ subject + condition, mean, data = dat)
p1 <- ggplot(by_subject,
aes(x = factor(condition, c("Locked", "ad libitum", "Minimal")),
y = power, group = subject)) +
geom_point(aes(colour = factor(subject)), size = 2, show.legend = FALSE) +
geom_line(aes(colour = factor(subject)), show.legend = FALSE) +
labs(x = "", y = "Maximal 1 s Power (W)") +
theme(text = element_text(size = 20))
locked <- by_subject$power[by_subject$condition == "Locked"]
adlib <- by_subject$power[by_subject$condition == "ad libitum"]
minimal <- by_subject$power[by_subject$condition == "Minimal"]
a <- (adlib - locked) / locked * 100
b <- (minimal - locked) / locked * 100
c <- (minimal - adlib) / adlib * 100
perc_diff <- as.vector(cbind(a, b, c))
comparison <- c(rep(1, 19), rep(2, 19), rep(3, 19))
m <- as.data.frame(cbind(perc_diff, comparison))
m$comparison <- factor(m$comparison)
p2 <- ggplot(m, aes(x = comparison, y = perc_diff)) +
geom_hline(yintercept = 0) +
geom_violin(trim = FALSE, fill = "darkgray") +
geom_boxplot(width = 0.1) +
labs(x = "", y = "% Difference") +
theme(text = element_text(size = 20)) +
scale_x_discrete(labels =
c("ad libitum\nvs.\nLocked", "Minimal\nvs.\nLocked",
"Minimal\nvs.\nad libitum"))
options(repr.plot.width = 8, repr.plot.height = 5)
p3 <- grid.arrange(p1, p2, nrow = 1)
path <- "./rock-no-rock/results/figures/"
filename <- "rnr_results_power.png"
ggsave(paste(path, filename, sep=""), plot = p3, width = 8, height = 5, units = "in", dpi = 300)