# Pointwise Nonparametric Estimation of Odds Ratio Curves with R: Introducing the flexOR Package
## 3 Software Description  
The flexOR R package is designed to generate pointwise estimates of OR curves for continuous predictors along with their corresponding confidence limits. Integrated seamlessly with the R statistical environment [15], this package includes a suite of functions that support both numerical analysis and graphical representation. Table 1 provides a summary of the available functions. Detailed guidance on using these functions can be found in the respective help pages.  
Managing the level of smoothing in additive models is particularly challenging, especially in multivariable contexts. To address this, we introduce the dfgam function, which allows flexible control over the degree of smoothing by providing various methodological options for optimization. In its current implementation, the dfgam function exclusively supports the \"s\" option for the smoother parameter, which indicates the use of smoothing splines for modeling nonlinear effects of predictors.  
dfgam( response, nl.predictors, other.predictors = NULL, smoother = \"s\", method = \"AIC\", data, step = NULL )  
This function requires continuous predictors that need to be introduced nonlinearly to be specified in the nl.predictors argument (as a vector), using smoothing splines (smoother = \"s\"), while other predictors (continuous or not) are included under other.predictors. This function generates a list containing the degrees of freedom for the spline smoothing terms, determined by the minimization of specific criteria based on the selected method. These criteria include (a) the Akaike Information Criterion (AIC) when method=\"AIC\", (b) a variant of the corrected AIC, adapted from [9], when method=\"AIC\", (c) the Bayesian Information Criterion (BIC) when method=\"BIC\", (d) the restricted maximum likelihood (REML) score when method=\"REML\", and (e) the Generalized Cross-Validation Criterion plus a penalty (GCV.Cp) when method=\"GCV.Cp\".  
The flexOR function, the cornerstone of the package, requires data, a response variable, and a formula to compute the odds ratios:  
\begin{table}
\begin{tabular}{l p{142.3 pt}} \hline \hline
**Function** & **Description** \\ \hline AICc & Calculates AICc, the Akaike Information Criterion corrected for small sample sizes, for Generalized Additive Models. \\ \hline floor\_to & Takes a numeric value or vector and rounds it down to the nearest multiple of a specified base. \\ \hline dfgam & Calculates the degrees of freedom for specified non-linear predictors in a GAM model. \\ \hline flexOR & Computes odds ratios and CIs for predictors in GAM models. \\ \hline plot.OR & Plots smooth odds ratios along with confidence intervals for a specified predictor. For an object of class OR. \\ \hline predict.OR & Predicts values using a fitted OR model. \\ \hline \hline \end{tabular}
\end{table}
Table 1: Summary of functions in the flexOR package.  
flexOR(  data,  response,  formula )  The plot function can then visualize flexible odds ratio curves, accommodating nonlinear relationships between continuous predictors and the response variable:  
plot(  x,  predictor,  prob = NULL,  ref.value = NULL,  conf.level = 0.95,  round.x = NULL,  ref.label = NULL,  col,  main,  xlab,  ylab,  lty,  xlim,  ylim,  xx,  ylog = TRUE, ...  )  The reference value is set using the ref.value argument or determined automatically to represent either the minimum or maximum of the odds ratio curve, depending on the setting of the prob argument.  
Users are encouraged to utilize the output of flexOR with additional R packages such as plotly for creating more interactive and dynamic visualizations. This integration not only enhances the interpretative value of the statistical analysis but also provides a more engaging way to explore the data visually. Details on generating interactive plots using the plotly R package and the application of these advanced functions will be demonstrated in subsequent sections, using two real datasets.