% 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}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
  pdftitle={Homework 05 Solutions},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[margin=1in]{geometry}
\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\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
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{xcolor}
\usepackage{txfonts}
\DeclareMathOperator{\Cov}{Cov}
\DeclareMathOperator{\Corr}{Corr}
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi

\title{Homework 05 Solutions}
\author{}
\date{\vspace{-2.5em}10/4/2021}

\begin{document}
\maketitle

\hypertarget{sheather-6.7.5}{%
\section{1. (Sheather 6.7.5)}\label{sheather-6.7.5}}

\begin{enumerate}
\def\labelenumi{(\alph{enumi})}
\item
  Agree. Since the \(Y\) variable is heavily right-skewed and ranges
  over several orders of magnitude, a log transformation probably makes
  sense. To confirm this, you can regress \texttt{PrizeMoney} against
  the other predictors and then regress \texttt{log(PrizeMoney)} against
  the other predictors. The residuals are clearly non-normal in the
  first case and are approximately normal in the second case, which
  suggests that the log transformation of the outcome variable is
  appropriate. There is no apparent need to transform the predictors.
\item
  I simply regressed the log-transformed \texttt{PrizeMoney} variable
  (\texttt{LogPrizeMoney}) against the seven predictors. The diagnostic
  plots (Figure \ref{f:diagnostics1}) look about as good as one could
  ask. Since I know nothing about golf, I have no reason to expect any
  particular interactions, so for the sake of simplicity, and since the
  diagnostics look good, I will leave the model as is. A summary of the
  model is below, and Figure \ref{f:golf_pairs} contains a pairs plot of
  the data. Some collinearity is evident in the pairs plots, in
  particular between \texttt{PuttingAverage} and
  \texttt{BirdieConversion} and between \texttt{PuttingAverage} and
  \texttt{PuttsPerRound}.
\end{enumerate}

\begin{quote}
It is tempting to remove some of the predictors with high p-values, but
until we are working with a golf expert as a collaborator we do not know
which ones to remove. If we wanted to remove some predictors without
further information, we might consider removing ones for which the 95\%
confidence interval for \(\hat\beta\) (a) is narrow and (b) contains
zero. \texttt{DrivingAccuracy}, \texttt{SandSaves} and maybe
\texttt{Scrambling} could be considered for removal. On the other hand
\texttt{PuttingAverage} has a very wide confidence interval, which
suggests that we may not have enough information yet to have a good
estimate of its \(\hat\beta\). (See also the comments after part (e)
below.)
\end{quote}

\hypertarget{summary-of-the-golf-model}{%
\subsection{Summary of the golf
model:}\label{summary-of-the-golf-model}}

\begin{longtable}[]{@{}
  >{\centering\arraybackslash}p{(\columnwidth - 8\tabcolsep) * \real{0.32}}
  >{\centering\arraybackslash}p{(\columnwidth - 8\tabcolsep) * \real{0.15}}
  >{\centering\arraybackslash}p{(\columnwidth - 8\tabcolsep) * \real{0.18}}
  >{\centering\arraybackslash}p{(\columnwidth - 8\tabcolsep) * \real{0.15}}
  >{\centering\arraybackslash}p{(\columnwidth - 8\tabcolsep) * \real{0.17}}@{}}
\toprule
~ & Estimate & Std. Error & t value &
Pr(\textgreater\textbar t\textbar) \\
\midrule
\endhead
\textbf{(Intercept)} & 0.1943 & 7.777 & 0.02498 & 0.9801 \\
\textbf{DrivingAccuracy} & -0.00353 & 0.01177 & -0.2998 & 0.7646 \\
\textbf{GIR} & 0.1993 & 0.04382 & 4.549 & 9.658e-06 \\
\textbf{PuttingAverage} & -0.4663 & 6.906 & -0.06752 & 0.9462 \\
\textbf{BirdieConversion} & 0.1573 & 0.04038 & 3.897 & 0.0001355 \\
\textbf{SandSaves} & 0.01517 & 0.009862 & 1.539 & 0.1256 \\
\textbf{Scrambling} & 0.05151 & 0.03179 & 1.621 & 0.1068 \\
\textbf{PuttsPerRound} & -0.3431 & 0.4735 & -0.7246 & 0.4696 \\
\bottomrule
\end{longtable}

\begin{longtable}[]{@{}
  >{\centering\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.21}}
  >{\centering\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.31}}
  >{\centering\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.12}}
  >{\centering\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.24}}@{}}
\toprule
Observations & Residual Std. Error & \(R^2\) & Adjusted \(R^2\) \\
\midrule
\endhead
196 & 0.6639 & 0.5577 & 0.5412 \\
\bottomrule
\end{longtable}

\begin{figure}
\centering
\includegraphics{hw05_solutions_files/figure-latex/1_pairs-1.pdf}
\caption{Pairs plot of golf data, with log transformation of PrizeMoney
variable.\label{f:golf_pairs}}
\end{figure}

\begin{figure}
\centering
\includegraphics{hw05_solutions_files/figure-latex/1_diagnostics-1.pdf}
\caption{Problem 1: Diagnostic plots.\label{f:diagnostics1}}
\end{figure}

\begin{enumerate}
\def\labelenumi{(\alph{enumi})}
\setcounter{enumi}{2}
\item
  There are no points that clearly require investigation. Point 185 has
  a large residual, but in a data set of size 196 it is not particularly
  surprising to see a point with a standardized residual of 3 or so.
  There are no bad leverage points, and since the diagnostics look good
  in general, there's nothing obvious to investigate.
\item
  As noted above, there's some collinearity in the predictors, so some
  of the predictors may be redundant; and the standard errors of the
  estimates may be large because of this. As always, the assumption that
  the outcome is linearly related to the predictors is a strong one, and
  it means the model will not capture nonlinearities.
\item
  There are two problems with relying only on insignificant \(t\)-values
  to eliminate predictors in a model. The first is that a \(t\)-value
  can be small because the predictor is (nearly) collinear with another
  predictor or group of predictors. In that case, it's not obvious which
  predictor (if any!) to eliminate, without a conversation with a
  subject matter expert. The second is that hypothesis tests are
  asymmetrical, in the sense that when we reject the test, we are making
  an assertion that \(H_0\) is false (with the attendant possibility of
  Type I error), whereas when we fail to reject the test, it could be
  because we have strong evidence that \(H_0\) is true or because we
  simply don't have enough evidence to make a judgment either way.
\end{enumerate}

\begin{quote}
\begin{quote}
A TA from a previous iteration of the class comments further on the
second reason:
\end{quote}
\end{quote}

\begin{quote}
\begin{quote}
The value of the \(t\)-statistic associated with a coefficient
\(\beta_k\) in a regression is a function of the magnitude of
\(\beta_k\), the variance of the predictor \(X_k\), the amount of noise
around the regression line, and the sample size. We may be able to
reject the null for coefficients with very small magnitudes if, say, the
variance of the associated predictor is high; conversely, we may fail to
reject the null for coefficients with large magnitudes because the range
of the associated predictor is small. Just because a test is
insignificant does not mean that the predictor is insignificant in a
real world sense. (If, however, the confidence interval for the
predictor were very small and contained 0, then we might be able to
confidently say that the coefficient was insignificant in a real world
sense, as long as the model were generally credible.) For more details,
see Professor Shalizi's lecture notes from 36-401:

\begin{itemize}
{\color{blue} \item \href{http://www.stat.cmu.edu/~cshalizi/mreg/15/lectures/08/lecture-08.pdf}{Fall 2015, Lecture 8. Statistical Signifcance: Uses and Abuses}} (esp. Sections 5, 6, \& 7)
{\color{blue}\item \href{http://www.stat.cmu.edu/~cshalizi/mreg/15/lectures/lecture-15.pdf}{Fall 2015, Lecture 15. What, Exactly, Is R Testing?}}
{\color{blue}\item \href{http://www.stat.cmu.edu/~cshalizi/mreg/15/lectures/26/lecture-26.pdf}{Why Variable Selection Using p-Values Is a Bad Idea}}
\end{itemize}
\end{quote}
\end{quote}

\hypertarget{the-beauty-data-again}{%
\section{2. The Beauty Data Again}\label{the-beauty-data-again}}

\hypertarget{a}{%
\subsection{(a)}\label{a}}

Why might we want to transform a predictor? There are at least three
reasons:

\begin{itemize}
  \item For interpretability, for example if we want the intercept to have a particular meaning, or if we want to be able to think about percentage changes in $y$ relative to $x$, rather than linear changes.
  \item To reduce the leverage of particular points.
  \item To satisfy modeling assumptions, for example if $y$ is not linearly related to $x$ but is linearly related to some transformation $g(x)$.
\end{itemize}

Now let's think about the predictors we have in this problem. The
distributions of all the non-indicator predictors are given in Figure
\ref{f:hist}.

Regarding the first item 1, I see no compelling reason to transform the
predictors for the sake of interpretability. True, a y-value with
respect to an ``age'' of 0, for example, will not be meaningful, but we
won't ever be predicting in this range anyway.

With respect to the second item above, there are some predictors with
very skewed distributions, so we could consider transforming them to
reduce the skewness. In particular, \texttt{btystdvariance},
\texttt{didevaluation}, and \texttt{students} are strongly right-skewed
and strictly positive, so we could consider log-transforming them.

We also have \texttt{btystdavepos}, which is strongly right-skewed, and
\texttt{btystdaveneg}, which is strongly left-skewed. However, both
these variables have a large number of values which are 0, so obviously
no deterministic transformation will change the fact that there are a
large number of instances with the same value. Since the rest of the
values are fairly spread out within their ranges, transformations won't
necessarily be useful.

With respect to the third item above, we'd need to fit the model and
then check whether the assumptions appear reasonable.

\begin{figure}
\centering
\includegraphics{hw05_solutions_files/figure-latex/2a-1.pdf}
\caption{Problem 2: Histograms of all non-indicator variables in the
beauty dataset.\label{f:hist}}
\end{figure}

\hypertarget{b}{%
\subsection{(b)}\label{b}}

I tried fitting the model with no transformations as well as with log
transformations of \texttt{btystdvariance}, \texttt{didevaluation}, and
\texttt{students}. The diagnostics for the former (Figure
\ref{f:diagnostics2}) looked slightly better than the latter, so I will
stick with the model with no transformations. The t-values and VIF
values are in Table \ref{t:t_vif}.

\begin{verbatim}
##    Length     Class      Mode 
##         1 knit_asis character
\end{verbatim}

\begin{longtable}[]{@{}lrr@{}}
\caption{Problem 2b: Table of t-values and Variance Inflation Factors
for the model coefficients.\label{t:t_vif}}\tabularnewline
\toprule
& t-value & VIF \\
\midrule
\endfirsthead
\toprule
& t-value & VIF \\
\midrule
\endhead
(Intercept) & 0.028 & 0.000000e+00 \\
age & 2.352 & 2.170000e+00 \\
beautyf2upper & 0.996 & 3.809736e+13 \\
beautyflowerdiv & -0.673 & 6.305091e+13 \\
beautyfupperdiv & 1.017 & 1.036440e+03 \\
beautym2upper & -1.067 & 1.239121e+14 \\
beautymlowerdiv & 0.207 & 7.168414e+13 \\
beautymupperdiv & 1.853 & 5.091113e+13 \\
blkandwhite & 0.222 & 1.899000e+00 \\
btystdave & -0.820 & 6.244059e+13 \\
btystdaveneg & -1.177 & 1.451961e+11 \\
btystdavepos & -1.177 & 1.856450e+11 \\
btystdf2u & -0.725 & 4.145703e+13 \\
btystdfl & 0.808 & 7.379827e+13 \\
btystdfu & 0.882 & 2.734726e+12 \\
btystdm2u & 1.167 & 1.300686e+14 \\
btystdml & -0.032 & 6.617188e+13 \\
btystdmu & -1.655 & 5.006012e+13 \\
btystdvariance & -0.642 & 1.699000e+00 \\
didevaluation & -1.201 & 4.525400e+01 \\
female & -1.205 & 2.286000e+00 \\
formal & 0.896 & 1.541000e+00 \\
fulldept & -0.197 & 1.772000e+00 \\
lower & 0.325 & 1.701000e+00 \\
minority & -1.318 & 1.578000e+00 \\
nonenglish & -1.674 & 1.497000e+00 \\
onecredit & 1.827 & 1.751000e+00 \\
percentevaluating & 2.443 & 2.685000e+00 \\
profevaluation & 48.783 & 1.379000e+00 \\
students & 1.105 & 5.096800e+01 \\
tenured & 0.449 & 2.720000e+00 \\
tenuretrack & -1.019 & 2.605000e+00 \\
\bottomrule
\end{longtable}

\begin{figure}
\centering
\includegraphics{hw05_solutions_files/figure-latex/2b_diagnostics-1.pdf}
\caption{Problem 2b: Diagnostics.\label{f:diagnostics2}}
\end{figure}

\begin{enumerate}
\def\labelenumi{(\alph{enumi})}
\setcounter{enumi}{2}
\item
  Using the rule of thumb that a VIF above 5 is high, many of the
  predictors have extremely high VIFs. If the purpose of the model is to
  perform inference on the coefficients, then you may wish to eliminate
  some of these predictors. If the purpose of the model is to generate
  accurate predictions, then you may wish to leave them in, though we
  would need to evaluate predictive performance on various subsets of
  predictors in order to make that decision.
\item
  The same issues considered in part (e) of the previous problem apply
  here. The two reasons to not consider \(t\)-statistics and VIF's alone
  are:

  \begin{itemize}
  \item $t$-statistics tell you about whether a variable has a coefficient significantly different from zero, {\em after} accounting for all of the other predictors.  If the variable with a non-significant $t$-statistic is collinear with another variable or group of variables, it is no obvious which (if any!) predictors to eliminate, without help from a subject matter expert.
  \item The $t$-statistic is being used in a hypothesis test of the hypothesis $H_0:~\beta=0$.  If the $t$-statistic is large, we have sufficient evidence to reject $H_0$. But if the $t$-statistic is small, it might be {\em either} because the $\beta$ really is zero, {\em or} because we don't have enough evidence (data) yet to rule out $\beta=0$. 
  \end{itemize}
\end{enumerate}

\end{document}
