DESCRIPTION Students: This is a group quiz. You are allowed to talk to your teammates (but no one else), use the Internet and so on. To get credit, you MUST be logged in under an e-mail address of the form ajones@ucdavis.edu_jsmith@ucdavis.edu_gyu@ucdavis.edu where the individual components must EXACTLY MATCH what you have been using in the quizzes. QUESTION -ext .R -run 'Rscript omsi_answer1.R' (50 pts, code) Recall that "ridge regression" fits a linear model but with an "l2" penalty: Instead of minimizing (3.6), we minimize (D - Ab)'(D - Ab) + s b'b. One can show that this is done by replacing A'A in (3.11) by A'A + s I. Write code to implement this. The call form will be ridgelm(xy,s) and it will return b, the vector of coefficients. Here xy is a matrix with the response variable in the last column and the predictors in the other columns. Hint: You may find useful R's solve() and diag() functions. ridgelm<- function(xy,s) { } d <- cbind(c(5,1,2,8),c(0,2,2,1),c(8,3,4,2)) print(ridgelm(d,0.2)) # [,1] # [1,] 6.5701554 # [2,] -0.1712036 # [3,] -1.5710789 QUESTION -ext .R -run 'Rscript omsi_answer2.R' This problem concerns Sec. 6.2.2.1 of our book. You will develop general code that adds a new covariate like the "average rating in service courses" example. # rsdf: a data frame in the standard (userID, itemID, rating, covs) format # idCol: column number in rsdf of the grouping ID, either user or item ID # dummyCol: dummy variable on which average rating is to be found # returns copy of rsdf, with an exra column: for a given row (u,i,r,covs), # the value of the new column will be the mean rating given by user u among # all rows for which the given dummy is 1 makeAvgCov <- function(rsdf,idCol,dummyCol) { dm <- as.numeric(rsdf[,dummyCol]) rsdf.sub <- rsdf[dm == 1,] id <- as.character(rsdf[,idCol]) meanNoNA <- function(x) mean(x,na.rm=T) tmp <- tapply( ) newCol <- cbind(rsdf,newCol) } library(rectools) getInstEval() ivl15 <- ivl[1:15,] makeAvgCov(ivl15,1,6) # new col in above return value should be 4 2.5s, then 2 NAs, then 9 3.333s