Fleeting

A temporary collection of notes

ITV Experiments Spring 2013: Randomization Inference

| Comments

Today we might use some of the new features of the RItools package for doing randomization inference. We’ll be working with the handout that you completed last term slightly updated here

To get this, as yet in-progress, undocumented, and unreleased version do the following:

1
2
3
4
5
install.packages("devtools")
library("devtools")
.libPaths(getwd()) # <- installs to the working directory rather than the system
install_github("RItools", user = "markmfredrickson", ref = "randomization-distribution")
library("RItools",lib.loc=getwd())

To test a sharp null using this package you can do the following (assuming you’ve loaded the news.df data frame.

First you have to represent the design of the study. We call them ‘samplers’ because ‘random assigners’ or ‘design machines’ seemed strange:

1
2
3
4
5
6
7
paired.assignment.sampler<-simpleRandomSampler(z=news.df$z,
                                               b=news.df$s)
## test it : should have 8 rows, 10 columns, etc..
( ten.experiments<-paired.assignment.sampler(10) )
## Does it do the right thing?
## One test (not the only one):
all(colSums(ten.experiments$samples)==4)

Given the design, we need a hypothesis (here assumed by default to be the sharp null of no effects) and a test statistic (here using the mean difference):

1
2
3
4
5
6
7
8
9
10
11
12
testH0<-RItest(y=news.df$r,
               z=news.df$z,
               test.stat=mean.difference,
               p.value=upper.p.value,
               sampler=paired.assignment.sampler,
               samples=100,
               include.distribution=T)
## The p-value
summary(testH0)

## The distribution of the test statistic
table(testH0@distribution)

Comments