\documentclass[fleqn]{book} %\usepackage{times} %\usepackage{chicago} %\input dbp-book.sty \input 312HW.sty \def\betatilde{\widetilde\beta} \def\Ztilde{\widetilde Z} \def\Ytilde{\widetilde Y} \def\yhat{\widehat y} \def\rank{\text{rank}} \def\xbar{\bar x} \def\ybar{\bar y} \def\Btilde{\widetilde B} \def\bhat{\widehat b} \def\ghat{\widehat g} %\pagewidth{5.5in} \voffset-1in \hoffset0.5in \topmargin0pt \textheight 600pt \textheight 650pt \def\taa{widetilde\aa} \def\corr{\text{corr}} \begin{document} %knit("homework4.Rnw",quiet=T) <>= BC.coeff <- function(out,digits=1){ coeff <- summary(out)$coeff[,1:2] dd <- dimnames(coeff) dd[[1]] <- gsub("(p|t)\\K[a-z]*","",dd[[1]],perl=T) dd[[2]] <- c("Est","StdErr") dimnames(coeff) <- dd print(out$call) print( t(coeff),digits ) } @ \HW{4}{Monday 3 October} \problem[cath] The catheter data set is taken from a well known text book. If you happen to know the book please do not just repeat the analysis it presents. <<>>= cath <- read.table("catheter.txt",header=T) outHW <- lm(distance ~ height + weight,cath) outH <- lm(distance ~ height, cath) outW <-lm(distance ~ weight, cath) cath[1:3,] @ The summary information for each fit (\verb!outHW!, \verb!outH!, \verb!outW!) seems to suggest that height by itself is a good predictor of distance, that weight by itself is a good predictor of distance, but when both predictors are used then neither is particularly useful. (The stars in the summary table suggest `significance'.) \ppart (15 points) Add more variables to the cath data.frame: height and weight centered to zero means (call them hcen and wcen); and things like \verb!wres <-lm(wcen~ hcen, cath)$res!. Explain why some of the coeffs and std. errors are the same and some are different for the models: \begin{verbatim} distance ~ height distance ~ hcen distance ~ hcen + wres distance ~ height+wres distance ~ hcen+wcen distance ~ height+weight \end{verbatim} \ppart (5 points) Explains why \verb!summary(outHW)! is misleading regarding the value of \verb!height! and \verb!weight! as predictors. %<<>>= %source("cath.R") %@ \ppart (5 points) Explain how the output from \verb!cor(cath)! is relevant to the problem. \problem[reparam] The handout two\_factors.pdf showed how to calculate several least squares fits using the Box-Cox data: <<>>= BC <- read.table("../Handouts/boxcox.data", header=T,sep="\t") BC$rate <- 1/BC$time # transformation suggested by BHH page 235 BC$Htreatment <- C(BC$treatment,helmert) out5 <- lm(rate ~ -1 + treatment,BC) out7 <- lm(rate ~ Htreatment,BC) @ In class I showed (page~9 of the handout) how to transform results from one parametrization into results for a different parametrization, using \verb!out5! and \verb!out6! as an example. For this homework problem I want you to recreate the shortened summary <>= BC.coeff(out5,3) @ \noindent using only the information contained in \verb!out7!, which is essentially the same as the~\verb!out9! generated by: <<>>= C7 <- contrasts(BC$Htreatment) dummyT <- outer(BC$treat,levels(BC$treat),"==")+0 X7 <- cbind(1, dummyT %*% C7) out9 <- lm(BC$rate ~ -1+X7) @ Display all the \Rlang/ code that you use. \ppart (5 points) Show that \verb!X7! is equal to \verb!dummyT %*% K7! where \verb!K7 <- cbind(1,C7)!. \ppart (10 points) If $\ghat$ is the vector of coefficients from \verb!out7! and $\bhat$ is the vector of coefficients from \verb!out5!, show that $\bhat=K_7 \ghat$. \ppart (10 points) Use (ii) and \verb!out7! to recreate the shortened summary for \verb!out5!. \References \end{document}