hw5_R -...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
abalone=read.table("http://www- stat.stanford.edu/~hastie/stats305/Data/abalone.305",sep=",",head=T,row.names=1) attach(abalone) tps=function(x,knots,d=3){ B1=outer(x,1:d,"^") B2=outer(x,knots,"-")^d B2[B2<0]=0 cbind(1,B1,B2) } cB=function(B,C){ qrC=qr(t(C)) qC=qr.Q(qrC,complete=T)[,-seq(nrow(C))] B%*%qC } pdf(file="hw5_plots.pdf") Rings.grid=seq(from=0,to=25,by=.1) fit1=lm(Shucked.wt~tps(Rings,knots=c(5,10,15,20),d=1)-1) plot(Rings,Shucked.wt,xlim=c(0,25),ylim=c(-.5,1.4),main="Linear Spline") matlines(Rings.grid,predict(fit1,list(Rings=Rings.grid),interval="conf"),col=1,lty= c(1,2,2)) abline(v=c(5,10,15,20),lty=2) abline(h=0) fit2=lm(Shucked.wt~tps(Rings,knots=c(5,10,15,20))-1) plot(Rings,Shucked.wt,xlim=c(0,25),ylim=c(-.5,1.4),main="Cubic Spline") matlines(Rings.grid,predict(fit2,list(Rings=Rings.grid),interval="conf"),col=1,lty= c(1,2,2)) abline(v=c(5,10,15,20),lty=2) abline(h=0) C1=rbind( c(0,1,0,0,0,0), c(0,0,1,1,1,1) ) fit3=lm(Shucked.wt~cB(tps(Rings,knots=c(5,10,15,20),d=1),C1)-1)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 11/14/2010.

Page1 / 2

hw5_R -...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online