% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\usepackage[margin=1in]{geometry}
\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{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[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{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\usepackage{graphicx}
\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}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same} % disable monospaced font for URLs
\hypersetup{
  pdftitle={Homework 03 Solutions},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}

\title{Homework 03 Solutions}
\author{}
\date{\vspace{-2.5em}2022-09-15}

\begin{document}
\maketitle

\def\red#1{\textcolor{red}{#1}}
\def\blue#1{\textcolor{blue}{#1}}
\let\bar\overline
\let\ul\underline

\frenchspacing

\begin{center}
\Large
36-617: Applied Linear Models\\
Fall 2022\\
Solutions
\end{center}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{library}\NormalTok{(arm)  }\DocumentationTok{\#\# includes lme4, MASS, Matrix}
\FunctionTok{library}\NormalTok{(ggplot2); }\FunctionTok{theme\_set}\NormalTok{(}\FunctionTok{theme\_bw}\NormalTok{())}
\FunctionTok{library}\NormalTok{(gridExtra) }\DocumentationTok{\#\# to arrange ggplots...}
\FunctionTok{library}\NormalTok{(GGally) }\DocumentationTok{\#\# for ggpairs...}
\end{Highlighting}
\end{Shaded}

\hypertarget{problem-1-sheather-ch-3-yes-pp.-109-ff.-5.-cars04.csv}{%
\section{Problem 1: Sheather, Ch 3 (yes!), pp.~109 ff., \#5. \%
cars04.csv}\label{problem-1-sheather-ch-3-yes-pp.-109-ff.-5.-cars04.csv}}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{cars04 }\OtherTok{\textless{}{-}} \FunctionTok{read.csv}\NormalTok{(}\StringTok{"cars04.csv"}\NormalTok{,}\AttributeTok{header=}\NormalTok{T)}
\NormalTok{lm.}\FloatTok{3.10} \OtherTok{\textless{}{-}} \FunctionTok{lm}\NormalTok{(SuggestedRetailPrice }\SpecialCharTok{\textasciitilde{}}\NormalTok{ DealerCost,}\AttributeTok{data=}\NormalTok{cars04)}
\FunctionTok{summary}\NormalTok{(lm.}\FloatTok{3.10}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## 
## Call:
## lm(formula = SuggestedRetailPrice ~ DealerCost, data = cars04)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1743.52  -262.59    74.92   265.98  2912.72 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -61.904248  81.801381  -0.757     0.45    
## DealerCost    1.088841   0.002638 412.768   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 587 on 232 degrees of freedom
## Multiple R-squared:  0.9986, Adjusted R-squared:  0.9986 
## F-statistic: 1.704e+05 on 1 and 232 DF,  p-value: < 2.2e-16
\end{verbatim}

\hypertarget{problem-1a}{%
\subsection{Problem 1(a)}\label{problem-1a}}

Based on the above output for model \verb|lm.3.10|, the analyst
concluded the following: Since the model explains just more than 99.8\%
of the variability in Suggested Retail Price and the coefficient of
Dealer Cost has a \(t\)-value greater than 412, the model \verb|lm.3.10|
is a highly effective model for producing prediction intervals for
Suggested Retail Price.\textbackslash{[}0.6em{]} \% Provide a detailed
critique of this conclusion.

\em

Although the regression output in the summary of model \verb|lm.3.10|
above looks good, there are several volations of the modeling
assumptions revealed in following diagnostic plots:

\begin{center}\includegraphics{hw03-solutions_files/figure-latex/unnamed-chunk-3-1} \end{center}

\begin{itemize}
\item SuggestedRetailPrice, DealerCost and the residuals, are all skewed right
\item The residuals have nonconstant variance
\item The aggregation of the data around different lines in the plot suggests that some predictor variable(s) may be missing from the model
\end{itemize}

Violations of the modeling assumptions undermine the validity of
inferences we can make from the \verb|summary(lm.3.10)| output.

\rm

\hypertarget{problem-1b}{%
\subsection{Problem 1(b)}\label{problem-1b}}

Carefully describe all the shortcomings evident in model \verb|lm.3.10|.
For each shortcoming, describe the steps needed to overcome the
shortcoming.

\em

Here are four possible shortcomings
\rm (you may have found others!  Name any two legitimate criticisms, and ways to fix them, for full credit) \em:

\begin{itemize}

\item The ``SuggestedRetailPrice vs DealerCost'', ``Standardized Residuals vs DealerCost'', and\\ ``Sqrt(|Standardized Residuals|) vs DealerCost'' plots all show that Dealer Cost is substantially right-skewed.  Right skewing tends to create high-leverage points in the data.
A transformation of DealerCost to reduce the skewing would help: usually a fractional power, or a logarithm are good fixes for this.

\item The Normal QQ Plot shows that the residuals are also right-skewed.  The same sort of transformation (log or fractional power) of SuggestedRetailPrice will help to reduce this skewing.

\item Both the Standardized Residuals plot and the ``Sqrt(|Standardized Residuals|) vs DealerCost'' plot show that the residuals have non-constant variance.  You could suggest a variance-stabilizing transformation, or a log or power transformation, to help fix this problem.

\item The Standardized Residual plot shows the data clustering along several different lines, suggesting that perhaps different vehicle types or brands have different relationships between SuggestedRetailPrice and DealerCost.  One could explore this idea by considering an ANCOVA model, which we will talk about in later lectures.

\end{itemize}

\rm

\hypertarget{problem-1c}{%
\subsection{Problem 1(c)}\label{problem-1c}}

Is model \verb|lm.3.11| below an improvement over model \verb|lm.3.10|
in terms of predicting Suggested Retail Price? If so, please describe
all the ways in which it is an improvement.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{lm.}\FloatTok{3.11} \OtherTok{\textless{}{-}} \FunctionTok{lm}\NormalTok{(}\FunctionTok{log}\NormalTok{(SuggestedRetailPrice) }\SpecialCharTok{\textasciitilde{}} \FunctionTok{log}\NormalTok{(DealerCost),}\AttributeTok{data=}\NormalTok{cars04)}
\FunctionTok{summary}\NormalTok{(lm.}\FloatTok{3.11}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## 
## Call:
## lm(formula = log(SuggestedRetailPrice) ~ log(DealerCost), data = cars04)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.062920 -0.008694  0.000624  0.010621  0.048798 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     -0.069459   0.026459  -2.625  0.00924 ** 
## log(DealerCost)  1.014836   0.002616 387.942  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01865 on 232 degrees of freedom
## Multiple R-squared:  0.9985, Adjusted R-squared:  0.9985 
## F-statistic: 1.505e+05 on 1 and 232 DF,  p-value: < 2.2e-16
\end{verbatim}

\em

\verb|lm.3.11| is definitely an improvement over \verb|lm.3.10|. The
regression output for both models is about the same, so the differences
are in diagnostic plots below. Here are some ways in which the plots are
better for \verb|lm.3.11| than for \verb|lm.3.10|
\rm (You may have found other reasons. Name any two legitimate reasons for full credit)\em.

\begin{itemize}

\item Both DealerCost and SuggestedRetailPrice exhibit less right-skewing in \verb|lm.3.11| than in \verb|3.10|.  

\item While there are still outliers in the residual vs fitted plot for \verb|3.11|, they are less extreme than for \verb|3.10|.

\item In addition to less right-skew, the normal QQ plot suggests more nearly-normal residuals for \verb|3.11| than for \verb|3.10|.  We have pushed some values out into the left tail, but there are fewer of these in the QQ plot for \verb|3.11| than there are for \verb|3.10|.

\end{itemize}

\begin{center}\includegraphics{hw03-solutions_files/figure-latex/unnamed-chunk-5-1} \end{center}

\rm

\hypertarget{problem-1d}{%
\subsection{Problem 1(d)}\label{problem-1d}}

Interpret the estimated coefficient of log(Dealer Cost) in
\verb|lm.3.11|.

\em

As we know from the text, or from the handout ``log xform and percent
interpretation.pdf'\,' in the week03 folder in the files area,
\(\beta_1\) is the expected percent change in \(y\) for a 1\% change in
\(x\). Since \(\hat\beta_1=1.015\) in \verb|summary(lm.3.11)|, there is
about a 1\% change in SuggestedRetailPrice for every 1\% change in
DealerCost, according to the fitted model.

\rm

\hypertarget{problem-1e}{%
\subsection{Problem 1(e)}\label{problem-1e}}

List any weaknesses apparent in \verb|lm.3.11|.

\em

Here are some weaknesses we can see in the diagnostic plots
\rm (you may have discovered others; list any two legitimate weaknesses to get full credit)\em:

\begin{itemize}

\item From the QQ plot, both tails of the residual distribution are a bit long.  Although the deviation is more impressive in the lower tail, there are more data points in the upper tail.

\item The scale-location plot suggests that the variance of residuals may increase as DealerCost increases. 

\item Although it is not as evident in the diagnostic plots for \verb|lm.3.11| as it is in the plots for \verb|lm.3.10|, it still looks like the data aggregates along definable curves, which suggests that perhaps different car types have different relationships between DealerCost and SuggestedRetailPrice.

\end{itemize}

(Aside: If we were to successfully model different DealerCost
vs.~SuggestedRetailPrice relationships for different car types, that
might remove the other two problems above as well.)

\rm

\hypertarget{problem-2-sheather-ch-5-p.-147-2.}{%
\section{Problem 2: Sheather, Ch 5, p.~147,
\#2.}\label{problem-2-sheather-ch-5-p.-147-2.}}

We begin with a little exploration, and finding a good model.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{houston }\OtherTok{\textless{}{-}} \FunctionTok{read.csv}\NormalTok{(}\StringTok{"HoustonChronicle.csv"}\NormalTok{,}\AttributeTok{header=}\NormalTok{T)}
\FunctionTok{str}\NormalTok{(houston)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## 'data.frame':    122 obs. of  5 variables:
##  $ District             : chr  "Alvin" "Alvin" "Angleton" "Angleton" ...
##  $ X.Repeating.1st.Grade: num  4.1 5.8 7.1 6.7 7.3 2.6 8.2 2.3 12.5 0 ...
##  $ X.Low.income.students: num  49.7 41.1 44.2 30.2 49.4 33.7 45.6 29.7 71.7 37.6 ...
##  $ Year                 : int  2004 1994 2004 1994 2004 1994 2004 1994 2004 1994 ...
##  $ County               : chr  "Brazoria" "Brazoria" "Brazoria" "Brazoria" ...
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{cat}\NormalTok{(}\StringTok{"}\SpecialCharTok{\textbackslash{}n}\StringTok{"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{Shaded}
\begin{Highlighting}[]
\ControlFlowTok{for}\NormalTok{ (i }\ControlFlowTok{in} \FunctionTok{names}\NormalTok{(houston)) \{}
  \FunctionTok{cat}\NormalTok{(i,}\StringTok{"}\SpecialCharTok{\textbackslash{}n}\StringTok{"}\NormalTok{)}
  \FunctionTok{print}\NormalTok{(}\FunctionTok{summary}\NormalTok{(houston[,i]))}
  \FunctionTok{cat}\NormalTok{(}\StringTok{"Number of unique values:"}\NormalTok{,}\FunctionTok{length}\NormalTok{(}\FunctionTok{unique}\NormalTok{(houston[,i])),}\StringTok{"}\SpecialCharTok{\textbackslash{}n\textbackslash{}n}\StringTok{"}\NormalTok{)}
\NormalTok{\}}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## District 
##    Length     Class      Mode 
##       122 character character 
## Number of unique values: 61 
## 
## X.Repeating.1st.Grade 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   3.100   5.700   6.076   8.750  18.400 
## Number of unique values: 77 
## 
## X.Low.income.students 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    3.20   27.15   41.35   41.88   53.02   98.10 
## Number of unique values: 111 
## 
## Year 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1994    1994    1999    1999    2004    2004 
## Number of unique values: 2 
## 
## County 
##    Length     Class      Mode 
##       122 character character 
## Number of unique values: 8
\end{verbatim}

Apparently, there are only two ``year'' values: 1994 and 2004; so we
will convert this to a factor variable, just to make interpretation of
the coefficients easier; and we make a scatterplot matrix (``pairs''
plot) of all of the variables except district. I'm also going to rename
the two continuous variables to something more suggestive, and re-order
the variables, so that the ``pairs'' plot makes a little more sense.

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{houston}\SpecialCharTok{$}\NormalTok{Year }\OtherTok{\textless{}{-}} \FunctionTok{as.factor}\NormalTok{(houston}\SpecialCharTok{$}\NormalTok{Year)}
\FunctionTok{names}\NormalTok{(houston)[}\FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{)] }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\StringTok{"Pct.Repeating.1st.Grade"}\NormalTok{, }\StringTok{"Pct.Low.income.students"}\NormalTok{)}
\NormalTok{houston }\OtherTok{\textless{}{-}}\NormalTok{ houston[,}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{4}\NormalTok{,}\DecValTok{5}\NormalTok{)]}
\FunctionTok{ggpairs}\NormalTok{(houston[,}\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{])  }\CommentTok{\# there are too many districts for the plot, so we omit it}
\end{Highlighting}
\end{Shaded}

\begin{center}\includegraphics{hw03-solutions_files/figure-latex/unnamed-chunk-7-1} \end{center}

There is some evidence in the ``pairs'' plots for all three of the
hypotheses in parts (a), (b) and (c), but we now fit regression and
ANCOVA models to see which effects are ``significant'' (i.e.~large
enough that they are not likely just due to noise in the data).

\hypertarget{problem-2a-low-income-associated-with-repeating-first-grade}{%
\subsection{Problem 2(a) Low income associated with repeating first
grade?}\label{problem-2a-low-income-associated-with-repeating-first-grade}}

Let's start with a simple regression of repeating first grade on low
income

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{summary}\NormalTok{(lm}\FloatTok{.2}\NormalTok{a }\OtherTok{\textless{}{-}} \FunctionTok{lm}\NormalTok{(Pct.Repeating}\FloatTok{.1}\NormalTok{st.Grade }\SpecialCharTok{\textasciitilde{}}\NormalTok{ Pct.Low.income.students,}\AttributeTok{data=}\NormalTok{houston))}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## 
## Call:
## lm(formula = Pct.Repeating.1st.Grade ~ Pct.Low.income.students, 
##     data = houston)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.9845 -2.5072 -0.4184  1.8505 11.1067 
## 
## Coefficients:
##                         Estimate Std. Error t value Pr(>|t|)    
## (Intercept)              2.91419    0.83836   3.476 0.000709 ***
## Pct.Low.income.students  0.07550    0.01823   4.141 6.47e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.821 on 120 degrees of freedom
## Multiple R-squared:  0.125,  Adjusted R-squared:  0.1177 
## F-statistic: 17.14 on 1 and 120 DF,  p-value: 6.472e-05
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow=}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{1}\NormalTok{))}
\FunctionTok{plot}\NormalTok{(Pct.Repeating}\FloatTok{.1}\NormalTok{st.Grade }\SpecialCharTok{\textasciitilde{}}\NormalTok{ Pct.Low.income.students,}\AttributeTok{data=}\NormalTok{houston)}
\FunctionTok{abline}\NormalTok{(lm}\FloatTok{.2}\NormalTok{a)}
\end{Highlighting}
\end{Shaded}

\begin{center}\includegraphics{hw03-solutions_files/figure-latex/unnamed-chunk-8-1} \end{center}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow=}\FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))}
\FunctionTok{plot}\NormalTok{(lm}\FloatTok{.2}\NormalTok{a)}
\end{Highlighting}
\end{Shaded}

\begin{center}\includegraphics{hw03-solutions_files/figure-latex/unnamed-chunk-9-1} \end{center}

This actually looks like a good regression; the summary shows a very
significant increasing association between percent of students repeating
first grade and percent of students with low (family) incomes: the
coefficient on percent low income students is \(\hat\beta_1 = 0.07550\),
with \(SE(\hat\beta_1)=0.01823\). The effect seems rather small,
however---we expect an increase of only 0.08\% of kids repeating first
grade, for every 1\% increase in kids in poverty.

\hypertarget{problem-2b-more-students-repeating-first-grade-in-2004-2005-than-in-1994-1995}{%
\subsection{Problem 2(b) More students repeating first grade in
2004-2005 than in
1994-1995?}\label{problem-2b-more-students-repeating-first-grade-in-2004-2005-than-in-1994-1995}}

For this question, we will just regress repeating first grade on year

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{summary}\NormalTok{(lm}\FloatTok{.2}\NormalTok{b }\OtherTok{\textless{}{-}} \FunctionTok{lm}\NormalTok{(Pct.Repeating}\FloatTok{.1}\NormalTok{st.Grade }\SpecialCharTok{\textasciitilde{}}\NormalTok{ Year,}\AttributeTok{data=}\NormalTok{houston))}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## 
## Call:
## lm(formula = Pct.Repeating.1st.Grade ~ Year, data = houston)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.6787 -2.6537 -0.6262  2.5750 12.9262 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   5.4738     0.5172  10.584   <2e-16 ***
## Year2004      1.2049     0.7314   1.647    0.102    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.039 on 120 degrees of freedom
## Multiple R-squared:  0.02212,    Adjusted R-squared:  0.01397 
## F-statistic: 2.714 on 1 and 120 DF,  p-value: 0.1021
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow=}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{1}\NormalTok{))}
\NormalTok{jy }\OtherTok{\textless{}{-}} \FunctionTok{jitter}\NormalTok{(}\FunctionTok{as.numeric}\NormalTok{(houston}\SpecialCharTok{$}\NormalTok{Year)}\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{)}
\FunctionTok{plot}\NormalTok{(Pct.Repeating}\FloatTok{.1}\NormalTok{st.Grade }\SpecialCharTok{\textasciitilde{}}\NormalTok{ jy,}\AttributeTok{data=}\NormalTok{houston,}\AttributeTok{xlab=}\StringTok{"Year (jittered)"}\NormalTok{)}
\FunctionTok{abline}\NormalTok{(lm}\FloatTok{.2}\NormalTok{b)}
\end{Highlighting}
\end{Shaded}

\begin{center}\includegraphics{hw03-solutions_files/figure-latex/unnamed-chunk-10-1} \end{center}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow=}\FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))}
\FunctionTok{plot}\NormalTok{(lm}\FloatTok{.2}\NormalTok{b)}
\end{Highlighting}
\end{Shaded}

\begin{center}\includegraphics{hw03-solutions_files/figure-latex/unnamed-chunk-11-1} \end{center}

Again, this looks like a good regression model, in the sense that the
assumptions underlying linear regression are approximately
satisfied\footnote{Remember, the clustering around different $x$ values is just due to the fact that $x$ is categorical.  The important thing here is that we don't see any interesting patterns within or between those clusters.}.
However, the estimated coefficient on Year, \(\hat\beta_1=1.2\) with
\(SE(\hat\beta_1)=0.73\) is not statistically significantly different
from zero. From this we would conclude that there really is not enough
evidence to say that there are more students repeating first grade in
the 2004 school year than in 1994 school year.

\hypertarget{problem-2c-difference-in-the-relationship-of-income-with-repeating-between-the-two-school-years}{%
\subsection{Problem 2(c) Difference in the relationship of income with
repeating between the two school
years?}\label{problem-2c-difference-in-the-relationship-of-income-with-repeating-between-the-two-school-years}}

Now let's fit the interactive ANCOVA model. This will both help answer
question (2c), and help us to understand whether our answers to
questions (2a) and (2b) need any additional elaboration.

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{summary}\NormalTok{(lm}\FloatTok{.2}\NormalTok{c }\OtherTok{\textless{}{-}} \FunctionTok{lm}\NormalTok{(Pct.Repeating}\FloatTok{.1}\NormalTok{st.Grade }\SpecialCharTok{\textasciitilde{}}\NormalTok{ Pct.Low.income.students}\SpecialCharTok{*}\NormalTok{Year,}\AttributeTok{data=}\NormalTok{houston))}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## 
## Call:
## lm(formula = Pct.Repeating.1st.Grade ~ Pct.Low.income.students * 
##     Year, data = houston)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.1606 -2.6121 -0.5576  1.7495 11.6014 
## 
## Coefficients:
##                                  Estimate Std. Error t value Pr(>|t|)   
## (Intercept)                       3.27194    1.22347   2.674  0.00855 **
## Pct.Low.income.students           0.06080    0.03093   1.966  0.05167 . 
## Year2004                         -0.38956    1.76109  -0.221  0.82532   
## Pct.Low.income.students:Year2004  0.01903    0.03949   0.482  0.63066   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.845 on 118 degrees of freedom
## Multiple R-squared:  0.1288, Adjusted R-squared:  0.1066 
## F-statistic: 5.813 on 3 and 118 DF,  p-value: 0.0009689
\end{verbatim}

The summary shows that neither the main effect for Year, nor the
interaction between low income and Year, are significant in the model.
This is illustrated in the scatterplot below: the regression lines for
the two categories (year=1994-1995 and year=2004-2005) are nearly
identical. The residual diagnostic plots that follow suggest that the
modeling assumptions hold up fairly well here.

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow=}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{1}\NormalTok{))}
\FunctionTok{plot}\NormalTok{(Pct.Repeating}\FloatTok{.1}\NormalTok{st.Grade }\SpecialCharTok{\textasciitilde{}}\NormalTok{ Pct.Low.income.students,}\AttributeTok{data=}\NormalTok{houston,}
     \AttributeTok{col=}\FunctionTok{as.numeric}\NormalTok{(houston}\SpecialCharTok{$}\NormalTok{Year))}
\NormalTok{coefs }\OtherTok{\textless{}{-}} \FunctionTok{coefficients}\NormalTok{(lm}\FloatTok{.2}\NormalTok{c)}
\FunctionTok{abline}\NormalTok{(}\AttributeTok{a=}\NormalTok{coefs[}\DecValTok{1}\NormalTok{],}\AttributeTok{b=}\NormalTok{coefs[}\DecValTok{2}\NormalTok{],}\AttributeTok{col=}\DecValTok{1}\NormalTok{)}
\FunctionTok{abline}\NormalTok{(}\AttributeTok{a=}\NormalTok{coefs[}\DecValTok{1}\NormalTok{]}\SpecialCharTok{+}\NormalTok{coefs[}\DecValTok{3}\NormalTok{],}\AttributeTok{b=}\NormalTok{coefs[}\DecValTok{2}\NormalTok{]}\SpecialCharTok{+}\NormalTok{coefs[}\DecValTok{4}\NormalTok{],}\AttributeTok{col=}\DecValTok{2}\NormalTok{)}
\FunctionTok{legend}\NormalTok{(}\DecValTok{78}\NormalTok{,}\DecValTok{18}\NormalTok{,}\AttributeTok{legend=}\FunctionTok{c}\NormalTok{(}\StringTok{"1994{-}1995"}\NormalTok{,}\StringTok{"2004{-}2005"}\NormalTok{),}\AttributeTok{pch=}\DecValTok{1}\NormalTok{,}\AttributeTok{col=}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{),}\AttributeTok{cex=}\FloatTok{0.5}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{center}\includegraphics{hw03-solutions_files/figure-latex/unnamed-chunk-12-1} \end{center}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow=}\FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))}
\FunctionTok{plot}\NormalTok{(lm}\FloatTok{.2}\NormalTok{c)}
\end{Highlighting}
\end{Shaded}

\begin{center}\includegraphics{hw03-solutions_files/figure-latex/unnamed-chunk-13-1} \end{center}

We can also apply an F test using the ANOVA function in R to compare the
full ANCOVA model in part (c) with the models in parts (a) and (b).

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{anova}\NormalTok{(lm}\FloatTok{.2}\NormalTok{a,lm}\FloatTok{.2}\NormalTok{c)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Analysis of Variance Table
## 
## Model 1: Pct.Repeating.1st.Grade ~ Pct.Low.income.students
## Model 2: Pct.Repeating.1st.Grade ~ Pct.Low.income.students * Year
##   Res.Df    RSS Df Sum of Sq      F Pr(>F)
## 1    120 1751.9                           
## 2    118 1744.4  2     7.512 0.2541 0.7761
\end{verbatim}

Since the \(F\) statistic testing \(H_0\):
\({\tt Pct.Repeating.1st.Grade ~\sim~ Pct.Low.income.students}\) vs
\(H_A\):
\({\tt Pct.Repeating.1st.Grade ~\sim~ Pct.Low.income.students * Year}\)
is nonsignificant (\(F=0.2541\), \(p=0.7761\)), we cannot reject the
simpler model in part (a): If we are starting with
\({\tt Pct.Repeating.1st.Grade ~\sim~ }\)
\({\tt Pct.Low.income.students}\), there is really no need to add
\({\tt Year}\) (let alone an interaction with \({\tt Year}\)) to the
model.

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{anova}\NormalTok{(lm}\FloatTok{.2}\NormalTok{b,lm}\FloatTok{.2}\NormalTok{c)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## Analysis of Variance Table
## 
## Model 1: Pct.Repeating.1st.Grade ~ Year
## Model 2: Pct.Repeating.1st.Grade ~ Pct.Low.income.students * Year
##   Res.Df    RSS Df Sum of Sq      F   Pr(>F)   
## 1    120 1957.9                                
## 2    118 1744.4  2    213.52 7.2221 0.001099 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
\end{verbatim}

Here the \(F\) statistic testing \(H_0\):
\({\tt Pct.Repeating.1st.Grade ~\sim~ Year}\) vs \(H_A\):
\({\tt Pct.Repeating.1st.Grade ~\sim~ }\)
\({\tt Pct.Low.income.students * Year}\) is highly significant
(\(F=7.2221\), \(p=0.001099\)), so we would reject the simpler model in
part (b): starting with \({\tt Pct.Repeating.1st.Grade ~\sim~ Year}\),
we really do get a better model by adding
\({\tt Pct.Low.income.students}\) to the model.

Note that we cannot perform an \(F\) test like
\({\tt anova(lm.2a, lm.2b)}\)
directly\footnote{There are ways to compare non-nested models, e.g. cross-validation, AIC, BIC, etc., but it doesn't work with $F$ tests or likelihood ratio tests.},
since these models are not nested. We can infer, informally, from the
above tests though, that of all three models,
\({\tt Pct.Repeating.1st.Grade ~\sim~ Pct.Low.income.students}\) seems
to be the best. Thus, there is no difference between years in the way
that low income is related to repeating first grade.

\hypertarget{problem-3-sheather-ch-6-pp.-224-ff.-5.}{%
\section{Problem 3: Sheather, Ch 6, pp.~224 ff.,
\#5.}\label{problem-3-sheather-ch-6-pp.-224-ff.-5.}}

\begin{itemize}
\item For part (b), feel free to transform variables as needed so that (i) the assumptions of the linear regression model are better satisfied; and (ii) the model is still ``explainable'' to non-statisticians.

\item For part (e): We will discuss variable selection formally next week.  For now, remember that the $t$ statistic for each column $X_j$ of the $X$ matrix tests whether the coefficient $\beta_j$ is significantly different from zero, \textit{after including all other columns of $X$ in the model.}

\end{itemize}

\hypertarget{problem-3a-transform-prizemoney-rightarrow-logprizemoney-but-no-other-transformations}{%
\subsection{\texorpdfstring{Problem 3(a) Transform PrizeMoney
\(\rightarrow\) log(PrizeMoney) but no other
transformations?}{Problem 3(a) Transform PrizeMoney \textbackslash rightarrow log(PrizeMoney) but no other transformations?}}\label{problem-3a-transform-prizemoney-rightarrow-logprizemoney-but-no-other-transformations}}

\em

From the \verb|ggpairs| plot below, and possibly from futher analysis
that you did for Quiz 2, only the variables \verb|TigerWoods| and
\verb|PrizeMoney| are strongly skewed. The variable \verb|TigerWoods| is
a dummy/indicator variable, so we won't transform that. Because of the
strong skew in \verb|PrizeMoney|, a log transformation makes sense for
this variable (Box-Cox would confirm that, by suggesting a power of
\verb|PrizeMoney| very close to zero).

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{golf }\OtherTok{\textless{}{-}} \FunctionTok{read.csv}\NormalTok{(}\StringTok{"pgatour2006.csv"}\NormalTok{,}\AttributeTok{header=}\ConstantTok{TRUE}\NormalTok{)}
\FunctionTok{names}\NormalTok{(golf)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
##  [1] "Name"               "TigerWoods"         "PrizeMoney"        
##  [4] "AveDrivingDistance" "DrivingAccuracy"    "GIR"               
##  [7] "PuttingAverage"     "BirdieConversion"   "SandSaves"         
## [10] "Scrambling"         "BounceBack"         "PuttsPerRound"
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{ggpairs}\NormalTok{(golf[}\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{],}\AttributeTok{upper =} \FunctionTok{list}\NormalTok{(}\AttributeTok{continuous =} \FunctionTok{wrap}\NormalTok{(}\StringTok{"cor"}\NormalTok{, }\AttributeTok{size=}\FloatTok{2.5}\NormalTok{))) }\DocumentationTok{\#\# don\textquotesingle{}t include golfer\textquotesingle{}s name }
\end{Highlighting}
\end{Shaded}

\begin{center}\includegraphics{hw03-solutions_files/figure-latex/unnamed-chunk-16-1} \end{center}

None of the other variables show strong skew visually, though Box-Cox
might recommend various transformations for them. In the interest of
being able to communicate clearly about any predictors in the model, and
since these predictors don't exhibit much skew anyway, I'm going to
leave them untransformed.

\rm

\hypertarget{problem-3b-develop-a-valid-full-regression-model-containing-all-seven-potential-predictors-listed-in-the-problem-stmt-using-logprizemoney-as-the-response-variable}{%
\subsection{Problem 3(b) Develop a valid full regression model
containing all seven potential predictors (listed in the problem stmt),
using log(PrizeMoney) as the response
variable}\label{problem-3b-develop-a-valid-full-regression-model-containing-all-seven-potential-predictors-listed-in-the-problem-stmt-using-logprizemoney-as-the-response-variable}}

\em

If we look at the data set directly

\tiny

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{oldwidth }\OtherTok{\textless{}{-}} \FunctionTok{options}\NormalTok{()}\SpecialCharTok{$}\NormalTok{width}
\FunctionTok{options}\NormalTok{(}\AttributeTok{width=}\DecValTok{200}\NormalTok{)}
\FunctionTok{head}\NormalTok{(golf)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
##               Name TigerWoods PrizeMoney AveDrivingDistance DrivingAccuracy   GIR PuttingAverage BirdieConversion SandSaves Scrambling BounceBack PuttsPerRound
## 1   Aaron Baddeley          0      60661              288.3           60.73 58.26          1.745            31.36     54.80      59.37      19.30         27.96
## 2       Adam Scott          0     262045              301.1           62.00 69.12          1.767            30.39     53.61      57.94      19.35         29.28
## 3      Alex Aragon          0       3635              302.6           51.12 59.11          1.787            29.89     37.93      50.78      16.80         29.20
## 4       Alex Cejka          0      17516              288.8           66.40 67.70          1.777            29.33     45.13      54.82      17.05         29.46
## 5      Arjun Atwal          0      16683              287.7           63.24 64.04          1.761            29.32     52.44      57.07      18.21         28.93
## 6 Arron Oberholser          0     107294              285.0           62.53 69.27          1.775            29.20     47.20      57.67      20.00         29.56
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{options}\NormalTok{(}\AttributeTok{width=}\NormalTok{oldwidth)}
\end{Highlighting}
\end{Shaded}

\normalsize

we see that each line is for one golfer, and each golfer has a different
name. Thus, if we include \verb|Name| in the regression (a) the model
will fit perfectly, but (b) we will get no information about the other
predictors (try it! it's truly ugly!).

So I will remove \verb|Name| from the data set and proceed from
there\ldots{}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{golf }\OtherTok{\textless{}{-}}\NormalTok{ golf[,}\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{]}
\end{Highlighting}
\end{Shaded}

Really, nothing more than this model is required:

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{summary}\NormalTok{(lm.}\FloatTok{3.1} \OtherTok{\textless{}{-}} \FunctionTok{lm}\NormalTok{(}\FunctionTok{log}\NormalTok{(PrizeMoney) }\SpecialCharTok{\textasciitilde{}}\NormalTok{ DrivingAccuracy }\SpecialCharTok{+}\NormalTok{ GIR }\SpecialCharTok{+}\NormalTok{ PuttingAverage }
                     \SpecialCharTok{+}\NormalTok{ BirdieConversion }\SpecialCharTok{+}\NormalTok{ SandSaves }\SpecialCharTok{+}\NormalTok{ Scrambling }\SpecialCharTok{+}\NormalTok{ PuttsPerRound,}
                     \AttributeTok{data=}\NormalTok{golf))}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
## 
## Call:
## lm(formula = log(PrizeMoney) ~ DrivingAccuracy + GIR + PuttingAverage + 
##     BirdieConversion + SandSaves + Scrambling + PuttsPerRound, 
##     data = golf)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.71949 -0.48608 -0.09172  0.44561  2.14013 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       0.194300   7.777129   0.025 0.980095    
## DrivingAccuracy  -0.003530   0.011773  -0.300 0.764636    
## GIR               0.199311   0.043817   4.549 9.66e-06 ***
## PuttingAverage   -0.466304   6.905698  -0.068 0.946236    
## BirdieConversion  0.157341   0.040378   3.897 0.000136 ***
## SandSaves         0.015174   0.009862   1.539 0.125551    
## Scrambling        0.051514   0.031788   1.621 0.106788    
## PuttsPerRound    -0.343131   0.473549  -0.725 0.469601    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6639 on 188 degrees of freedom
## Multiple R-squared:  0.5577, Adjusted R-squared:  0.5412 
## F-statistic: 33.87 on 7 and 188 DF,  p-value: < 2.2e-16
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow=}\FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))}
\FunctionTok{plot}\NormalTok{(lm.}\FloatTok{3.1}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{center}\includegraphics{hw03-solutions_files/figure-latex/unnamed-chunk-19-1} \end{center}

You can play with other transformations, but this is already a pretty
good model, in terms of the casewise diagnostic plots, and so I wouldn't
bother (this is easier to explain to a client or collaborator!):

\begin{itemize}
\item The residuals vs fitted values plot does not show any pattern other than smaller amounts of data for very low or very high $\hat y$'s.  
\item Tne normal QQ plot looks very good except for a slight hint of a bit of a long tail to the right, but this is very minor and probably can be ignored.
\item The Scale-Location plot is almost a perfect example of constant variance, with just a little bit of small-sample bias for larger $\hat y$ where there is very little data
\item The residuals vs leverage plot shows no concerning points in the northeast or southeast corners of the plot.
\end{itemize}

Given that the model \verb|lm.3.1| seems to satisfy the assumptions of
linear regression well, we can use the overall F test to see that
regressing on these variables is better than the intercept-only model
(\(F=33.872\) on 7 and 188 df, \(p<2.2\times10^{-16}\)). Here \(R^2\) is
a fairly modest 0.66, and only two of the seven predictors have
significant \(t\) statistics. \rm

\hypertarget{problem-3c-identify-any-points-that-should-be-investigated.-give-one-or-more-reasons-to-support-each-point-chosen.}{%
\subsection{Problem 3(c) Identify any points that should be
investigated. Give one or more reasons to support each point
chosen.}\label{problem-3c-identify-any-points-that-should-be-investigated.-give-one-or-more-reasons-to-support-each-point-chosen.}}

\em

One point in the casewise diagnostic plots seems to have a high fitted
value and high leverage. One way to find that point is this (sorry for
the small type; trying to make a row of the data frame fit on one
line)\ldots{}

\tiny

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{oldwidth }\OtherTok{\textless{}{-}} \FunctionTok{options}\NormalTok{()}\SpecialCharTok{$}\NormalTok{width}
\FunctionTok{options}\NormalTok{(}\AttributeTok{width=}\DecValTok{200}\NormalTok{)}

\NormalTok{max.fitted.val }\OtherTok{\textless{}{-}} \FunctionTok{max}\NormalTok{(}\FunctionTok{fitted}\NormalTok{(lm.}\FloatTok{3.1}\NormalTok{))}
\NormalTok{golf[}\FunctionTok{fitted}\NormalTok{(lm.}\FloatTok{3.1}\NormalTok{)}\SpecialCharTok{==}\NormalTok{max.fitted.val,]}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
##     TigerWoods PrizeMoney AveDrivingDistance DrivingAccuracy   GIR PuttingAverage BirdieConversion SandSaves Scrambling BounceBack PuttsPerRound
## 178          1     662771              306.4           60.71 74.15          1.756            35.26     55.17      62.81      24.77         29.38
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{max.leverage }\OtherTok{\textless{}{-}} \FunctionTok{max}\NormalTok{(}\FunctionTok{hatvalues}\NormalTok{(lm.}\FloatTok{3.1}\NormalTok{))}
\NormalTok{golf[}\FunctionTok{hatvalues}\NormalTok{(lm.}\FloatTok{3.1}\NormalTok{)}\SpecialCharTok{==}\NormalTok{max.leverage,]}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
##     TigerWoods PrizeMoney AveDrivingDistance DrivingAccuracy   GIR PuttingAverage BirdieConversion SandSaves Scrambling BounceBack PuttsPerRound
## 178          1     662771              306.4           60.71 74.15          1.756            35.26     55.17      62.81      24.77         29.38
\end{verbatim}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{options}\NormalTok{(}\AttributeTok{width=}\NormalTok{oldwidth)}
\end{Highlighting}
\end{Shaded}

\normalsize

\ldots and we find that the unusual data point belongs to Tiger Woods!
We already know there is a special indicator variable for Tiger Woods,
which is perhaps not surprising since he was far and away the top prize
money earner in golf in 2006:

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{attach}\NormalTok{(golf)}
\NormalTok{tw }\OtherTok{\textless{}{-}}\NormalTok{ PrizeMoney[}\DecValTok{178}\NormalTok{]}
\FunctionTok{hist}\NormalTok{(PrizeMoney)}
\FunctionTok{abline}\NormalTok{(}\AttributeTok{v=}\NormalTok{tw,}\AttributeTok{col=}\StringTok{"red"}\NormalTok{)}
\FunctionTok{text}\NormalTok{(tw}\DecValTok{{-}160000}\NormalTok{,}\DecValTok{50}\NormalTok{,}\StringTok{"Tiger Woods\textquotesingle{} Prize Money"}\NormalTok{,}\AttributeTok{col=}\StringTok{"red"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{center}\includegraphics{hw03-solutions_files/figure-latex/unnamed-chunk-21-1} \end{center}

\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{detach}\NormalTok{(golf)}
\end{Highlighting}
\end{Shaded}

\rm

\hypertarget{problem-3d-describe-any-weaknesses-in-your-model.}{%
\subsection{Problem 3(d) Describe any weaknesses in your
model.}\label{problem-3d-describe-any-weaknesses-in-your-model.}}

\em

As shown above, the model seems to satisfy the assumptions of linear
regression, so the overall fit seems good. Weaknesses of the model
include:

\begin{itemize}
\item $R^2=0.66$ so only 66\% of the variation in \verb|log(PrizeMoney)| is explained by the predictors.
\item Only two of the seven predictors (\verb|GIR| and \verb|BirdieConversion|) have coefficients significantly different from zero, according to the $t$ statistics.
\end{itemize}

\rm

\hypertarget{problem-3e-the-golf-fan-wants-to-remove-all-predictors-with-insignificant-t--values-from-the-full-model-in-a-single-step.-explain-why-you-would-not-recommend-this-approach.}{%
\subsection{Problem 3(e) The golf fan wants to remove all predictors
with insignificant t -values from the full model in a single step.
Explain why you would not recommend this
approach.}\label{problem-3e-the-golf-fan-wants-to-remove-all-predictors-with-insignificant-t--values-from-the-full-model-in-a-single-step.-explain-why-you-would-not-recommend-this-approach.}}

\em

The \(t\)-test for a predictor is the numerical equivalent of the
added-variable plot: it shows the importance of that predictor,
\textit{after} other predictors have been added to the model. Indeed,
\(t^2 = F\), the partial \(F\) statistic for adding that predictor,
after all other predictors have been added to the model.

If two or more predictors are co-linear, the \(t\) statistics for any of
them---even for all of them---can be nonsignificant, even though they
contribute significantly to explaining \(y\).

Thus, removing all the predictors with non-significant \(t\)-statistics
at once can remove important variables in the model. As seen in the
\verb|ggpairs| plot in part (a), some predictors are highly correlated
with one another, and linear combinations of them may be even more
highly correlated with one another.

If we are going to use \(t\) statistics to eliminate variables, it is
better to eliminate one-at-a-time, starting with the \(t\) statistics
closest to zero (unless our client or collaborator wants to eliminate
something else first). Each time we eliminate a variable, we would
re-fit the model and discover that all the remaining \(t\)-statistics
have changed, and we would use the new \(t\)-statistics to select the
next predictor to eliminate.

This recipe is easy to follow but it does not necessarily lead to a
great model, because (a) it is ``greedy'' in that it only looks at the
``worst'' variable at each step, rather than considering other orders in
which to eliminate variables, and (b) it re-uses the data many times,
and so is vulnerability to ``capitalization on chance'': \(t\)
statistics in subsequent models after removing one or more predictors do
not have the ``textbook'' distributions, and we may be making severe
errors by relying on them for variable selection.

In Chapter 7 and related readings, we will look at better ways to do
variable selection.

\rm

\hypertarget{problem-4}{%
\section{Problem 4}\label{problem-4}}

In the folder for this hw assignment you will find a pdf called ``COVID
breakthrough rates in England''. This is a recent article from the
medical journal \textit{The Lancet}. Note that the article is exactly in
IMRAD format, with sections labelled ``Introduction'', ``Methods'',
``Results'' and \{``Discussion''.

The Abstract for this paper has a special form, called a ``structured
abstract'', in which there is a short, labelled, paragraph corresponding
to each section of the paper. We will not be writing structured
abstracts in our class, but it is good to see the additional information
that a structured abstract can contain. In our class, we will be writing
shorter abstracts, consisting of approximately one sentence per section
of the paper (so, 4--5 sentences for a paper with 4 sections). Each
sentence highlights the main point of each section, possibly with one
extra sentence giving the main resul of the paper.

\hypertarget{problem-4a}{%
\subsection{Problem 4(a)}\label{problem-4a}}

Write a one-paragraph abstract with exactly four sentences, one for each
section of the paper: Introduction, Methods, Results and Discussion.
Each sentence should highlight the main point of each section, and
together the four sentences should tell the story of the paper. The last
sentence should include the main result of the paper (or, if you need a
fifth sentence to give the main result, that is fine too).

\em

\textsf{(For most of this abstract I simply copied or merged sentences from the structured abstract on p. 1 of the article [you could of course write your own sentences summarizing each part of the article].  I thought it would be helpful if I added a footnote for the place I got each sentence [you do not have to do this for your answer].)}

This study aimed to identify risk factors for post-vaccination
SARS-CoV-2 infection and describe the characteristics of
post-vaccination
illness\footnote{Last sentence of summary paragraph, p. 1}. We used
univariate logistic regression models (adjusted for age, BMI, and sex)
to analyse the associations between risk factors and post-vaccination
infection, and the associations of individual symptoms, overall disease
duration, and disease severity with vaccination status, in self-report
data from UK-based, adult (\mbox{$\geq$} 18 years) users of the COVID
Symptom Study mobile phone
app\footnote{Combining first and last sentences of Methods paragraph, p. 1}.
Vaccination (compared with no vaccination) was associated with reduced
odds of hospitalisation or having more than five symptoms in the first
week of illness following the first or second dose, and long-duration
(\mbox{$\geq$} 28 days) symptoms following the second dose; following
first dose only, older adults, individuals living in deprived areas, and
obese individuals all experienced higher risk of breakthrough
infection\footnote{Second-to-last sentence of Findings paragraph, combined with a summary of the risk factor analysis.}.
Our findings might support caution around relaxing physical distancing
and other personal protective measures in the post-vaccination era,
particularly around frail older adults and individuals living in more
deprived areas, even if these individuals are vaccinated, and might have
implications for strategies such as booster
vaccinations\footnote{Last sentence of Interpretation paragraph, p. 1}.

\rm

\hypertarget{problem-4b}{%
\subsection{Problem 4(b)}\label{problem-4b}}

Does the paper appropriately address each of the parts of an IMRAD paper
as described the ``IMRAD: What goes into each section'' pdf? (in the
hw01 folder in the files area of our Canvas site.)

For each section below, either say ``yes this section has the right
content'', or say ``no'' and describe what is missing and/or what needs
to be moved to another section of the paper or deleted.

\em

\textbf{Note:} I give one possible set of answers below. You do not have
to give the same answers, as long as the answers you give are
thoughtful.

\begin{itemize}
\item Your ``yes'' and ``no'' answers do not have to match mine.
\item If you say ``yes the content in this section is fine'' you do not have to give examples (even though I do below)
\item If you say ``no'' then we want to see thoughtful examples/discussion of what is missing or what needs to be moved elsewhere, etc.
\end{itemize}

\begin{description}
\item[Introduction:] ~ Yes this section has the right content \rm(you do not need to give examples; I did just so you could see where some of the elements are)\em

\begin{itemize}
\item Supplies sufficient background information, e.g.:
\begin{quote}
``Vaccination against SARS-CoV-2 is a leading strategy to
change the course of the COVID-19 pandemic
worldwide\ldots ''\\

``A previous analysis of community-based individuals
in the COVID Symptom Study showed a significant
reduction in infection post-vaccination from 12 days
after the first dose\ldots''\\

``Nonetheless, some people still contract COVID-19 after
vaccination, and further virus variants could evolve\ldots''

\end{quote}


\item Shows Define lacunae and shortcomings in current
state of knowledge \& Rationale for the study, e.g.:
\begin{quote}
Individuals with COVID-19 have differing symptoms
and clinical needs.20 Elucidating symptom profiles in
individuals with COVID-19 after vaccination has clinical
utility, facilitating the identification of risk groups for
intervention, predicting medical resource requirements,
and informing appropriate testing guidelines. Additionally,
some unvaccinated individuals with COVID-19 have
prolonged illness duration (so-called long COVID) and
whether vaccination reduces the risk of long COVID is
currently unknown.
\end{quote}

\item States aim of the study, e.g.:
\begin{quote}
Therefore, we aimed to (1) describe individual risk
factors associated with SARS-CoV-2 infection at least
14 days after first vaccination or 7 days after second
vaccination, and (2) assess illness duration, severity, and
symptom profile in individuals with SARS-CoV-2 infection
after their first and second vaccinations, compared with
unvaccinated individuals with SARS-CoV-2 infection.
\end{quote}
\end{itemize}

\item[Methods:] ~ Yes this section has the right content \rm(again, you do not need to give examples; I did just so you could see where some of the elements are)\em

\begin{itemize}
\item Broken down into subsection (may not be necessary for all papers, but nice here):
\begin{itemize}
\item Study design and participants
\item Risk factor variable definitions
\item Disease severity, duration, and symptom definitions
\item Statistical analysis
\item Role of the funding source
\end{itemize}
These sections provide all of the elements recommended by the slides on what goes into an IMRAD paper (study design, variable definitions, how outcomes are measured, analysis and statistical methods).\\

\underline{Notes:} 
\begin{enumerate}
\item In an IDMRAD (Introduction, Data, Methods, Results, and Discussion) paper (which we will be writing later in the course, instead of IMRAD papers), the first three bullets above (study design, variable defintions) would be moved into the Data section of the paper, between the Introduction and Methods sections of the paper.
\item The subsection ``Role of the funding source'' would not be needed in our papers, but it is needed in papers where the author needs to show that their research was not unduly influenced by who funded the work.  This is actually an aspect of addressing \textbf{ethics} in the study.  (Other aspects of ethics include: how fairly and respectfully did the researchers treat human subjecs; whether invidually-identifiable results were kept confidential, whether related research by other researchers was fairly credited and cited in the paper, etc.)
\item If the paper is intended to answer more than one research question, another way to organize the Methods section would be to have one subsection for each research question.  The Results section would then have the same subsections.  Since this study had two major questions --- (1) describe individual risk
factors associated with SARS-CoV-2 infection at least
14 days after first vaccination or 7 days after second
vaccination; and (2) assess illness duration, severity, and
symptom profile in individuals with SARS-CoV-2 infection
after their first and second vaccinations, compared with
unvaccinated individuals with SARS-CoV-2 infection --- another way to organize this paper would have been to have two subsections, one for each question, in the Methods section, and in the Results section. Organizing these sections by research question makes it more skimmable by readers who are in a hurry (and most readers are!).
\end{enumerate}

\end{itemize}

\item[Results:] ~ Yes this section has the right content, \textbf{BUT} I thought this was the weakest section of the paper \rm(again, you do not need to give examples; I did just so you could see where some of the elements are)\em

\begin{itemize}
\item The first part of the discussion talks about the results of the experiment/data collection, which was good.
\item The next several paragraphs discuss statistical analyses in a natural order, but they are not very good at helping the reader remember which of the two major questions each analysis goes with
\item Here, subsections labelled with each research question would be really helpful.
\item Tables 1 and 2 and Figures 1,2,3,4 are very helpful in answering the first research question (if the reader can remember what it was!) but there doesn't seem to be an easily identifiable summary of results for the second research question (results for the second question are discussed at the end of p. 7 and the first column of page 9, in text form only).
\end{itemize}
A good rule is: if the reader has to work too hard to find what they are looking for in the paper, then the paper really should be better written or organized!

\item[Discussion:] ~ Yes this section has the right content \rm(you do not need to give examples; I did just so you could see where some of the elements are)\em

\begin{itemize}
\item A summary (recapitulation) of the study and its major findings appears on pp 8--10.
\item Limitations and strengths of the study are discussed on p. 11
\item Broader implications are discussed in the last paragraph of the paper.
\item It might have been nice for the authors to indicate ideas for future research building on this work, as well.
\end{itemize}

\end{description}

\rm

\end{document}
