#Problem 1 Y=c(2256,2340,2426,2293,2330,2368,2250,2409,2364,2379,2440,2364,2404,2317,2309,2328) x0=rep(1,16) x1=c(80,93,100,82,90,99,81,96,94,93,97,95,100,85,86,87) x2=c(8,9,10,12,11,8,8,10,12,11,13,11,8,12,9,12) X=cbind(x0,x1,x2) X%*%t(X) XTX=t(X)%*%X IXTX=solve(XTX) P=X%*%IXTX%*%t(X) hatbeta=IXTX%*%t(X)%*%Y X%*%hatbeta P%*%Y hate=P%*%y res=y-hate x=c(1,80,14) haty=x%*%hatbeta #Problem 4 install.packages("splines") library(splines) help(splines) library(help = "splines") help(bs) x=seq(0,1,by=0.01) BS=bs(x,knots=c(0.5),intercept=TRUE) plot(x,BS[,1]) plot(x,pmax(0,(1-2*x)^3)) #pointwise maximum dev.set(2) plot(x,pmax(0,(1-2*x)^3),col="red") pdf("BSplines.pdf") Colors=c("red","blue","green","brown","black") plot(x,BS[,1], col=Colors[1], type='l',ylab="",lwd=2) for(i in 2:5) { lines(x,BS[,i], col=Colors[i],lwd=2) } dev.off()