Skip to content

Instantly share code, notes, and snippets.

Avatar

Kristoffer Magnusson rpsychologist

View GitHub Profile
@rpsychologist
rpsychologist / anova.pwr.mixed.r
Last active Jun 22, 2020
Analytical power analysis for mixed design ANOVA
View anova.pwr.mixed.r
# 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
Power simulation for mixed design ANOVA
View anova.pwr.mixed.sim.r
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
View PubMedTrend.r
library("RCurl")
library("XML")
library("plyr")
library("ggplot2")
library("directlabels")
########################
# Download PubMed Data #
########################