% This is a simple LaTex sample document that gives a submission format
%   for IEEE PAMI-TC conference submissions.  Use at your own risk.
% Make two column format for LaTex 2e.\
\documentclass[11pt,twocolumn]{article} %,twocolumn
\usepackage{times,amsmath,amsfonts}

% Use following instead for LaTex 2.09 (may need some other mods as well).
%\documentstyle[times,twocolumn]{article}
\usepackage[dvips]{graphicx,graphics}
% Set dimensions of columns, gap between columns, and paragraph indent
\setlength{\textheight}{10in} \setlength{\textwidth}{7in}
%\setlength{\columnsep}{0.3125in} \setlength{\topmargin}{0in}
\setlength{\headheight}{0in} \setlength{\headsep}{-1in}
\setlength{\parindent}{1pc}
\setlength{\oddsidemargin}{-.5in}  % Centers text.
\setlength{\evensidemargin}{-.5in}

% Add the period after section numbers.  Adjust spacing.
\newcommand{\Section}[1]{\vspace{-8pt}\section{\hskip -1em.~~#1}\vspace{-3pt}}
\newcommand{\SubSection}[1]{\vspace{-3pt}\subsection{\hskip -1em.~~#1}
        \vspace{-3pt}}
\newcommand{\bqn}{\begin{eqnarray}}
\newcommand{\eqn}{\end{eqnarray}}
\newcommand {\diff}[1] {\frac{\partial}{\partial #1}}
\newcommand{\jacob}[3]{\frac{\partial^2 #3}{\partial #1 \partial #2}}
\newcommand{\der}[2]{\frac{\partial #2}{\partial #1}}
\begin{document}

% Make title bold and 14 pt font (Latex default is non-bold, 16pt)
\title{Stat 471: Lecture 17\\
Bootstrap III: Regression}
% For single author (just remove % characters)
\author{Moo K. Chung\\
mchung@stat.wisc.edu}
% For two authors (default example)
\maketitle \thispagestyle{empty}
\begin{enumerate} 
\item Continuing lecture 16, if $f$ is not normal, $T$ will be still a pivot but we do not know its distribution. So we generate 1000 bootstrap replicates of $T^* = \frac{\bar X^* - \bar X}{S^*/\sqrt{n}}$ of $T$ and get the bootstrap CI
$$\Big(\bar x - t_{1-\alpha/2}^*S/\sqrt{n} , \bar x - t_{\alpha/2}^*S/\sqrt{n}\Big).$$
\begin{verbatim}
t=inline('(mean(x)-u)/(std(x)/
length(x))','x','u')
for i=1:1000;
  trep(i)=t(boot(arm,1),mean(arm))
end;
>> quantile(trep,[0.05 0.95])
  -19.8246   22.0677
\end{verbatim}


\item For given bivariate data $(x_i,y_i), i=1, \cots, n$ suppose we have model
$$Y_i = g(x_i; \beta) + \epsilon_i.$$
Let $g(x; \beta) = \beta_0 + \beta_1 x$. Fitting a somewhat crazy model like 
$g(x; \beta) = \frac{\beta_0}{\beta_1 - \beta_2 e^{-\beta_3 x}}$ is also possible. The least squares estimation (LSE) is given by
$$\hat \beta = \arg \min_{\beta} \sum_{i=1}^n \Big(y_i - g(x_i; \beta)\Big)^2$$

Based on LSE, the observed residual is
\bqn \hat \epsilon_i = y_i - g(x_i; \hat \beta). \label{eq:res}\eqn
A bootstrap dataset is then
\bqn Y_i^* = g(x_i; \hat \beta) + \epsilon_i^*. \label{eq:bs}\eqn
The bootstrap estimate of $\beta$ is then
\bqn \hat \beta^* = \arg \min_{\beta} \sum_{i=1}^n \Big(y_i^* - g(x_i; \beta)\Big)^2. \eqn

\item Let's find CI for $\beta_1$ for model 
$$\tt{grip} = \beta_0 + \beta_1 \tt{arm}.$$
 The pivot for $\beta_1$ is $T = \frac{\hat \beta_1 - \beta_1}{SE{\hat \beta_1}}$, where $SE \hat \beta_1$ = \sqrt{{\bf Var} \hat \beta_1}$. If you don't know the standard error $SE$, we estimate it, i.e. $T=(\hat \beta_1 - \beta_1)/S_{\hat \beta_1}$. Following eq.1,2 and 3 we generate 1000 bootstrap replicates of $T^*=\frac{\hat \beta_1^* - \hat \beta}{SE \hat \beta_1^*}$. We need to estimate $SE \hat \beta_1^*$ via bootstrap which requires bootstrapping from bootstrapped residual $e_i^*$ (there is a formula for computing the standard error but well let's forget that). Then $100(1-\alpha)\%$ CI for $\beta_1$ is
$$(\hat \beta_1 - t^*_{1-\alpha/2} S_{\hat \beta_1},\; \hat \beta_1 - t^*_{\alpha/2} S_{\hat \beta_1}). $$
\begin{verbatim}
beta=inline('pinv([ones(147,1) x])*y')
>>b=beta(arm,grip)
b=
   54.7081  
   0.7050
e=grip-b(1)-b(2)*arm;
for j=1:1000
  bse=boot(e,1);
  bsgrip = bse + b(1) + b(2)*arm;
  bsb=beta(arm,bsgrip);
  for i=1:50
     bs2e=boot(bse,1);
     bs2grip = bs2e + b(1) + b(2)*arm;
     bs2b=beta(arm,bs2grip);
     bsbeta(i)=bs2b(2);
  end;
  trep(j)=(bsb(2)-0.7050)/std(bsbeta);
end;
>>quantile(trep,[0.05 0.95])
-1.5308    1.6580
\end{verbatim}
\end{document}

