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:
12345
install.packages("devtools")library("devtools").libPaths(getwd())# <- installs to the working directory rather than the systeminstall_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:
1234567
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):
123456789101112
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-valuesummary(testH0)## The distribution of the test statistictable(testH0@distribution)