I am running a generalized additive model (GAM), but when I check the model diagnostics (using gam.check()
) I run into problems. I have tried adjusting the value of k
, but this isn't working. What am I missing?
Note that gam.check()
lets you see if the number of basis functions (k
) is appropriate (as per this OP). In my case, it shows that it is significant. I tried different values of k
to see what value of k
would give me a non-significant p-value, but it is always significant. Does this mean that the k
is appropriate or is there a different test to see if the k
value is appropriate for the smoothing term?
I'm using R
, version 3.6.1; mgcv
version 1.8-34; gamm4
version 0.2-6.
The data (called prime
) I used is available here.
Here is how my data frame is currently structured (first 6 rows):
ID DaysBeforeMigration AdultMass OffspringMass
A00001 59 59.52239 57.18145
A00002 61 143.8808 61.75128
A00002 63 147.7373 68.80916
A00002 61 143.8808 41.82444
A00002 63 147.7373 61.4211
A00002 61 143.8808 61.64883
Here is the code and packages to run my generalized additive model:
require(mgcv)
require(gamm4)
prime <- read.csv("MyData.csv”)
mod1 <- gamm4(OffspringMass ~ DaysBeforeMigration + s(AdultMass,
k=9), random=~(1|ID), data=prime)
Output:
> summary(mod1$gam)
Family: gaussian
Link function: identity
Formula:
OffspringMass ~ DaysBeforeMigration + s(AdultMass, k = 9)
Parametric coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 53.73208 3.88430 13.833 <2e-16 ***
DaysBeforeMigration 0.09548 0.07662 1.246 0.215
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Approximate significance of smooth terms:
edf Ref.df F p-value
s(AdultMass) 1.935 1.935 13.86 5.8e-06 ***
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
R-sq.(adj) = 0.231
lmer.REML = 830.06 Scale est. = 63.323 n = 109
Diagnostic output:
> gam.check(mod1$gam)
'gamm' based fit - care required with interpretation.
Checks based on working residuals may be misleading.
Basis dimension (k) checking results. Low p-value (k-index<1) may
indicate that k is too low, especially if edf is close to k'.
k' edf k-index p-value
s(AdultMass) 8.00 1.94 0.77 0.005 **
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Diagnostic figure code:
plot.gam(mod1$gam, residuals = TRUE, pch =1, cex = 1, shade =
TRUE, shade.col = "lightblue", seWithMean = TRUE,
pages = 1, all.terms = TRUE)
The diagnostic figures: