# How to construct an optimal spline model when two continuous independent variables are included

I am interested in evaluating the relationship between age, BMI and lipid level. The lipid level is an outcome in my study. I think that the relationship between lipid level and age and the relationship between lipid level and BMI may be non-linear, respectively. Therefore, I would like to apply restricted cubic splines into the age and BMI in the rms package of R

In this case, I have to consider how many knots should be used for each of the two splines, one for age and the other for BMI (and moreover, I have to decide the position of the knots).

As a solution to this issue, I am thinking of implementing the following commands to determine how many knots are optimal for age and BMI, respectively, changing the number of knots and adopting the model with the lowest AIC.

mod <- ols(lipid~rcs(age,num_knot_age)+rcs(BMI,num_knot_BMI),data=dat);

Is there any other better way to do this? I would appreciate your advice.

• There is quite a bit of discussion of this in Frank Harrell's book "Regression Modelling Strategies". (He is the author of the rms package that has these functions). Commented Jan 27 at 11:05

To expand on the comment from Peter Flom, Chapter 2 of Frank Harrell's online Regression Modeling Strategies provides specific guidance. Section 2.4.6 says:

Locations not important in most situations

Place knots where data exist — fixed quantiles of predictor’s marginal distribution

The latter is the default with rcs().

The number of knots is primarily determined by the size of the data set: 3, 4 or 5 are typical choices. Section 2.4.6 also suggests using AIC to choose the number of knots, consistent with your approach.

Your proposed model doesn't seem to allow for any interactions between age and BMI. That might be important to include. Section 2.7.2 discusses ways to include complex interactions between flexibly fit continuous predictors.

• Thank you for your advice. Your response was very helpful and I would like to consider the number of knots for age and BMI based on the AIC. I would also like to consider the interaction. Commented Jan 29 at 6:53