\documentstyle[bj,txfonts]{article}

\frenchspacing
\def\vtrim{\vspace*{-0.8em}}

\begin{document}

\begin{center}
\Large
36-617: Applied Linear Models\\
Fall 2021\\
HW03 -- Due Mon Sept 20, 11:59pm
\end{center}

\begin{itemize}\parsep=0pt\itemsep=0pt\parskip=0pt

\item Please turn the homework in online in our course webspace at canvas.cmu.edu.
\begin{itemize}
\item There is a link to Gradescope in the description of this assignment on Canvas. 
\item You should submit a single pdf to Gradescope. If you need help with this, please see \\ https://www.cmu.edu/teaching/gradescope/index.html.  Also, allow yourself some extra time to create the pdf \& upload it in Gradescope.
\item Gradescope allows the TA to grade all the problem 1's together, then all the problem 2's, and so forth.  This leads to more consistent grading and better comments for you.
\end{itemize}

\item Reading:
\begin{itemize}

\item You should have read Chapter 3 in Sheather for this week. We are skipping Sheather Ch 4 for now, and proceeding to Ch 5, for next week.

\end{itemize}

\item There are five exercises; the first four are all related.\\[-2em]

\end{itemize}


\section*{Exercises}

\begin{enumerate} % \itemsep=0pt\parsep=0pt\parskip=0pt


\item{} [Based on Sheather, Ch 3, \# 5, pp. 109ff.] An analyst for the auto industry has asked for your help in modeling data on the prices of new cars. Interest centers on modeling suggested retail price as a function of the cost to the dealer for 234 new cars. The data set, which is available in the file {\tt cars04.dat} in the same folder as this hw, is a subset of the data described at {\tt http://www.amstat.org/publications/jse/datasets/04cars.txt}.  You can read the data into R with a command like {\tt data <- read.table(cars04.dat,header=T)}.

There are many interesting variables in this data set, but we are only interested in two, for now: \\{\tt SuggestedRetailPrice}, and {\tt DealerCost}.  

\begin{enumerate}


\item Provide a good initial description of the data {\em (This would be, essentially, the {\bf Data} section of an IDMRAD paper, minus a description of where the data came from)}.  This should include
\begin{itemize}
\item A table with the names and definitions of all variables in the data set.
\item The number of observations (rows) and variables (columns).
\item A brief discussion of whether there is any missing data, and if so, how much and where.
\item An appropriate summary of each individual variable.  This might consist of means and standard deviations, and/or boxplots, and/or histograms, for example.
\item Scatterplots (perhaps in a scatterplot matrix) of all the pairs of variables.
\end{itemize}
Since our only interest for now is in {\tt SuggestedRetailPrice} and {\tt DealerCost}, it would be useful to include an additional, separate description of those two variables.

\item\label{i:linmodel} Fit the model 
\[
    \mbox{SuggestedRetailPrice} = \beta_0 + \beta_1\mbox{DealerCost} + \varepsilon
\]
Provide a {\tt summary()} of the model, and also the four casewise residual diagnostic plots.  Write five sentences:
\begin{itemize}
\item One sentence for each of the four diagnostic plots, indicating the main feature of each, and whether this feature indicates good or bad fit of the model to the data; and
\item One more sentence comparing your conclusions here with the description of the two variables \\ {\tt SuggestedRetailPrice} and {\tt DealerCost} from part (a).
\end{itemize}

\end{enumerate}

\item{} [Continuing problem \#1: Box-Cox transformations]

\begin{enumerate}

\item Now explore power transformations of our two variables using {\tt boxCox()} and {\tt powerTransform()} from {\tt library(car)}.
\begin{enumerate}
\item Find the Box-Cox transformation for {\tt DealerCost}.
\item Construct a new variable {\tt TransCost} that is the transformation of {\tt DealerCost} you found.  Fit the regression ${\tt SuggestedRetailPrice} = \beta_0 + \beta_1 {\tt TransCost} + \varepsilon$, and use this to find the Box-Cox transformation for {\tt SuggestedRetailPrice}.
\end{enumerate}

\item\label{i:boxcox} Fit the model 
\[
    \mbox{TransPrice} = \beta_0 + \beta_1\mbox{TransCost} + \varepsilon
\]
Provide a {\tt summary()} of the model, and also the four casewise residual diagnostic plots.  Write five sentences:
\begin{itemize}
\item One sentence for each of the four diagnostic plots, indicating the main feature of each, and whether this feature indicates good or bad fit of the model to the data.
\item One more sentence indicating whether you are happy with the fit of the model to the power-transformed data.
\end{itemize}

\end{enumerate}

\item{}\label{i:log} [Continuing problem \#1: log transformations]

\begin{enumerate}

\item[] Now fit the model suggested by Sheather, 
\[
    \mbox{log(SuggestedRetailPrice)} = \beta_0 + \beta_1\mbox{log(DealerCost)} + \varepsilon
\]
rovide a {\tt summary()} of the model, and also the four casewise residual diagnostic plots.  Write five sentences:
\begin{itemize}
\item One sentence for each of the four diagnostic plots, indicating the main feature of each, and whether this feature indicates good or bad fit of the model to the data.
\item One more sentence indicating whether you are happy with the fit of the model to the log-transformed data.
\end{itemize}

\end{enumerate}

\item{} [Continuing problem \#1: comparisons and conclusions]

\begin{enumerate}

\item All of these models---(\ref{i:linmodel}), (\ref{i:boxcox}), and (\ref{i:log})---have incredibly high $R^2$.  For which model are the assumptions of linear regression best satisfied, based on your analyses above?

\item Complete each sentence below, or explain why it is difficult to complete:
\begin{itemize}
\item For the model in (\ref{i:linmodel}), a \rule{1in}{0.01in} increase in {\tt DealerCost}  results in a  \rule{1in}{0.01in} increase in the expected value of {\tt SuggestedRetailPrice}.  
\item For the model in (\ref{i:boxcox}), a \rule{1in}{0.01in} increase in {\tt DealerCost}  results in a  \rule{1in}{0.01in} increase in the expected value of {\tt SuggestedRetailPrice}.  
\item For ~ the ~ model ~ in (\ref{i:log}), a \rule{1in}{0.01in} increase in {\tt DealerCost}  results in a  \rule{1in}{0.01in} increase in the expected value of {\tt SuggestedRetailPrice}.  
\end{itemize}
(You may want to consult the file ``{\tt log xform and percent interpretation.pdf}'' in the week03 folder in our files area on canvas.)

\item Which model---(\ref{i:linmodel}), (\ref{i:boxcox}), or (\ref{i:log})---would you use if you were the statistical consultant on this project?  Why?

\end{enumerate}

\clearpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\item{} [Based on Gelman \& Hill. Ch 3, \#1, p. 49] The file {\tt pyth.dat}, in the same folder as this hw,  contains outcome {\tt y} and inputs {\tt x1}, {\tt x2} for 40 data points, with a further 20 points with the inputs but no observed outcome (for this problem we will ignore these last 20 points). Save the file to your working directory and read it into R using the {\tt read.table()} function.

\begin{enumerate}

\item Fit the two models
\begin{eqnarray*}  
	{\bf M1:~} {\tt y} & = & \beta_0 + \beta_1 {\tt x1} + \varepsilon \\
	{\bf M2:~} {\tt y} & = & \beta_0 + \beta_1 {\tt x2} + \varepsilon 
\end{eqnarray*}
Which model provides a better fit for {\tt y}?  Why?

\item Construct new variables {\tt y2 = y$^2$}, {\tt x12 = x1$^2$}, and {\tt x22 = x2$^2$} and fit the models
\begin{eqnarray*}  
	{\bf M3:~} {\tt y2} & = & \beta_0 + \beta_1 {\tt x12} + \varepsilon \\
	{\bf M4:~} {\tt y2} & = & \beta_0 + \beta_1 {\tt x22} + \varepsilon 
\end{eqnarray*}
Compare the fits of these two models to the models in part (a).  Which fits best?  Why?

\item To fit the model 
\[
	{\tt y2} ~ = ~ \beta_0 + \beta_1 {\tt x1} + \beta_2 {\tt x2} + \varepsilon ~,
\]
we just expand the R modeling language a little bit: \verb|y ~ x1 + x2|.  Fit both of the models
\begin{eqnarray*}
	{\bf M5:~} {\tt ~y} & = & \beta_0 + \beta_1 {\tt x1} + \beta_2 {\tt x2} + \varepsilon \\
	{\bf M6:~} {\tt y2} & = & \beta_0 + \beta_1 {\tt x12}  + \beta_2 {\tt x22} + \varepsilon 
\end{eqnarray*}
Compare these to the earlier models.  Which fits best?  Why?

\item Can you find a simple, recognizable function {\tt x3 = (something involving both x1 and x2)}, so that 
\[
		{\bf M7:~} {\tt y} ~ = ~ \beta_0 + \beta_1 {\tt x3} + \varepsilon
\]
provides a fit comparable to the best fitting models above?  What is going on?




\end{enumerate}


\end{enumerate}

\end{document}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
