 # Generalized Additive model Regression

Hallo All,

I am trying to fit a GAM regression to my data. However I have a question. So for instance if I have
Y = S(A) + S(B) as my GAM model,
Can I include a linear model of one variables, say B to the model. So that I get
Y = S(A) + B +S(B).
I do this because I want to obtain point estimates for the variable B. In that case how would this affect the interpretation of the smooth function. Can I say my smooth function S(B) shows the deviation from my average point estimates?

I would appreciate your support

What do you mean by point estimates for the variable B ? can you give an example ?

For instance in the model below, I have modelled debtratiolagged as both parametric and a smooth non parametric term in the code below.

``````# mod10 <- gam(psratio ~ Gvar  +  Yvar + debtratiolagged + s(debtratiolagged), data = d_data)
# plot(mod10)
``````

Specifically My question has to do with the interpretation of the above graph. Since I have included debtratiolagged also as a parametric term in the regression, would this affect the interpretation of the y-axis of the smooth function?

I don't have your data, so lets discuss with common data in a artificially 'simple' example.
I often produce my own datasets to test my understanding on concepts.
Here is an example.

``````set.seed(42)

d <- data.frame(
x = 1:500,
y = .3*1:500 + 500 + ((1:500)^2)/100 +sample(
-150:150,size=500,replace=TRUE)
)

plot(d\$x,d\$y)

library(mgcv)

(gam1 <- mgcv::gam(y ~ s(x),data = d,method = "REML"))
(s1 <- summary(gam1))
par(mfcol=c(2,2))
gam.check(gam1)
plot(gam1)

(gam2 <- mgcv::gam(y ~ x + s(x),data = d,method = "REML"))
(s2 <- summary(gam2))
par(mfcol=c(2,2))
gam.check(gam2)
plot(gam2)
``````

Thank you for the feedback @nirgrahamuk. So my question is, how would you interpret the plot of gam2 (since we have now added a parametric term of x)?

I feel a bit out of my condifent zone here, but playing around, I think the following is rough but gives some insight. taking the previous code for granted.
What if we define a separate varaible z, to capture the higher order relationship of the poly x order 2.
If we fit the gam with x +s(z) where s(z) is some smoothed x^2 pure function with no linear term...
I can compare the plot(gam2) which is the y~x+s(x) with my hand plot of x by an approximate f(x,order 2) function) and I think its a close enough match.

Hopefully someone else can way in.

``````
d\$z <-((d\$x-300)^2)/150 -200

(gam3 <- mgcv::gam(y ~ x + s(z),data=d,method="REML"))
(s3 <- summary(gam3))
par(mfcol=c(2,2))
plot(gam3,all.terms = TRUE)

par(mfcol=c(1,2))
plot(gam2)
plot(d\$x,d\$z)``````

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.