Download pptx - Recitation 2 April 23

Transcript
Page 1: Recitation 2 April 23

RECITATION 2APRIL 23

Natural Cubic SplinesPenalized Cubic Regression Splines

Page 2: Recitation 2 April 23

Natural Cubic Splines

• sm.spline() in library “pspline”• How to choose a smoothing parameter

• by OCV score: sm.spline(x= , y= , cv= TRUE)• by GCV score: sm.spline(x= , y= , cv= FALSE)

• R demo 1

Cubic splines

NCS -- linearity beyond boundary

Page 3: Recitation 2 April 23

Penalized Cubic Regression Splines

• gam() in library “mgcv”

• gam( y ~ s(x, bs=“cr”, k=n.knots) , data = dataset)

• Find the optimal smoothing parameter• By default, only select smoothing parameter by GCV score

• R demo 2