View simulation-in-R-2016
--- | |
title: "Designing simulation studies in R" | |
author: "James E. Pustejovsky" | |
date: "September 28, 2016" | |
output: | |
ioslides_presentation: | |
css: custom.css | |
widescreen: true | |
transition: faster | |
--- |
View bug-in-nlme::getVarCov.R
# Demonstrate the problem with gls model | |
library(nlme) | |
data(Ovary) | |
gls_raw <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data = Ovary, | |
correlation = corAR1(form = ~ 1 | Mare), | |
weights = varPower()) |
View Fatal crashes by city, 2006-2015
library(tidyr) | |
library(dplyr) | |
library(stringr) | |
library(ggplot2) | |
cities_select <- c("HOUSTON","SAN ANTONIO","DALLAS","AUSTIN","FORT WORTH","EL PASO") | |
#---------------------------------------- | |
# get population estimates | |
#---------------------------------------- |
View Austin crashes - annual data figures
library(tidyr) | |
library(dplyr) | |
library(stringr) | |
library(ggplot2) | |
#-------------------------------- | |
# format the data for graphing | |
#-------------------------------- | |
crash_dat <- read.csv("http://blogs.edb.utexas.edu/pusto/files/2015/08/Yearly_crash_data_Austin_and_Travis_County.csv") |
View metafor-BRL.R
require(Formula) | |
require(metafor) | |
require(sandwich) | |
require(zoo) | |
require(lmtest) | |
#----------------------------------------------- | |
# Identify outer-most clustering variable | |
#----------------------------------------------- |
View metafor-sandwich.R
require(Formula) | |
require(metafor) | |
require(sandwich) | |
require(zoo) | |
require(lmtest) | |
#----------------------------------------------- | |
# Functions for making sandwich standard errors | |
#----------------------------------------------- |
View RVE-hierarchical.R
# robumeta calculations | |
library(grid) | |
library(robumeta) | |
data(hierdat) | |
HTJ <- robu(effectsize ~ males + binge, | |
data = hierdat, modelweights = "HIER", | |
studynum = studyid, | |
var.eff.size = var, small = FALSE) |
View Simulate Welch t-test in parallel
#---------------------------------------------- | |
# data-generating model | |
#---------------------------------------------- | |
two_group_data <- function(iterations, n, p, var_ratio, delta) { | |
Group <- c(rep("C", n * p), rep("T", n * (1 - p))) | |
Y_C <- matrix(rnorm(iterations * n * p, mean = 0, sd = 1), n * p, iterations) | |
Y_T <- matrix(rnorm(iterations * n * (1 - p), mean = delta, sd = sqrt(var_ratio)), n * (1 - p), iterations) | |
dat <- data.frame(Group, rbind(Y_C, Y_T)) | |
return(dat) |
View Simulate Welch t-test
#---------------------------------------------- | |
# data-generating model | |
#---------------------------------------------- | |
two_group_data <- function(iterations, n, p, var_ratio, delta) { | |
Group <- c(rep("C", n * p), rep("T", n * (1 - p))) | |
Y_C <- matrix(rnorm(iterations * n * p, mean = 0, sd = 1), n * p, iterations) | |
Y_T <- matrix(rnorm(iterations * n * (1 - p), mean = delta, sd = sqrt(var_ratio)), n * (1 - p), iterations) | |
dat <- data.frame(Group, rbind(Y_C, Y_T)) | |
return(dat) |