One of the very first steps in using GLM for statistical modeling is to verify the assumption of linearity between all numerical predictors and the outcome. This could be done using a regression spline. A spline is the best smoother that can summarize a relationship between two variables. If it is close to a straight line, the assumption of linearity is verified. If it is monotonic, with only a slight curvature, the assumption can be accepted but the statistical power of the test of association between Y and Xi will be depreciated.
Using the retinol data we are interested to test whether there is a linear relationship between calories and retdiet (amount of retinol consumed):
using the package {mgcv}
>mod<-gam(retdiet~s(calories), data=retinol)
>plot (mod)
It can be observed that the relationship between amount of calories and amount of retinol consumed is not strictly linear.
now let us test the relationship between Y (concentration of plasmatic retinol) and X (amount of retinol consumed)
>plot (mod)
The relationship is clearly linear
*for logit or poisson models, you need to add the option family=binomial or family=poisson to the gam function.
#example
>mod<-gam(binaryvariable~s(age), data=dataset, family=binomial)
ref: Bruno Falissard (The analysis of questionnaire data using R)