# Pointwise Nonparametric Estimation of Odds Ratio Curves with R: Introducing the flexOR Package
## 4 Examples of Application
### Pima Indians Diabetes Database  
In this Section 4.2 we use the Pima Indians Diabetes Database, a well-known dataset in the field of machine learning and statistics. The dataset originates from a study conducted by the National Institute of Diabetes and Digestive and Kidney Diseases (NIDDK) in the 1990s, focusing on the Pima Indian population in Arizona, USA. The dataset includes various demographic, clinical, and diagnostic measurements for individuals, along with an indication of whether or not each person developed diabetes. Researchers and data scientists often use this dataset to develop and test predictive models for diabetes based on features like age (years), BMI (Body Mass Index), blood pressure, diabetes pedigree function, and other health-related variables. The dataset is available as part of the mlbench R package. After identifying the variables to be included in the model and determining those requiring a nonlinear effect through smoothing splines, we utilized the dfgam function. This function enabled us to obtain optimal degrees of freedom, minimizing the AIC of the model. The resulting degrees of freedom for the nonlinear predictors, namely age and body mass index (mass), were determined to be 3.3 and 4.1, respectively. Subsequently, these optimal degrees of freedom were incorporated into the generalized additive model (GAM) using the gam function of the gam R package:  
> data(PimaIndiansDiabetes2, package=\"mlbench\") > df2 <- dfgam(response=\"diabetes\", nl.predictors=c(\"age\",\"mass\"), other.predictors=c(\"pedigree\"), smoother=\"s\", method=\"AIC\", data = PimaIndiansDiabetes2) > df28 df  df age 3.3 mass 4.1 > m2 <- gam(diabetes ~ s(age, df=3.3) + s(mass, df=4.1) + pedigree, data=PimaIndiansDiabetes2, family=binomial) \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Covariates** & **AIC** & **GCV.Cp** & **REML** \\ \hline Age & 8.9 & 6.97 & 3.34 \\ Creatinine & 1.8 & 1.79 & 2.06 \\ Fasting & 4.6 & 4.37 & 3.47 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Degrees of freedom (df) for the multivariable logistic model with smoothing splines for age, creatinine, and fasting. The remaining variables were anemia, sex, and smoking. Acute coronary syndrome. Next, we can leverage the primary function of the flexOR package, which, in turn, is employed to generate a plot illustrating the smooth log-odds ratio curve. This curve, shown in Figure 3, provides insight into the relationship between the risk of diabetes and body mass index within the Pima Indian population in Arizona, USA. The log-odds ratio (LnOR) is visually represented, accompanied by 80% (depicted in gray) and 95% (light gray) confidence bands, using a reference value of 40 for BMI. The input commands to generate the plot shown in Figure 3 are given below. > or2 <- flexOR(data = PimaIndiansDiabetes2,  response = \"diabetes\",  formula = \"s(age, 3.3) + s(mass, 4.1) + pedigree) > plot(  x = or2,  predictor = \"mass\",  ref.value = 40,  ref.label = \"Ref. value\",  col.area = c(\"grey75\", \"grey90\"),  main = \" \",  xlab = \"Body mass index\",  ylab = \"Log Odds Ratio (Ln OR)\",  lty = c(1,2,2,3,3),  round.x = 1,  conf.level = c(0.8, 0.95) )  
It is important to note that normal BMI values typically fall within the range of 19 to 25. In our context, individuals with a BMI lower than 40 manifest lower odds of diabetes. The log-odds of diabetes, as depicted in Figure 3, follows a distinctive pattern: there is a rapid increase until a BMI value of 30, followed by a relatively stable period between 30 and 40. However, beyond a BMI of 40, there is a notable and accelerated rise in the odds of diabetes. Finally, the following input commands and results provide predicted values along with confidence intervals for the log-odds ratio at different levels of the predictor variable body mass index when a reference value is set at 40. > pdval <- c (20, 25, 30, 35, 40, 45  
Table 3 presents the degrees of freedom for the logistic model with smoothing splines for age and mass, and with pedigree as the additional predictor.