memy memy - 1 month ago 14
R Question

mgcv: How to set number and / or locations of knots for splines

I want to use function

gam
in
mgcv
packages:

x <- seq(0,60, len =600)
y <- seq(0,1, len=600)
prova <- gam(y ~ s(x, bs='cr')


can I set the number of knots in
s()
? and then can I know where are the knots that the spline used? Thanks!

Answer

knots are k

gam(y ~ s(x, bs='cr', k=5))

if you want the number of knots to be fixed, then

gam(y ~ s(x, bs='cr', k=5, fx=TRUE))
Comments