INTERPRETATION OF GRAPHIC RESULTS OF GAM IN R Hello I am trying to adjust a GAM in R. I am new to GAM and I am trying to see the relationship that can exist through time in 57 river stations that are divided into Impacted and not previously Impacted. There are several variables to measure Wtemp, pH, TN, DOconc, which are nutrients that are evaluated in each of these river stations.
I have been reading and implementing the following model:
m = gam(Wtemp ~  Impacted + s(Year, bs= "ps") + 
    s(Year, by= Impacted)+ s(Stnumber, bs="re") + 
    s(Year,Stnumber, bs="fs"), data = X)

where:

Wtemp = is temperature (I understand there shouldn't be a big change
  there)
Year = numeric year variable Stnumber = categorical variable of the
  river station Impacted = categorical variable of Impact or no Impact

I understand (if not hope corrections if possible) that I am adding the random effect of the river station (stnumber) and the random effect of the interaction of stnumber for the year (I put fs because in readings they recommend that when there are many levels it is better to place this)
The summary the this model is:

I understand that there show me the significance of the estimated curves, but the view graphs and confidence intervals in all includes zero even though the summary tells me that is significantly different from a line.



If someone can clarify the following questions:
1. It is correct that I am adding random effect for Stnumber and the interaction between Stnumber and year.
2. These graphs where the year appears by the impact is the interaction between these two representing me?
3. There is a way to see the difference between impacted and n or impacted curves.
I would appreciate any help, thanks.
 A: Q0
If you look closely at the plot for the s(Year) term, you'll see it doesn't actually include 0 everywhere, e.g. the local peak around ~2000.
You likely want m = 1 on the s(Year, by = Impacted, m = 1) smooths or perhaps select = TRUE. A smooth + group smooth of the same variable can get highly concurved and the model may not be identifiable. Changing the penalty to be on the integrated squared first derivative (i.e. penalising deviations from a flat function) can help make the model identifiable. Adding extra penalties can help also.
Q1
You can have + s(Stnumber, bs="re") + s(Year, Stnumber, bs="fs") but it is redundant as the factor smooth term already includes the random intercept. If you don't really need to separate out these effects then just use the random factor-smooth one (the `bs = 'fs' one).
Q2
These by factor smooths are the interaction between a basis expansion (smooth) and a factor covariate, but the exact interpretation is not immediately clear when you have a global effect and a separate effects of Year by groups. You can parameterise these models in many ways; one is the m = 1 point I made above. The other is to turn Impacted into an ordered factor and then fit the model:
Wtemp ~  Impacted +
  s(Year, bs= "ps") +        #1
  s(Year, by = Impacted) +   #2
  s(Year,Stnumber, bs="fs")

where mgcv sets this up as a smooth of Year for the reference level (line #1) and then a difference smooth between the reference and the other level (line #2)
Q3
There are ways to visualise the differences between by factor smooths. This Answer has some pointers.
