% 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 16\\
Bootstrap II.}
% 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 Based on our repeated sampling, 
\begin{verbatim}
boot=inline('x(unidrnd( length(x),
m,length(x)))','x','m');
\end{verbatim}
let us estimate
$$\mathbb{E} \; \hat \theta({\bf X}) \approx \bar \theta^*=\sum_{i=1}^m \hat \theta({\bf X}^{*i})/m$$
$${\bf Var} \; \hat \theta({\bf X}) \approx \sum_{i=1}^m \Big(\hat \theta ({\bf X}^{*i}) -
\bar \theta^*\Big)^2/(m-1)$$
from $\tt{strength.data}$ based on 200 bootstrap replications. For population mean,
we use $\hat \theta({\bf X})=\bar X$.For population variance, we
use $\hat \theta({\bf X}) = \sqrt{n}\bar X$.
\begin{verbatim}
bs=boot(arm,200); %200x147 matrix
bsmean=mean(bs,2)
>>[mean(arm) mean(bsmean)]
   78.7517   78.9025
%MATLAB built-in function
>>mean(bootstrp(200,'mean',arm))
   78.7799
%For matrices, var(X) is a row
%vector containing the variance
%of each column.
>>[var(arm) 147*var(bsmean)]
  445.6040   423.0257
\end{verbatim}
\item ${\bf Var} \hat \theta ({\bf X})$ measures the performance of a bootstrap estimate. To measure the accuracy of an estimate, we compute the {\em bias}, which is 
defined as the difference between the expection of the estimator and the true parameter,
$${\bf bias}(\hat \theta ) = \mathbb{E} \hat \theta - \theta.$$
The bootstrap estimation of of the bias is given by 
$${\bf bias}^*(\hat \theta) = \bar \theta^* - \hat \theta.$$ 
Read textbook or Efron (1982) for further detail. For our example $\hat \theta=\bar X$,
$${\bf bias}^*(\bar X) = \bar X^* - \bar X.$$
\begin{verbatim}
>>78.9025-78.7517
0.1508
\end{verbatim}
\item Suppose $X \sim \frac{1}{\sigma}f(\frac{x-\mu}{\sigma})$.      
 We want to find $100(1-\alpha) \%$
  confidence interval (CI) for $\mu$. It depends on finding a pivot of $\mu$. A pivot is a statistic that contains $\mu$ but whose distribution does not depends on $\mu$ or $\sigma$. 
 In the case $f \sim N(\mu,\sigma^2)$, $T=\frac{\bar X - \mu}{S/\sqrt{n}} \sim t_{n-1}$ is a pivot for $\mu$. Let $t_{\alpha/2}$ and $t_{1-\alpha/2}$ be $\alpha/2$ and $1 - \alpha/2}$ quantiles for $t_{n-1}$ distribution. Then the $95\%$ CI is
$$\Big(\bar x - t_{1-\alpha/2}S/\sqrt{n} , \bar x - t_{\alpha/2}S/\sqrt{n}\Big).$$


If $f$ is not normal, $T$ will be still a pivot but we do not know its distribution. So we generate 1000 bootstrap repliates of $T^* = \frac{\bar X^* - \bar X}{S^*/\sqrt{n}}$ of $T$ and get the bootstap 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
>> mean(arm) -22.0677*std(arm)/sqrt(147)
   40.3303
>> mean(arm) +19.8246*std(arm)/sqrt(147)
  113.2677   
\end{verbatim}
\end{document}
