I want to set up manually some knots locations in the gam function that uses a tensor product.
For example :
set.seed(0)
n <- 500
x <- runif(n)
z <- runif(n)
y <- runif(n)
gam(y ~ te(x, z), knots = list(x = c(0.2, 0.5, 0.8), y=c(0.2, 0.5, 0.8)))
But I have this error :
Error in smooth.construct.cr.smooth.spec(object$margin[[i]], dat, knt) :
number of supplied knots != k for a cr smooth
I tried to add a k value in the tensor, but the error is still the same How can I solve this ? Thank you for your help.
The knot locations you specify via
knotsand the number of basis functionskmust be compatible. In your example, the defaults were used forkwhich IIRC is to havek = c(5,5)for a 2d tensor product.If you want to use the knot locations you specified then you need to set
klower than this: