Modeling Nonlinear Relationships in Clinical Trial Data with Generalized Additive Models Using AI, SAS, and R
July 16, 2026
Clinical trial data rarely behaves as neatly as our statistical models would like.
Many traditional regression approaches assume that relationships between predictors and outcomes follow a straight line. Yet in practice, biomarkers, disease progression, and treatment response often exhibit complex nonlinear patterns that cannot be adequately described with simple linear effects. Recognizing and modeling these relationships appropriately can lead to more meaningful insights and better scientific communication.
In a recent project, we explored how artificial intelligence (AI), Generalized Additive Models (GAMs), SAS, and R can work together to simplify the process of investigating nonlinear associations while producing publication-quality visualizations.
Why use AI for a statistical methods project?
One of the biggest challenges when demonstrating statistical methodology is obtaining data that is both realistic and shareable.
Using ongoing clinical trial data often requires extensive approvals and introduces concerns around confidentiality. Instead, we leveraged GitHub Copilot to generate a synthetic dataset that closely resembled a respiratory clinical trial, including:
- A negative binomial endpoint representing exacerbation counts
- A continuous baseline biomarker with a nonlinear relationship to the outcome
- Treatment assignment
- Time-at-risk for use as a model offset
Minor refinements were then made to the generated data to create clinically realistic treatment separation while maintaining the desired nonlinear behavior.
Beyond the practical advantages, the project also demonstrated an important mindset shift: AI is becoming another tool in the statistician’s toolbox. Rather than replacing statistical expertise, AI can accelerate routine tasks such as generating simulation datasets, drafting code, or creating starting points for methodological exploration.
When linear models aren’t enough
Traditional generalized linear models assume that each predictor has a constant effect across its entire range. In other words, every one-unit increase in a predictor changes the expected outcome by the same amount on the model scale.
While this assumption simplifies interpretation, it may not accurately reflect biological reality.
Consider a baseline biomarker used to predict exacerbation rates. The difference between values of 200 and 201 may have little clinical meaning, while treatment effects may emerge only after the biomarker exceeds a certain threshold. A linear model cannot naturally capture these changing relationships.
Generalized Additive Models (GAMs) address this limitation by replacing straight-line effects with smoothing functions estimated directly from the data. Rather than forcing researchers to specify polynomial terms or arbitrary transformations, GAMs allow the data itself to determine the shape of the relationship.
The result is a model that better reflects complex biological processes while preserving the familiar regression framework.
Comparing SAS and R implementations
Although both SAS and R can successfully fit GAMs, their implementations differ in several practical ways, a few of which include:
Interaction terms
R provides a particularly elegant syntax for treatment-specific smoothing functions through the by argument, allowing interaction effects to be incorporated directly within the model specification.
In SAS, equivalent functionality requires additional data preparation by creating separate interaction variables before fitting the model.
Smoothing parameters
SAS allows separate smoothing parameters for each spline, providing greater flexibility when different predictors require different levels of smoothness.
R simplifies maintenance by allowing a single smoothing parameter to be defined once and reused throughout the model.
Visualization
One area where the programming environments differ substantially is visualization.
SAS can output predicted values directly from the model, making it straightforward to generate publication-quality GAM plots.
R requires an additional prediction step — often using packages such as emmeans — to calculate expected values across the range of the continuous predictor before plotting. Although this introduces an extra step, it also provides flexibility for generating predictions in more complex models involving multiple covariates.
Despite these implementation differences, both software platforms produced nearly identical fitted curves and led to the same scientific conclusions.
Visualizing treatment effects across a continuum
Perhaps the greatest strength of GAMs lies in visualization.
Instead of summarizing treatment effects with a single coefficient, GAM plots reveal how treatment effects evolve continuously across the range of a biomarker.
In our example, little treatment separation was observed among participants with lower biomarker values. As biomarker levels increased, treatment groups diverged substantially before eventually reaching a plateau. This type of nuanced relationship would be difficult to identify — and even harder to communicate — using traditional linear assumptions alone.
These visualizations provide researchers with an intuitive way to explore complex interactions while supporting more clinically meaningful discussions with physicians, regulatory reviewers, and multidisciplinary development teams.
Key takeaways
Our project highlights several practical lessons for statisticians working in clinical development:
- AI-generated synthetic datasets provide a fast, efficient alternative for demonstrating statistical methodology without relying on sensitive clinical trial data.
- Generalized Additive Models offer an effective framework for modeling nonlinear relationships commonly encountered in biomedical research.
- Both SAS and R are capable of producing high-quality GAM analyses, with each platform offering distinct strengths in model specification and visualization.
- Effective graphical displays of nonlinear effects can substantially improve interpretation and communication of complex statistical findings.
As clinical trial data continues to grow in complexity, flexible modeling approaches such as GAMs — combined with modern AI-assisted workflows — offer statisticians powerful new tools for uncovering meaningful relationships that traditional linear methods may overlook.
Interested in learning more?
Kaitlyn Fernandez will be presenting on this topic at JSM in Boston on August 2 at 2:35 pm. We hope to see you there!
Book a meeting!Subscribe to our newsletter
Kaitlyn Fernandez
Associate Director of Biostatistics
Kaitlyn (“Kaitie”) Fernandez, MS, is an Associate Director of Biostatistics within the FSP group, where she provides statistical leadership for Phase II and III clinical trials in asthma and COPD. With more than 15 years of experience in the pharmaceutical and clinical research industry, she has contributed to clinical development programs spanning respiratory disease, food allergy, immunology, and other chronic disease therapeutic areas. Her expertise includes protocol development, statistical analysis planning, regulatory submissions, and study reporting. Kaitie has served as the lead statistician on multiple global development programs.
Kaitie’s professional interests include statistical graphics and data visualization, communicating complex statistical concepts to multidisciplinary audiences, and scientific writing for presentations and publications. Throughout her career, she has authored or co-authored more than 30 peer-reviewed publications, oral presentations, and conference posters. An award-winning presenter, she has spoken at the Joint Statistical Meetings (JSM), SAS Global Forum, PharmaSUG, and numerous other statistical conferences.
Kaitie holds a Master of Science in Biostatistics from the University of North Carolina at Chapel Hill and a Bachelor of Arts in Applied Mathematics from Maryville College.
Read full employee bioClaim your free 30-minute strategy session
Book a free, no-obligation strategy session with a Cytel expert to get advice on how to improve your drug’s probability of success and plot a clearer route to market.