Skip to content
Prev 312751 / 398506 Next

[mgcv][gam] Manually defining my own knots?

Hi Simon,

Thanks for your help.  I've got another question if you don't mind -- is 
it possible to "swap out" a set of coefficients of a gamObject in order 
to change the results when that gamObject is plotted?  The (silly) 
example below illustrates that this is possible with the Vp matrix.  But 
it is not working for me as I'd like it to for the coefficients.

library(mgcv)
#Random data
x = runif(1000,0,1)
y = (log(x^2)+x^3)/sin(x)
dumb.knots = c(.1,.2,.3)
dumb.example1 = gam(y~s(x,k=3),knots=list(x=dumb.knots))
plot(dumb.example1)

x = runif(1000,0,1)
y = (log(x^2)+x^3)/sin(x)
dumb.knots = c(.1,.2,.3)
dumb.example2 = gam(y~s(x,k=3),knots=list(x=dumb.knots))
plot(dumb.example2)

cbind(dumb.example1$coeff,dumb.example2$coeff)

averaged.models=(dumb.example1$coeff+dumb.example2$coeff)/2
correc = matrix(5,3,3)#5 is totally arbitrary, standing in for a proper 
MI correction
changed.vcv=correc+(dumb.example1$Vp+dumb.example2$Vp)/2

par(mfrow = c(1,2))
plot(dumb.example2,ylim=c(-500,200))
dumb.example2$coeff = averaged.models
dumb.example2$Vp = changed.vcv
plot(dumb.example2,ylim=c(-500,200))

The confidence bands expand but the location of the fit doesn't change!  
What part of the gamObject controls the plot of the smooth?
On 12/02/2012 02:15 AM, Simon Wood wrote: