Spatial data (x, y) is most often accompanied by spatial autocorrelation or locally different interactions between x & y. When I want to fit a parameter across space with generalized additive models and I am interested only in the long range effect of one spatial direction (e.g. x) is it valid to use the ti() tensor product interaction? What I am aiming to is to look for the main effect of x excluding a spatial autocorrelation effect or other local interaction between x and y. I am using the quantile version of gams out of the package qgam

b <- qgam(Response ~ ti(x)+ti(y)+ti(x,y)+s(some random factors,bs=”re”),qu=0.5) #0.5 for median

Can I say that interpreting the results from ti(x) represents the main effect or left-over effect excluding the interaction (or local correlation of x & y)? So the effect I see in ti(x) is taking out both the effect of y and the interaction / local correlation of x,y?

By increasing the number of k in the ti(x,y) can I account for smaller scale interactions / correlation of y & x on higher resolution?

And a final question related to that, is there a difference in this context using:

b <- qgam(Response ~ s(x)+s(y)+ti(x,y)+s(some random factors,bs=”re”),qu=0.5)

I know there are other methods like gamm which can add correlation terms for errors e.g. in this spatial context, but I need quantile estimates so qgam is mandatory.

-Or are there any other techniques with which I can accomplish that?



Yes, your interpretation is correct; s(x) + s(z) + ti(x,z) includes the main effects of x and z as separate terms from the interaction term ti(x,z), in the same sense as x + z + x:z would in an linear model.

From some tests I did a while back, ti(x) or s(x) in a model like

y ~ s(x) + s(z) + ti(x, z)

is close to the smooth effect of x averaged over the values of z. By that I mean say you fitted this model

y ~ te(x, z)

and then evaluated the smooth effect of x at a set of values for z from this model (using a grid of points x' and a very fine set of values for z, and then average the estimated smooth effect of x over z at each value of x') you would get something very close to s(x) in the first model.

I haven't quite worked out why there is more of a discrepancy than I would have expected, but this may just related to the first model not being exactly equal to the second model; there are more smoothness parameters in the first model than the second for example.

What you are doing seems valid to me.

Another option, which seems much more involved would be to fit the model with s(x, z, bs = 'tp') or s(x, z, bs = 'ds') or te(x, z). Create some vector of new values for x that you want to evaluate the model at, and combine it with a fine set of values for z. Then simulate from the model posterior at this grid of x and z points, and the average the predicted values over z for each value of x, yielding the average posterior effect of x.

Increasing k works as you say, up to a point; you're assuming that the effect of ti(x, z) is smooth so there becomes a point where increasing k will lead to a rough surface and the penalty will start to dominate the penalised likelihood of the model. If you have a large amount of data then you can have a k that is higher, but there's still some limit imposed by the definition of smoothness.

There isn't a difference between

y ~ s(x) + s(z) + ti(x, z)


y ~ ti(x) + ti(z) + ti(x, z)

At one time Simon Wood indicated that he didn't like having ti() work for single terms, but this warning seems to have been removed from the Changelog, so perhaps he has changed his mind about that.

| cite | improve this answer | |
  • $\begingroup$ Thank you very much for this extensive answer! May I ask a related question? If I am interested in the effect of e.g. temperature but want to account for spatial autocorrelation I would do: y ~ s(temp) + te(x,z). As temperature is also related to space some concurvity can be expected. If my focus is on the effect of temperature only, is something like y ~ s(temp) + ti(x,z) ( or y ~ s(temp) + s(x) +s(z) + ti(x,z,temp) ) more appropiate or would you recommend using te(x,z), but play around with the smoothing e.g. via k or sp in the te() term to reduce concurvity as estimated by concurvity(). $\endgroup$ – MriRo Sep 5 at 12:28
  • $\begingroup$ one add: when I am only interested in temp but not in direct effects of x,z; what about using: s(temp)+ti(temp,x,z) ;and then when predicting using predict(...exclude=c("ti(temp,x,z))? Is this valid? $\endgroup$ – MriRo Sep 6 at 17:50
  • $\begingroup$ Models like ~ s(temp) + te(x, z) are fine and the concurvity issue isn't as bad as you think; the smooth of temp is unlikely to look anything like the smooth of space and thus even though temperature is often spatially structured, the two smooth functions are identifiable up to a point. As with parametric terms, you shouldn't include an interaction without also including the main effects, so ~s(temp) + ti(x,z) is a non-starter, which also excludes the model in the second comment too. $\endgroup$ – Gavin Simpson Sep 7 at 17:23
  • $\begingroup$ thanks a lot again, I will go with the ~ s(temp) + te(x, z). If I am interested in the partial effect of Temp only, is there any difference in predicting with predict(...exclude=c("te(x,z)) or follow your suggestion of expanding a grid of parameter combinations, predict and then average over discrete Temperature groups? Or should this be the same with sufficiently large grid combinations? $\endgroup$ – MriRo Sep 7 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.