And here are three files (pdf, Mathematica notebook (nb) (if you have Mathematica), and a supposedly interactive Mathematica file (cdf)) showing how one might convince Mathematica to use calculus to solve the least squares problem. here for nb, here for cdf, here for pdf.
The source for both handouts is (for now without my comments) here.
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)
Confidence intervals summarize many hypothesis tests, at least,
approximately (or exactly if they arise from direct inversion of the hypothesis tests themselves). Confidence intervals also encourage us to make limits or boundaries on what kinds of hypotheses ought to be understood as plausible (in contrast with $p$-values, where we have only a continuous measure of discordance between the observations and the hypothesis.
The source code (without my comments) for work in class is here. Using the source code may make cutting and pasting code easier. Plus it allows you to see what Sweave is like.
Today we move from description to begin to engage with statistical
inference (not causal inference). When I say “statistical inference” I
refer to procedures like hypothesis tests and the creation of
confidence intervals (or the creation of posterior distributions or
functions thereof).
So today we dealt with the idea of “fitting”, and thus, with the idea of an objective function that we minimized. We played with three different such functions: least squares, least absolute deviations, and lasso-penalized least squares.
Soon we will be talking about fitting models and then about testing hypotheses. Yet, we will always return to the topic of description throughout the course. Description, after all, is most important. Description tells the story.