\documentclass[]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
\else % if luatex or xelatex
  \ifxetex
    \usepackage{mathspec}
  \else
    \usepackage{fontspec}
  \fi
  \defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\fi
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage[margin=1in]{geometry}
\usepackage{hyperref}
\hypersetup{unicode=true,
            pdftitle={Homework 07 Solutions},
            pdfborder={0 0 0},
            breaklinks=true}
\urlstyle{same}  % don't use monospace font for urls
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\usepackage{longtable,booktabs}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{0}
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi

%%% Use protect on footnotes to avoid problems with footnotes in titles
\let\rmarkdownfootnote\footnote%
\def\footnote{\protect\rmarkdownfootnote}

%%% Change title format to be more compact
\usepackage{titling}

% Create subtitle command for use in maketitle
\newcommand{\subtitle}[1]{
  \posttitle{
    \begin{center}\large#1\end{center}
    }
}

\setlength{\droptitle}{-2em}

  \title{Homework 07 Solutions}
    \pretitle{\vspace{\droptitle}\centering\huge}
  \posttitle{\par}
    \author{}
    \preauthor{}\postauthor{}
      \predate{\centering\large\emph}
  \postdate{\par}
    \date{11/09/2018}

\usepackage{amsmath}
\usepackage{amsthm}
\DeclareMathOperator{\Cov}{Cov}
\DeclareMathOperator{\Corr}{Corr}

\begin{document}
\maketitle

\section{1.}\label{section}

\subsection{(a).}\label{a.}

Summaries and diagnostic plots for both models are below. Since the
variance of a Poisson random variable is equal to the mean, the raw
residual plot and scale-location plot are not very informative, so we
will focus on the other two diagnostic plots.

For model1, the model with no interaction term, the residuals appear to
be approximately normally distributed (Figure \ref{f:1a_diagnostic1}).
All the points have relatively high leverage, and points 5, 9, and 24
have been labeled as influential points that be worth investigating
further. Many of these points have standardized Pearson residuals with
absolute values between 2 and 4, so there are appear to be a lot of
outliers. The binned residual plot doesn't give any particular cause for
concern (Figure \ref{f:1a_binned1}).

For model2, the model with the interaction term, the residuals also
appear to be approximately normally distributed (Figure
\ref{f:1a_diagnostic2}). Leverage is not shown directly on the leverage
plot in this case, since R has chosen to plot the factors of the
\texttt{Wool} variable on the x-axis instead, but there are no points
that are marked as influential. There are still a lot of points that
look like outliers, with very large standardized Pearson residual
values. The binned residual plot now has values very close to 0, though
all the values are slightly negative.

\textbf{Summary of Model 1 with no interaction:}

\begin{longtable}[]{@{}ccccc@{}}
\toprule
\begin{minipage}[b]{0.21\columnwidth}\centering\strut
~\strut
\end{minipage} & \begin{minipage}[b]{0.13\columnwidth}\centering\strut
Estimate\strut
\end{minipage} & \begin{minipage}[b]{0.16\columnwidth}\centering\strut
Std. Error\strut
\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\centering\strut
z value\strut
\end{minipage} & \begin{minipage}[b]{0.13\columnwidth}\centering\strut
Pr(\textgreater{}\textbar{}z\textbar{})\strut
\end{minipage}\tabularnewline
\midrule
\endhead
\begin{minipage}[t]{0.21\columnwidth}\centering\strut
\textbf{(Intercept)}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
3.692\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.04541\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
81.3\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.21\columnwidth}\centering\strut
\textbf{woolB}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.206\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.05157\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
-3.994\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.0000649\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.21\columnwidth}\centering\strut
\textbf{tensionM}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.3213\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.06027\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
-5.332\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
9.729e-08\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.21\columnwidth}\centering\strut
\textbf{tensionH}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.5185\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.06396\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
-8.107\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
5.209e-16\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

(Dispersion parameter for poisson family taken to be 1 )

\begin{longtable}[]{@{}cc@{}}
\toprule
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
Null deviance:\strut
\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\centering\strut
297.4 on 53 degrees of freedom\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
Residual deviance:\strut
\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\centering\strut
210.4 on 50 degrees of freedom\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

\begin{figure}
\centering
\includegraphics{hw07_solutions_files/figure-latex/1a_plot1-1.pdf}
\caption{Problem 1(a): Diagnostic plots for model without interaction
term.\label{f:1a_diagnostic1}}
\end{figure}

\begin{figure}
\centering
\includegraphics{hw07_solutions_files/figure-latex/1a_binnedplot1-1.pdf}
\caption{Problem 1(a): Binned plot of residuals vs.~fitted values for
model without interaction term.\label{f:1a_binned1}}
\end{figure}

\textbf{Summary of Model 2 with interaction term:}

\begin{longtable}[]{@{}ccccc@{}}
\toprule
\begin{minipage}[b]{0.25\columnwidth}\centering\strut
~\strut
\end{minipage} & \begin{minipage}[b]{0.13\columnwidth}\centering\strut
Estimate\strut
\end{minipage} & \begin{minipage}[b]{0.16\columnwidth}\centering\strut
Std. Error\strut
\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\centering\strut
z value\strut
\end{minipage} & \begin{minipage}[b]{0.13\columnwidth}\centering\strut
Pr(\textgreater{}\textbar{}z\textbar{})\strut
\end{minipage}\tabularnewline
\midrule
\endhead
\begin{minipage}[t]{0.25\columnwidth}\centering\strut
\textbf{(Intercept)}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
3.797\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.04994\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
76.03\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.25\columnwidth}\centering\strut
\textbf{woolB}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.4566\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.08019\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
-5.694\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
1.24e-08\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.25\columnwidth}\centering\strut
\textbf{tensionM}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.6187\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.0844\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
-7.33\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
2.295e-13\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.25\columnwidth}\centering\strut
\textbf{tensionH}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.5958\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.08378\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
-7.112\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
1.146e-12\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.25\columnwidth}\centering\strut
\textbf{woolB:tensionM}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.6382\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.1222\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
5.224\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
1.747e-07\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.25\columnwidth}\centering\strut
\textbf{woolB:tensionH}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.1884\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.1299\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
1.45\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.147\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

(Dispersion parameter for poisson family taken to be 1 )

\begin{longtable}[]{@{}cc@{}}
\toprule
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
Null deviance:\strut
\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\centering\strut
297.4 on 53 degrees of freedom\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
Residual deviance:\strut
\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\centering\strut
182.3 on 48 degrees of freedom\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

\begin{figure}
\centering
\includegraphics{hw07_solutions_files/figure-latex/1a_plot2-1.pdf}
\caption{Problem 1(a): Diagnostic plots for model with interaction
term.\label{f:1a_diagnostic2}}
\end{figure}

\begin{figure}
\centering
\includegraphics{hw07_solutions_files/figure-latex/1a_binnedplot2-1.pdf}
\caption{Problem 1(a): Binned plot of residuals vs.~fitted values for
model with interaction term.\label{1a_binned2}}
\end{figure}

\subsection{(b) i.}\label{b-i.}

The AICs and BICs are as follows:

\begin{longtable}[]{@{}lrr@{}}
\toprule
& AIC & BIC\tabularnewline
\midrule
\endhead
Model 1 (without interaction) & 493 & 501\tabularnewline
Model 2 (with interaction) & 469 & 481\tabularnewline
\bottomrule
\end{longtable}

Both metrics are lower for model 2, so that is the model we would
choose.

\subsection{(b) ii.}\label{b-ii.}

The log likelihoods are -243 for model 1 without the interaction and
-228 for model 2 with the interaction. The difference in degrees of
freedom is 2. This comes from the fact that the variable \texttt{wool}
has two levels, which corresponds to a single dummy variable, and the
variable \texttt{tension} has three levels, which corresponds to two
dummy variables. The interaction between them therefore corresponds to
\texttt{2\ x\ 1\ =\ 2} dummy variables.

We therefore compare the statistic \(-2(-243-(-228)) = 28\) to a
\(\chi_{(2)}^2\) distribution. The pvalue is \(7.96\times 10^{-7}\), so
we reject the null hypothesis and decide to include the interaction. The
likelihood ratio test therefore selects the same model as the AIC and
BIC.

\subsection{(c)}\label{c}

The Pearson residuals are \[
    r_i = \frac{y_i - \hat{y}_i}{\sqrt{\hat{y}_i}}
\] If the model is correctly specified, then \(\sum_{i=1}^n r_i\) should
have approximately a \(\chi_{n-(p+1)^2}\) distribution.

We have \(\sum_{i=1}^n r_i = 180.67\). Comparing this to a \(\chi^2\)
distribution with \(48\) degrees of freedom yields a p-value of
\(2.93\times 10^{-17}\). We conclude therefore that the residuals are
overdispersed, meaning that the variability of the responses is larger
than what we would expect if they really followed a conditional Poisson
distribution.

\subsection{(d)}\label{d}

\textbf{Summary of Model 3, the quasipoisson model:}

\begin{longtable}[]{@{}ccccc@{}}
\toprule
\begin{minipage}[b]{0.25\columnwidth}\centering\strut
~\strut
\end{minipage} & \begin{minipage}[b]{0.13\columnwidth}\centering\strut
Estimate\strut
\end{minipage} & \begin{minipage}[b]{0.16\columnwidth}\centering\strut
Std. Error\strut
\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\centering\strut
t value\strut
\end{minipage} & \begin{minipage}[b]{0.13\columnwidth}\centering\strut
Pr(\textgreater{}\textbar{}t\textbar{})\strut
\end{minipage}\tabularnewline
\midrule
\endhead
\begin{minipage}[t]{0.25\columnwidth}\centering\strut
\textbf{(Intercept)}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
3.797\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.09688\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
39.19\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
4.193e-38\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.25\columnwidth}\centering\strut
\textbf{woolB}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.4566\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.1556\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
-2.935\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.005105\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.25\columnwidth}\centering\strut
\textbf{tensionM}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.6187\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.1637\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
-3.778\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.0004359\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.25\columnwidth}\centering\strut
\textbf{tensionH}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.5958\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.1625\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
-3.666\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.000616\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.25\columnwidth}\centering\strut
\textbf{woolB:tensionM}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.6382\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.237\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
2.693\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.009727\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.25\columnwidth}\centering\strut
\textbf{woolB:tensionH}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.1884\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.252\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
0.7475\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.4584\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

(Dispersion parameter for quasipoisson family taken to be 3.8 )

\begin{longtable}[]{@{}cc@{}}
\toprule
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
Null deviance:\strut
\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\centering\strut
297.4 on 53 degrees of freedom\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
Residual deviance:\strut
\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\centering\strut
182.3 on 48 degrees of freedom\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

The coefficient estimates are identical to those in Model 2, but the
estimated standard errors are much larger, as expected. Consequently,
the p-values are larger, though still significant at customary
thresholds like 0.05 or 0.01. The dispersion parameter is estimated to
be 3.8, whereas it was assumed to be 1 in Model 2.

\section{2(a)}\label{a}

A summary of the model is below. Diagnostic plots are in Figure
\ref{f:2a_diagnostic}, and the estimated autocorrelation between the
residuals is plotted in Figure \ref{f:2a_acf}.

The residuals are very roughly normally distributed, but they appear to
show an increasing trend relative to the fitted values. The
scale-location plot also appears to show that the variance is increasing
with fitted values, and the autocorrelation plot shows large
autocorrelations, all of which suggest that the linear model with
assumed independence between the residuals is not appropriate.

\begin{longtable}[]{@{}ccccc@{}}
\toprule
\begin{minipage}[b]{0.21\columnwidth}\centering\strut
~\strut
\end{minipage} & \begin{minipage}[b]{0.13\columnwidth}\centering\strut
Estimate\strut
\end{minipage} & \begin{minipage}[b]{0.16\columnwidth}\centering\strut
Std. Error\strut
\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\centering\strut
t value\strut
\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\centering\strut
Pr(\textgreater{}\textbar{}t\textbar{})\strut
\end{minipage}\tabularnewline
\midrule
\endhead
\begin{minipage}[t]{0.21\columnwidth}\centering\strut
\textbf{(Intercept)}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
4421\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
1235\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
3.58\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
0.00336\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.21\columnwidth}\centering\strut
\textbf{Temp}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
78.18\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
33.89\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
2.307\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
0.03817\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.21\columnwidth}\centering\strut
\textbf{Sun}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
2.585\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
1.556\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
1.661\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
0.1206\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.21\columnwidth}\centering\strut
\textbf{Q2}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-879.7\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
1121\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
-0.7845\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
0.4468\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.21\columnwidth}\centering\strut
\textbf{Q3}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-1552\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
1541\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
-1.007\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
0.3323\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.21\columnwidth}\centering\strut
\textbf{Q4}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
715.4\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
474.3\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
1.508\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
0.1554\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

\begin{longtable}[]{@{}cccc@{}}
\caption{Problem 2a: Summary of ordinary linear model.}\tabularnewline
\toprule
\begin{minipage}[b]{0.18\columnwidth}\centering\strut
Observations\strut
\end{minipage} & \begin{minipage}[b]{0.27\columnwidth}\centering\strut
Residual Std. Error\strut
\end{minipage} & \begin{minipage}[b]{0.11\columnwidth}\centering\strut
\(R^2\)\strut
\end{minipage} & \begin{minipage}[b]{0.20\columnwidth}\centering\strut
Adjusted \(R^2\)\strut
\end{minipage}\tabularnewline
\midrule
\endfirsthead
\toprule
\begin{minipage}[b]{0.18\columnwidth}\centering\strut
Observations\strut
\end{minipage} & \begin{minipage}[b]{0.27\columnwidth}\centering\strut
Residual Std. Error\strut
\end{minipage} & \begin{minipage}[b]{0.11\columnwidth}\centering\strut
\(R^2\)\strut
\end{minipage} & \begin{minipage}[b]{0.20\columnwidth}\centering\strut
Adjusted \(R^2\)\strut
\end{minipage}\tabularnewline
\midrule
\endhead
\begin{minipage}[t]{0.18\columnwidth}\centering\strut
19\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering\strut
287.2\strut
\end{minipage} & \begin{minipage}[t]{0.11\columnwidth}\centering\strut
0.9537\strut
\end{minipage} & \begin{minipage}[t]{0.20\columnwidth}\centering\strut
0.9359\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

\begin{figure}
\centering
\includegraphics{hw07_solutions_files/figure-latex/2a_diagnostic-1.pdf}
\caption{Problem 2a: Diagnostic plots for ordinary linear
model.\label{f:2a_diagnostic}}
\end{figure}

\begin{figure}

{\centering \includegraphics{hw07_solutions_files/figure-latex/2a_acf-1} 

}

\caption{Problem 2a: acf plot for ordinary linear model residuals.\label{f:2a_acf}}\label{fig:2a_acf}
\end{figure}

\pagebreak

\section{2(b)}\label{b}

Note that the model can be estimated with either Maximum Likelihood (ML)
or Restricted Maximum Likelihood (REML). I have used the default, which
is REML, but either one is fine. They will produce different estimates.
The code should look like one of the following:

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{model <-}\StringTok{ }\KeywordTok{gls}\NormalTok{(Sales }\OperatorTok{~}\StringTok{ }\NormalTok{. }\OperatorTok{-}\NormalTok{Case }\OperatorTok{-}\StringTok{ }\NormalTok{Time, }\DataTypeTok{data=}\NormalTok{carlsen, }\DataTypeTok{correlation=}\KeywordTok{corAR1}\NormalTok{())}
\NormalTok{model <-}\StringTok{ }\KeywordTok{gls}\NormalTok{(Sales }\OperatorTok{~}\StringTok{ }\NormalTok{. }\OperatorTok{-}\NormalTok{Case }\OperatorTok{-}\StringTok{ }\NormalTok{Time, }\DataTypeTok{data=}\NormalTok{carlsen, }\DataTypeTok{correlation=}\KeywordTok{corAR1}\NormalTok{(),}
             \DataTypeTok{method =} \StringTok{"ML"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{enumerate}
\def\labelenumi{\roman{enumi}.}
\item
  A summary of this model is below. From this summary, the estimated
  value of \(\rho\), the lag-1 autocorrelation parameter, is 0.87. (If
  you use ML for estimation, the estimate is 0.79).
\item
  The coefficient values have changed in magnitude, though not in sign.
  The estimated standard errors in the AR1 model are much smaller than
  in the ordinary linear model, which is to be expected if the model is
  properly accounting for correlation among the residuals. As a result,
  both \texttt{Sun} and \texttt{Q4} are significant in the AR1 model but
  not in the ordinary linear model at conventional thresholds.
\end{enumerate}

\begin{verbatim}
## Problem 2b: Summary of AR1 model:
\end{verbatim}

\begin{verbatim}
## Generalized least squares fit by REML
##   Model: Sales ~ . - Case - Time 
##   Data: carlsen 
##   AIC BIC logLik
##   213 217    -98
## 
## Correlation Structure: AR(1)
##  Formula: ~1 
##  Parameter estimate(s):
##  Phi 
## 0.87 
## 
## Coefficients:
##             Value Std.Error t-value p-value
## (Intercept)  5215       747     7.0  0.0000
## Temp           56        23     2.4  0.0300
## Sun             2         1     2.8  0.0148
## Q2            -36       663    -0.1  0.9572
## Q3           -371       942    -0.4  0.6999
## Q4            946       295     3.2  0.0069
## 
##  Correlation: 
##      (Intr) Temp   Sun    Q2     Q3    
## Temp -0.870                            
## Sun   0.005 -0.357                     
## Q2    0.914 -0.938  0.033              
## Q3    0.912 -0.960  0.100  0.992       
## Q4    0.747 -0.937  0.485  0.840  0.876
## 
## Standardized residuals:
##   Min    Q1   Med    Q3   Max 
## -1.18 -0.29  0.50  0.57  1.13 
## 
## Residual standard error: 409 
## Degrees of freedom: 19 total; 13 residual
\end{verbatim}

\section{2(c)}\label{c-1}

The log likelihoods are -131 for the ordinary linear model and -98 for
the AR1 mode. The difference in degrees of freedom is 1, so we compare
the statistic \(-2(-131-(-98)) = 66\) to a \(\chi_{(1)}^2\)
distribution. The pvalue is \(8.08\times 10^{-16}\), so we reject the
null hypothesis and conclude that the autocorrelation is not 0.

\section{2(d)}\label{d-1}

A summary of the model is below. Diagnostic plots are in Figure
\ref{f:2d_diagnostic}, and the autocorrelation plot of the residuals is
in Figure \ref{f:2d_acf}.

The diagnostic plots suggest problems with the fit. The residuals are
not very close to normally distributed, and the scale-location plot
appears to show a relationship between the fitted values and the
variance. The autocorrelation plot, however, shows much reduced
autocorrelation among the residuals, as hoped for.

The likelihood of the model is \texttt{-130}, as compared to
\texttt{-98} for the model in 2c. It appears to be more effective to
estimate the autocorrelation simultaneously with estimating the model,
as in 2c, rather than following a two-stage estimation procedure.

\begin{longtable}[]{@{}ccccc@{}}
\toprule
\begin{minipage}[b]{0.27\columnwidth}\centering\strut
~\strut
\end{minipage} & \begin{minipage}[b]{0.13\columnwidth}\centering\strut
Estimate\strut
\end{minipage} & \begin{minipage}[b]{0.16\columnwidth}\centering\strut
Std. Error\strut
\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\centering\strut
t value\strut
\end{minipage} & \begin{minipage}[b]{0.13\columnwidth}\centering\strut
Pr(\textgreater{}\textbar{}t\textbar{})\strut
\end{minipage}\tabularnewline
\midrule
\endhead
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
\textbf{Xstar(Intercept)}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
5090\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
793.5\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
6.415\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.0000229\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
\textbf{XstarTemp}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
61.01\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
24.64\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
2.476\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.02781\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
\textbf{XstarSun}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
2.196\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.8827\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
2.488\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.02722\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
\textbf{XstarQ2}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-214.5\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
725.8\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
-0.2956\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.7722\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
\textbf{XstarQ3}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-631.1\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
1026\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
-0.6148\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.5493\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
\textbf{XstarQ4}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
879.1\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
322.7\strut
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\centering\strut
2.724\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.01738\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

\begin{longtable}[]{@{}cccc@{}}
\caption{Problem 2d: Summary of ordinary linear model with transformed
variables.}\tabularnewline
\toprule
\begin{minipage}[b]{0.18\columnwidth}\centering\strut
Observations\strut
\end{minipage} & \begin{minipage}[b]{0.27\columnwidth}\centering\strut
Residual Std. Error\strut
\end{minipage} & \begin{minipage}[b]{0.11\columnwidth}\centering\strut
\(R^2\)\strut
\end{minipage} & \begin{minipage}[b]{0.20\columnwidth}\centering\strut
Adjusted \(R^2\)\strut
\end{minipage}\tabularnewline
\midrule
\endfirsthead
\toprule
\begin{minipage}[b]{0.18\columnwidth}\centering\strut
Observations\strut
\end{minipage} & \begin{minipage}[b]{0.27\columnwidth}\centering\strut
Residual Std. Error\strut
\end{minipage} & \begin{minipage}[b]{0.11\columnwidth}\centering\strut
\(R^2\)\strut
\end{minipage} & \begin{minipage}[b]{0.20\columnwidth}\centering\strut
Adjusted \(R^2\)\strut
\end{minipage}\tabularnewline
\midrule
\endhead
\begin{minipage}[t]{0.18\columnwidth}\centering\strut
19\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering\strut
277.7\strut
\end{minipage} & \begin{minipage}[t]{0.11\columnwidth}\centering\strut
0.9979\strut
\end{minipage} & \begin{minipage}[t]{0.20\columnwidth}\centering\strut
0.9969\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

\begin{figure}
\centering
\includegraphics{hw07_solutions_files/figure-latex/2d_diagnostics-1.pdf}
\caption{Problem 2d: diagnostic plots.\label{f:2d_diagnostic}}
\end{figure}

\begin{figure}
\centering
\includegraphics{hw07_solutions_files/figure-latex/2d_acf-1.pdf}
\caption{Problem 2d: acf plot for ordinary linear model
residuals.\label{f:2d_acf}}
\end{figure}

\section{3.}\label{section-1}

\begin{enumerate}
\def\labelenumi{(\alph{enumi})}
\tightlist
\item
  The treatment variable is no longer randomized in the way intended by
  the researcher, because individuals have selected their own level of
  treatment. This selection process is very likely confounded with the
  outcome variable, meaning that there is some unobserved variable that
  is correlated with both the treatment variable and the outcome.
\end{enumerate}

For example, imagine that the therapy actually has no effect, but there
is an ``optimism'' variable that determines both how many sessions a
person attends and their emotional state at the end of the study. In
other words, the people who engage the most with the treatment are those
in the best state at the end of the study, but not because of the
therapy. Then the number of sessions attended will strongly predict the
outcome variable, but not because of an effect of the therapy.

An unobserved confounder could also obscure a real treatment effect.
Suppose that instead of an optimism variable, there is a variable
representing emotional wellbeing that is inversely correlated with the
number of sessions attended. That is, those who start out the most
depressed seek the most treatment, perhaps because they feel that they
have the most to gain. Suppose the treatment \emph{does} have a
beneficial effect that increases with the number of sessions attended,
and suppose that everyone seeks out just enough treatment to get them to
roughly the same level of emotional wellbeing at the end of the study.
Then a coefficient for number of treatment sessions could end up being 0
even though there is a treatment effect!

\emph{In sum:} whenever there is noncompliance in an experiment, there
is potential for confounding due to selection effects. Including a
variable for the amount of treatment received \emph{does not} address
this and can lead to highly misleading results.

\section{3(b)}\label{b-1}

This is perfectly set up for an Instrumental Variable analysis. The
assignment variable (assignment to treatment or control) is the
instrument, and the number of sessions attended is the treatment
variable. The assignment variable almost certainly affects the treatment
variable, but it should have no effect on the outcome through other
pathways. (That is, the mere fact of having been assigned to the
treatment or control group shouldn't affect participants' emotional
wellbeing at the end of the study.) An experimental design with
noncompliance is almost always a good candidate for an IV analysis.

An analysis based on propensity score matching won't work here unless we
have variables with which to construct the propensity score. The
propensity score is the probability of receiving treatment as a function
of some set of covariates \(X\). That is, the propensity score is a
function \(\pi(x) := P(A = 1|X = x)\), where \(A = 1\) means that
someone receives treatment. We can define it more broadly as the
probability of receiving a particular amount of treatment \(a\):
\(\pi_a(x) = P(A = a|X= x)\). We want as rich a set of covariates \(X\)
as possible in order to perform matching. If the investigator collected
these prior to the start of the study, then this analysis may be
possible.


\end{document}
