Skip to content

Commit

Permalink
Merge branch 'master' of github.com:deaneckles/multiway_bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Eckles committed Jul 18, 2013
2 parents 26ba704 + a26e2df commit 57babcf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions multiway_boot_ex.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
source("multiway_boot.R")

# In this example, we have two grouping factors, subjects and stimuli

# Generate simulated data
N <- 1e4
N.subjects <- 100
N.stimuli <- 20
Expand All @@ -10,6 +12,7 @@ subject <- rep(1:100, each = 100)
stimuli.re <- rlnorm(N.stimuli)
stimulus <- sample.int(N.stimuli, N, replace = TRUE)

# x has subject, stimulus, and subject-stimulus (error) components
x <- subjects.re[subject] + stimuli.re[stimulus] + rnorm(N)

# point estimate of mean
Expand All @@ -25,15 +28,15 @@ mb.2 <- multiway.boot(
statistic = wtd.mean,
R = 500,
groups = cbind(subject, stimulus),
.progress = 'text',
.progress = 'text', # can use plyr progress indicators
x = x
)
mb.2 <- unlist(mb.2)
sd(mb.2) # bootstrap estimate of standard error of the mean
qnorm(q, mean(x), sd(mb.2)) # normal approximation
quantile(mb.2, q) # percentile bootstrap CI

# setup multicore
# setup multicore for demonstration of parallel execution
library(foreach)
library(doMC)

Expand All @@ -44,7 +47,7 @@ mb.1 <- multiway.boot(
statistic = wtd.mean,
R = 500,
groups = cbind(subject), # only cluster/block on subject
.parallel = TRUE, # requires foreach and doMC libraries
.parallel = TRUE, # can use plyr parallel tools
x = x
)
mb.1 <- unlist(mb.1)
Expand Down

0 comments on commit 57babcf

Please sign in to comment.