# Pointwise Nonparametric Estimation of Odds Ratio Curves with R: Introducing the flexOR Package
## 4 Examples of Application
### Acute Coronary Syndrome Data  
This study aims to assess and compare the predictive efficacy of fasting glucose in forecasting mortality among patients with acute coronary syndrome (ACS). The analysis involves modeling the intricate, nonlinear relationships between glucose levels and the risk of death, utilizing smoothing splines within the framework of additive logistic regression. To explore the intricate dynamics of mortality prediction, a Generalized Additive Model (GAM) was employed. This model considered the binary response variable \"exitus\" (death) and incorporated key predictors, including age, creatinine, fasting blood glucose levels, anemia, sex, and smoking status (nonsmoker, smoker, and ex-smoker). Specifically, nonlinear relationships for age (years), creatinine, and fasting glucose levels were modeled using smoothing splines. The degrees of freedom for the smooth terms were determined using the dfgam function, minimizing the AIC criterion. The resulting degrees of freedom were 8.9 for age, 1.8 for creatinine, and 4.6 for fasting. In this case, to obtain the degrees of freedom for the three covariates, the dfgam function started with an initial value provided by the REML method, and through a recursive three-step process (default value, step = 3), it obtained the respective degrees of freedom for the three covariates. All selected predictors--age, creatinine, and fasting--demonstrated statistically significant effects, with their respective smooth terms exhibiting significant F-values. The model, fitted using the gam function from the gam R library, also captured the influence of anemia, sex, and smoking status, the first and the last showing significant effects. The overall model fit was evaluated through the analysis of deviance, indicating a strong fit to the data. These findings underscore the crucial role of the specified predictors in predicting the binary response outcome (death). > library (\"flexOR\") > df1 <- dfgam(response=\"exitus\",  nl.predictors=c(\"age\",\"creatinine\",\"fasting\"),  other.predictors=c(\"anemia\",\"sex\",\"smoking\"),  smoother=\"s\",  method=\"AIC\",  data = heart2) > df18 df  df age 8.9  creatinine 1.8  fasting 4.6  > ml <- gam(exitus ~ s(age, 8.9) + s(creatinine, 1.8) + s(fasting, 4.6) +  anemia + sex + factor(smoking),  data=heart2,  family=binomial()) > summary(ml)  Anova for Parametric Effects  Df Sum Sq Mean Sq F value Pr(>F)  s(age, 8.9) 1.0 43.44 43.444 49.9012 3.548e-12 ***  s(creatinine, 1.8) 1.0 16.08 16.077 18.4669 1.944e-05 ***  s(fasting, 4.6) 1.0 10.71 10.709 12.3004 0.0004784 ***  anemia 1.0 15.69 15.693 18.0257 2.438e-05 ***  sex 1.0 2.71 2.713 3.1165 0.0778910.  factor(smoking) 2.0 7.44 3.720 4.2725 0.0142708 *  Residuals 790.7 688.38 0.871  ---  Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1'1  
Anova for Nonparametric EffectsNpar Df Npar Chisq P(Chi) (Intercept) s(age, 8.9) 7.9 21.6053 0.005358 ** s(creatinine, 1.8) 0.8 3.2991 0.050784. s(fasting, 4.6) 3.6 9.3431 0.040178 * anemia sex factor(smoking)  
The most effective means of interpreting the nonlinear effects is through the analysis of the corresponding plot. Below, we present the input commands to generate the log-odds ratio curve illustrating the relationship between the odds of death and fasting glucose among ACS patients. The resulting plot is showcased in Figure 1. The figure illustrates a spoon-shaped dependence of the mortality odds ratio on fasting glucose, with the lowest odds observed at 114 mg/dL (6.3 mmol/L; to convert mg/dL of glucose to mmol/L, divide by 18). The log-odds ratio (LnOR) is visually represented, accompanied by 80% (depicted in gray) and 95% (light gray) confidence bands, utilizing a reference value of 100 for fasting blood glucose. Users have the option to choose a single confidence level, although two are also feasible, as demonstrated in the input command below. Additionally, the argument \"ylog\" provides the flexibility to generate a plot that is not on the log scale.