{{ message }}

Instantly share code, notes, and snippets.

# Kristoffer Magnusson rpsychologist

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