Skip to content

Instantly share code, notes, and snippets.

View rpsychologist's full-sized avatar

Kristoffer Magnusson rpsychologist

View GitHub Profile
@rpsychologist
rpsychologist / anova.pwr.mixed.r
Last active June 22, 2020 04:14
Analytical power analysis for mixed design ANOVA
# function ---------------------------------------------------------------
anova.pwr.mixed <- function(data, Formula, n, m, rho, n.needed=FALSE) {
require(stringr)
Formula <- formula(paste(Formula, "+Error(group)")) # aov formula
x <- summary(aov(Formula, data)) # aov model
terms <- c(rownames(x[[1]][[1]]), rownames(x[[2]][[1]])) # terms in model
terms <- str_pad(terms, max(nchar(terms)), "right") # fix typography
pwr <- function(n) {
k <- length(unique(study$group)) # n groups
@rpsychologist
rpsychologist / anova.pwr.mixed.sim.r
Created May 21, 2013 10:35
Power simulation for mixed design ANOVA
require(mvtnorm)
# function --------------------------------------------------------------------
anova.pwr.mixed.sim <- function(data, Formula, FactorA, n, rho, sims) {
Formula <- formula(Formula) # convert to formula
m <- nlevels(data$time) # number of time points
k <- nlevels(data[[FactorA]]) # number of groups
if(length(n) == 1) n <- rep(n, k) # n for each level of 'group'
n2 <- rep(n, each=m) # n for each cell
n_index <- cumsum(n) # help-variable used when creating subjects factor
subjects <- NULL
library("RCurl")
library("XML")
library("plyr")
library("ggplot2")
library("directlabels")
########################
# Download PubMed Data #
########################