Prediction from gam model at X = 0 not equal to intercept I'm having a problem with GAM.  Specifically when I try to make a prediction at a new data value at the origin, my prediction is not equal to the intercept.  Can someone help me understand why this is happening?  Here is an example:
set.seed(42)
N = 1000
x = runif(N)
y = x^.22+rnorm(N)
m = gam(y~s(x))
summary(m)
predict(m,newdata = data.frame(x=0))

Family: gaussian 
Link function: identity 

Formula:
y ~ s(x)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.78115    0.03164   24.69   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Approximate significance of smooth terms:
       edf Ref.df     F  p-value    
s(x) 2.158  2.687 13.79 7.61e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

R-sq.(adj) =  0.0344   Deviance explained = 3.65%
GCV score = 1.0043  Scale est. = 1.0011    n = 1000
1> predict(m,newdata = data.frame(x=0))
        1 
0.3756038 

I think the prediction should be equal to the intercept when x = 0, but it's not!
 A: You think wrong since your are not considering the spline functions! Let's first evaluate the spline at your new data i.e. 0. To do that I will use the predict function but with the type argument as terms.
> spline.at.0=predict(m,newdata = data.frame(x=0), type = "terms")
> spline.at.0
        s(x)
1 -0.4055495
attr(,"constant")
(Intercept) 
  0.7811533 

Now lets look at the coefficients of your fitted model m
> coef(m)
  (Intercept)        s(x).1        s(x).2        s(x).3        s(x).4        s(x).5        s(x).6        s(x).7 
 7.811533e-01 -5.353668e-02  1.676821e-02 -3.391826e-05 -1.724044e-02 -4.702938e-03 -1.383030e-02 -3.876392e-03 
       s(x).8        s(x).9 
 1.009809e-01  2.413780e-01

So the first one is actually the intercept. When you use the predict function (without specifying exactly the type argument), it gives you by default  the linear predictor i.e. :
> predict.at.0=coef(m)[1]+spline.at.0
> predict.at.0
       s(x)
1 0.3756038
attr(,"constant")
(Intercept) 
  0.7811533 

Which is basically the same as:
> predict(m,newdata = data.frame(x=0))
        1 
0.3756038

I recommend you to see the help file ?predict.gam in package mgcv. BTW, you need to add the package you are using ... like require(mgcv) in your code since there are more than one package doing GAM.
