I am creating a varying-coefficient GAMM using 'mgcv' in R with a continuous 'by' variable by using the by
setting. However, I am having difficulty in locating the parameter estimate of the effect of the 'by' variable. In this example we determine the spatially-dependent effect of temperature t
on sole eggs (i.e. how the linear effect of temperature on sole eggs changes across space):
require(mgcv)
require(gamair)
data(sole)
b = gam(eggs ~ s(la,lo) + s(la,lo, by = t), data = sole)
We can then plot the predicted effects of s(la,lo, by = t)
against the predictor t
:
pred <- predict(b, type = "terms", se.fit =T)
by.variable.prediction <- pred[[1]][,2]
plot(x= sole$t, y = by.variable.prediction)
However, I can't find a listing/function with the parameter estimates of the 'by' variable t
for each sampling location. summary()
, coef()
, and predict()
do not give you the parameter estimates.
Any help would be appreciated!
?mgcv::s
, specifically the description ofby
. Ift
is numeric then the value oft
multiplies the smooth. Ift
is a factor then there is a separate smooth for each level of the factor. If you want to extract the smooths themselves (I wouldn't recommend it... don't see what use they'd be), this might help. – Gregor Thomasmgcv::s
and it doesn't really give you much. With a numerict
predictor, in my case, we are assuming a linear relationship who's slope could change acrossla,lo
, so for each uniquela,lo
we get a specific slope, correct? Then I should be able to find the magnitude and direction of that slope somewhere, it's just being elusive :). I don't want to extract the smooths, just want to plot that variable-coefficient term using those slopes. – Grant Adamsla
andlo
, there is a smoothed value that gets multiplied byt
. There isn't anything else. This is what the documentation states. You can interprett
as the "slope" of the smoothedla,lo
variable, or you can interpret thela,lo
smooth as the slope oft
. – Gregor Thomas