library(mgcv)
load("cosmos-processed.RData")
<- subset(all_sites, SITE_NAME=="Wytham Woods")
wwoods
<- gam(COSMOS_VWC ~ s(ndate, k=20), data=wwoods, method="REML")
b
plot(b)
Biomathematics and Statistics Scotland
UK Centre for Ecology and Hydrology
gam()
to fit a modelsummary()
to assess itplot()
to visualise it(Intercept) s(ndate).1 s(ndate).2 s(ndate).3 s(ndate).4 s(ndate).5
47.3525000 7.5801107 13.8527308 -4.1595358 -12.1449614 -3.0512930
s(ndate).6 s(ndate).7 s(ndate).8 s(ndate).9 s(ndate).10 s(ndate).11
-8.8018184 0.8292287 -6.1265129 -7.6962263 12.2316442 7.0850161
s(ndate).12 s(ndate).13 s(ndate).14 s(ndate).15 s(ndate).16 s(ndate).17
-5.2282569 3.6549750 -0.2188604 -0.3257381 9.7677258 7.0620897
s(ndate).18 s(ndate).19
18.6422253 -12.5062881
s(nday)
s(nday)
\(\pm 2\) standard errors
shift
ing to include the interceptRecipe:
predict()
to make predictions over the gridnewdata=
needs to have all the covariates in itpredict(b)
just gives us fitted valuespredict(..., se=TRUE)
gives standard errors
List of 2
$ fit : num [1:200(1d)] 48.2 48.1 48 47.9 47.9 ...
..- attr(*, "dimnames")=List of 1
.. ..$ : chr [1:200] "1" "2" "3" "4" ...
$ se.fit: num [1:200(1d)] 1.046 0.899 0.767 0.657 0.579 ...
..- attr(*, "dimnames")=List of 1
.. ..$ : chr [1:200] "1" "2" "3" "4" ...
summary()
predict()
and plot()
we can use unconditional=TRUE
From ⚡theory⚡ \(\boldsymbol{\beta} \sim \text{MVN}(\hat{\boldsymbol{\beta}}, \Sigma)\)
So, we can 🔮simulate🔮 from that distribution
Make lots of predictions
This generalizes very well, so we can make predictions of more than just smooths
Miller et al (2022) and Miller (2021) have more details
predict()
predict()
latertype=
argument changes the type of prediction
"response"
to put on the response scale"iterms"
to give per term predictions"lpmatrix"
for a prediction matrixplot
shows us basic plots
predict()
se.fit=TRUE
to get uncertainty
unconditional=TRUE
give us smoothing parameter uncertainty