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(RItools) | |
library(optmatch) | |
set.seed(20130801) | |
n <- 500 | |
library(MASS) | |
xs <- mvrnorm(n, | |
mu = c(1,2,3), | |
Sigma = matrix(c(1, 0.5, 0.2, | |
0.5, 1, 0, |
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(optmatch) | |
example(match_on) | |
#' @param x An ISM or blocked ISM | |
#' @param rs Names of rows to keep | |
#' @param cs Names of columns to keep | |
submatrix <- function(x, rs, cs) { | |
subset(x, | |
x@rownames %in% rs, |
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
module Lady | |
where | |
{-- | |
- The Lady Tasting Tea | |
- | |
- In "Statistical Methods for Research Workers" (1925) Fisher illustrates the basic | |
- ideas of randomization inference in the story of a woman who claims she can | |
- tell the difference between tea in which the milk is added before or after | |
- the water. The experiment consists of a tray of 8 cups of tea, 4 of which |
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
gsize <- function(n) { | |
grid <- expand.grid(rep(list(1:10), n)) | |
object.size(grid) / 1024 | |
} | |
fsize <- function(n) { | |
f <- function(i) {force(i) ; function(j) { i + j}} | |
flst <- lapply(1:(10^n), f) | |
object.size(flst) / 1024 | |
} |
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(RItools) | |
# set up the potential outcomes, n = 20 | |
Yc <- rnorm(20) | |
Yt <- Yc + 1 # additive effect of 2 | |
# "randomly" sample 1/2 of the data, this works because we know how Yc is created | |
Z <- rep(c(T,F), 10) | |
R <- ifelse(Z, Yt, Yc) |
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
(defn data->maps "Turns a vector of vectors into a seq of maps" | |
[keys data] | |
(map #(zipmap keys %) data)) | |
(defn data-merge | |
"Merge two data sets on the given key" | |
[merge-key a b] | |
(let [indexed-b (zipmap (map merge-key b) b)] | |
(map #(into % (indexed-b (merge-key %))) (filter #(contains? indexed-b (merge-key %)) a)))) | |