# Pointwise Nonparametric Estimation of Odds Ratio Curves with R: Introducing the flexOR Package
## 2 The Additive Model  
Logistic regression is a widely used statistical method for modeling the probability of a binary outcome. The logistic regression model is based on the logistic function, and it expresses the log-odds of an event as a linear combination of predictor variables. The logistic function is defined as  
\[p(x)=\frac{e^{\beta_{0}+\beta_{1}x_{1}+\beta_{2}x_{2}+\ldots+\beta_{p}x_{p}}}{1 +e^{\beta_{0}+\beta_{1}x_{1}+\beta_{2}x_{2}+\ldots+\beta_{p}x_{p}}} \tag{1}\]  
where \(p(x)=p(Y=1|X=x)\) is the probability of the event, \(\beta_{0}\) is the intercept term, and \(\beta_{i}\), \(1\leq i\leq p\) are the coefficients of the predictor variables \(X_{i}\). The log-odds (logit) of the event is given by  
\[\ln\biggl{(}\frac{p(x)}{1-p(x)}\biggr{)}=\beta_{0}+\beta_{1}x_{1}+\beta_{2}x_ {2}+\ldots+\beta_{p}x_{p} \tag{2}\]The odds ratio (OR) in logistic regression is a crucial measure of association between a predictor variable and the outcome. The adjusted OR for a subject with (continuous) covariate value \(X_{i}=x_{i}\) compared with a subject with covariate value \(x_{i,ref}\) is given by  
\[\text{OR}(x_{i},x_{i,ref})=\exp\left(\beta_{i}(x_{i}-x_{i,ref})\right) \tag{3}\]  
In its additive form, the logistic additive model expresses the log-odds of an event that can be written as  
\[\ln\left(\frac{p(x)}{1-p(x)}\right)=\beta_{0}+\sum_{i=1}^{q}\beta_{i}x_{i}+ \sum_{i=q+1}^{p}f_{i}(x_{i}) \tag{4}\]  
where the first \(q\) covariates are introduced parametrically in the model and the remaining ones are introduced nonlinearly through (unknown) smooth functions, \(f_{i}\). Model (4) stands out as particularly well-suited for various applications due to its ability to accommodate nonlinear, smooth effects for continuous predictors, thereby providing a substantial increase in flexibility. These effects can be effectively modeled using regression splines [13] or smoothing splines [5]. Assuming (4), the adjusted odds ratio for a subject with covariate value \(X_{i}=x_{i}\), \(i>q\) compared with a subject with covariate value \(x_{i,ref}\) is given by  
\[\text{OR}(x_{i},x_{i,ref})=\frac{\exp\left(f_{i}(x_{i})\right)}{\exp\left(f_{ i}(x_{i,ref})\right)}=\exp\left(f_{i}(x_{i})-f(x_{i,ref})\right) \tag{5}\]  
A critical decision in estimating the function \(f(x)\) is the selection of the smoothing level, which directly influences the smoothness of the estimated function \(\hat{f}(x)\). The Akaike Information Criterion (AIC), introduced by [PERSON] [8], and the Bayesian Information Criterion (BIC), proposed by [PERSON] [10], stand out as widely utilized criteria for model selection in a given dataset. Grounded in log-likelihood (LogLik), these criteria can assist in determining the optimal model. For additive logistic models, selecting the appropriate level of smoothing is achieved by comparing models with varying degrees of freedom and opting for the one with the lowest AIC or BIC scores. The AIC, AICc, and BIC scores are calculated as follows:  
\[\text{AIC}=-2\times\text{LogLik}+2\times k\]  
\[\text{BIC}=-2\times\text{LogLik}+\log(n)\times k\]  
\[\text{AICc}=\text{AIC}+2\times k(k+2)/(n-k-1)\]  
where LogLik is the log-likelihood of the fitted model, \(k\) represents the equivalent degrees of freedom of the model, and \(n\) is the number of observations in a given dataset. The implementation of AIC, BIC, and AICc criteria to determine the degree of smoothing for the corresponding continuous variable is straightforward for the case of a model with a single covariate with a nonlinear effect, using one of these approaches. However, it will entail fitting and comparing a large number of models. If we aim to fit a larger number of covariates, this approach is no longer as simple. Later on, we illustrate the application of these methods to real data, where we apply them to three covariates, for which we propose using the dfgam function developed by us.