# Pointwise Nonparametric Estimation of Odds Ratio Curves with R: Introducing the flexOR Package
## 1 Introduction
The final estimated function is a smooth curve that passes through the data points while minimizing roughness. By adjusting \(\lambda\) and the placement of knots, the degree of smoothing can be controlled, allowing flexibility in capturing complex relationships in the data. For further insights, additional details can be found in [5] or [7]. A drawback associated with employing splines or smoothing splines to model the effect of a continuous covariate lies in the challenge of selecting the number and placement of knots that define the smooth line. The arbitrary determination of these parameters may inadvertently obscure crucial features in the dataset. Striking the right balance is essential, as an excessive number of knots can result in oversmoothing, while too few can lead to undersmoothing. Some implementations, such as the gam package in R, automatically select the number and position of knots based on the data and the specified degrees of freedom for the smoother. Various methods have been proposed to address this issue, with one approach relying on minimizing Akaike's Information Criterion (AIC, [8]), and an alternative based on minimizing a corrected version thereof (AICc, [9]). While these criteria are straightforward to minimize in a univariate context, their application becomes more intricate in multivariable settings. The Bayesian Information Criterion (BIC), initially proposed by [10] presents another viable option in this context. In response to these challenges, we introduce the flexOR package, accessible on the Comprehensive R Archive Network at [[https://CRAN.R-project.org/package=flexOR](https://CRAN.R-project.org/package=flexOR)]([https://CRAN.R-project.org/package=flexOR](https://CRAN.R-project.org/package=flexOR)) (accessed on 27 April 2024). This package offers a methodological advancement by incorporating robust nonparametric methods that improve the modeling and interpretation of odds ratios (ORs) within logistic regression frameworks. The conceptual foundations of this approach draw inspiration from the work of [11; 12], who introduced a versatile method for constructing hazard ratio curves with confidence limits. This methodology, rooted in clinical survival studies, leverages an additive Cox model where the nonlinear effects of continuous predictors on log hazards are elegantly modeled using P-splines. In our context, our objective is to estimate the odds ratios (OR) and their associated confidence intervals through a nonparametric approach. However, as in [11; 12] we aim to estimate these curves while considering a reference value. Capitalizing on the asymptotic normality of the logarithm of the odds ratio, we employ a new approximation for the covariance matrix of the log-odds ratio to construct these confidence intervals. One of the cornerstones of flexOR is the dfgam function, which determines the optimal number of degrees of freedom for smoothing in multivariable additive logistic models. The optimal degree of smoothing is ascertained by minimizing any of the following criteria: AIC, AICc, or BIC. The AIC is a measure of the relative quality of statistical models, balancing goodness of fit and model complexity. The AICc is a corrected version of AIC, particularly useful in situations with a limited sample size to prevent overfitting. Researchers often use these criteria to guide model selection, and in the context of smoothing parameters, they provide a systematic way to balance model fit and complexity. In addition, dfgam also incorporates the restricted maximum likelihood method (REML) and generalized cross-validation (GCV) into the implemented methods with a particular emphasis on the GCV.Cp criterion, as implemented in the famous mgcv package [6]. The use of these methods is particularly relevant in models involving multiple covariates with nonlinear effects, ensuring that the selected model is optimally adjusted without being overfitted or underfitted.