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.