\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 04 Solutions},
            pdfborder={0 0 0},
            breaklinks=true}
\urlstyle{same}  % don't use monospace font for urls
\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 04 Solutions}
    \pretitle{\vspace{\droptitle}\centering\huge}
  \posttitle{\par}
    \author{}
    \preauthor{}\postauthor{}
      \predate{\centering\large\emph}
  \postdate{\par}
    \date{10/1/2018}

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

\begin{document}
\maketitle

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

\begin{enumerate}
\def\labelenumi{(\alph{enumi})}
\item
  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}

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

\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.13\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{(Intercept)}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.1943\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
7.777\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.02498\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.9801\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
\textbf{DrivingAccuracy}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.00353\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.01177\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.2998\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.7646\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
\textbf{GIR}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.1993\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.04382\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
4.549\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
9.658e-06\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
\textbf{PuttingAverage}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.4663\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
6.906\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.06752\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.9462\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
\textbf{BirdieConversion}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.1573\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.04038\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
3.897\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.0001355\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
\textbf{SandSaves}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.01517\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.009862\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
1.539\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.1256\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
\textbf{Scrambling}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.05151\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.03179\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
1.621\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.1068\strut
\end{minipage}\tabularnewline
\begin{minipage}[t]{0.27\columnwidth}\centering\strut
\textbf{PuttsPerRound}\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.3431\strut
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\centering\strut
0.4735\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
-0.7246\strut
\end{minipage} & \begin{minipage}[t]{0.13\columnwidth}\centering\strut
0.4696\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

\begin{longtable}[]{@{}cccc@{}}
\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
196\strut
\end{minipage} & \begin{minipage}[t]{0.27\columnwidth}\centering\strut
0.6639\strut
\end{minipage} & \begin{minipage}[t]{0.11\columnwidth}\centering\strut
0.5577\strut
\end{minipage} & \begin{minipage}[t]{0.20\columnwidth}\centering\strut
0.5412\strut
\end{minipage}\tabularnewline
\bottomrule
\end{longtable}

\begin{figure}
\centering
\includegraphics{hw04_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{hw04_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
  Remember 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}

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}}
  {\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}

I will note that it is not entirely obvious here what ``the relative
importance of each different aspect of the game'' means, mathematically.
If it refers to the magnitude of coefficients in a linear regression
model, then we will have to accept that due to collinearity, the
estimates for some of these coefficients will not be stable. If it
refers to the relative importance in a predictive model generally, then
we should optimize the model for predictive performance and not worry
about hypothesis tests. If it refers to a causal relationship between
different aspects of the game and prize money, then we need tools from
causal inference, which do not come for free in an observational study.

\section{2.}\label{section}

\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{hw04_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}

\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\tabularnewline
\midrule
\endfirsthead
\toprule
& t-value & VIF\tabularnewline
\midrule
\endhead
(Intercept) & 0.028 & 0.000000e+00\tabularnewline
age & 2.352 & 2.170000e+00\tabularnewline
beautyf2upper & 0.996 & 3.809736e+13\tabularnewline
beautyflowerdiv & -0.673 & 6.305091e+13\tabularnewline
beautyfupperdiv & 1.017 & 1.036440e+03\tabularnewline
beautym2upper & -1.067 & 1.239121e+14\tabularnewline
beautymlowerdiv & 0.207 & 7.168414e+13\tabularnewline
beautymupperdiv & 1.853 & 5.091113e+13\tabularnewline
blkandwhite & 0.222 & 1.899000e+00\tabularnewline
btystdave & -0.820 & 6.244059e+13\tabularnewline
btystdaveneg & -1.177 & 1.451961e+11\tabularnewline
btystdavepos & -1.177 & 1.856450e+11\tabularnewline
btystdf2u & -0.725 & 4.145703e+13\tabularnewline
btystdfl & 0.808 & 7.379827e+13\tabularnewline
btystdfu & 0.882 & 2.734726e+12\tabularnewline
btystdm2u & 1.167 & 1.300686e+14\tabularnewline
btystdml & -0.032 & 6.617188e+13\tabularnewline
btystdmu & -1.655 & 5.006012e+13\tabularnewline
btystdvariance & -0.642 & 1.699000e+00\tabularnewline
didevaluation & -1.201 & 4.525400e+01\tabularnewline
female & -1.205 & 2.286000e+00\tabularnewline
formal & 0.896 & 1.541000e+00\tabularnewline
fulldept & -0.197 & 1.772000e+00\tabularnewline
lower & 0.325 & 1.701000e+00\tabularnewline
minority & -1.318 & 1.578000e+00\tabularnewline
nonenglish & -1.674 & 1.497000e+00\tabularnewline
onecredit & 1.827 & 1.751000e+00\tabularnewline
percentevaluating & 2.443 & 2.685000e+00\tabularnewline
profevaluation & 48.783 & 1.379000e+00\tabularnewline
students & 1.105 & 5.096800e+01\tabularnewline
tenured & 0.449 & 2.720000e+00\tabularnewline
tenuretrack & -1.019 & 2.605000e+00\tabularnewline
\bottomrule
\end{longtable}

\begin{figure}
\centering
\includegraphics{hw04_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
  Table \ref{t:t_vif2} contains the t-values and VIF values for a model
  with \texttt{profevaluation} as the dependent variable. The VIFs are
  virtually unchanged, which is unsurprising: the VIF for a given
  predictor is calculated by regressing that predictor on all the other
  predictors, so we wouldn't expect the results to change much when we
  swap out one predictor among a large set of variables.
\end{enumerate}

The t-values, on the other hand, are quite different, which is also not
surprising. However, I would only rarely use the t-values to inform
variable selection. Since the VIFs haven't changed much, the decision
about which variables to include or exclude wouldn't change either.

\begin{longtable}[]{@{}lrr@{}}
\caption{Problem 2d: Table of t-values and Variance Inflation Factors
for the model coefficients.\label{t:t_vif2}}\tabularnewline
\toprule
& t-value & VIF\tabularnewline
\midrule
\endfirsthead
\toprule
& t-value & VIF\tabularnewline
\midrule
\endhead
(Intercept) & 1.161 & 0.000000e+00\tabularnewline
age & -3.341 & 2.065000e+00\tabularnewline
beautyf2upper & -2.509 & 3.709393e+13\tabularnewline
beautyflowerdiv & -0.313 & 6.494636e+13\tabularnewline
beautyfupperdiv & 0.029 & 1.030650e+03\tabularnewline
beautym2upper & 0.854 & 1.291947e+14\tabularnewline
beautymlowerdiv & -0.209 & 6.765920e+13\tabularnewline
beautymupperdiv & -2.479 & 4.698856e+13\tabularnewline
blkandwhite & 1.429 & 1.911000e+00\tabularnewline
btystdave & 0.686 & 6.036691e+13\tabularnewline
btystdaveneg & 1.052 & 1.425207e+11\tabularnewline
btystdavepos & 1.052 & 1.800745e+11\tabularnewline
btystdf2u & 2.209 & 4.065001e+13\tabularnewline
btystdfl & 0.144 & 7.463179e+13\tabularnewline
btystdfu & -0.744 & 2.662346e+12\tabularnewline
btystdm2u & -0.939 & 1.360663e+14\tabularnewline
btystdml & 0.063 & 6.231129e+13\tabularnewline
btystdmu & 2.319 & 4.603067e+13\tabularnewline
btystdvariance & 1.056 & 1.704000e+00\tabularnewline
courseevaluation & 48.783 & 1.407000e+00\tabularnewline
didevaluation & 0.984 & 4.533100e+01\tabularnewline
female & -0.936 & 2.289000e+00\tabularnewline
formal & -0.002 & 1.545000e+00\tabularnewline
fulldept & 0.700 & 1.770000e+00\tabularnewline
lower & -0.344 & 1.699000e+00\tabularnewline
minority & 0.684 & 1.589000e+00\tabularnewline
nonenglish & 0.429 & 1.506000e+00\tabularnewline
onecredit & -0.173 & 1.767000e+00\tabularnewline
percentevaluating & -1.733 & 2.698000e+00\tabularnewline
students & -0.926 & 5.105800e+01\tabularnewline
tenured & 0.002 & 2.811000e+00\tabularnewline
tenuretrack & 0.002 & 2.615000e+00\tabularnewline
\bottomrule
\end{longtable}


\end{document}
