# Pointwise Nonparametric Estimation of Odds Ratio Curves with R: Introducing the flexOR Package
## 4 Examples of Application
### Acute Coronary Syndrome Data
> or1 <- flexOR(data = heart2, response = \"exitus\",  formula = \"s(age, 8.9) + s(creatinine, 1.8) + s(fasting, 4.6) + anemia + sex + factor(smoking)) > plot( x = or1, predictor = \"fasting\",  ref.value = 100, ref.label = \"Ref. value\",  
Figure 1: Relation between fasting blood glucose level and log-odds of death among ACS patients. The log-odds ratio (LnOR) is depicted by a solid line, while the 80% and 95% confidence bands are represented by dashed lines. These visualizations are provided for a reference value of 100 for fasting blood glucose level. col.area = c(\"grey75\", \"grey90\"), main = \" \", xlab = \"Fasting blood glucose levels\", ylab = \"Log Odds Ratio (Ln OR)\", lty = c(1,2,2,3,3), ylog = TRUE, round.x = 1, conf.level = c(0.8, 0.95) )  
Plotly's R graphing library offers a powerful tool for creating interactive, publication-quality graphs that enhance data visualization experiences. The library's versatility allows users to go beyond static representations and delve into dynamic visualizations, enabling a more engaging exploration of the data. In the example provided, the input commands showcase the library's capability to generate a smoothed log-odds curve with two confidence bands. The interactive nature of these plots facilitates a deeper understanding of the underlying patterns by allowing users to zoom in, pan, and hover over data points for detailed insights. This interactivity not only enhances the overall user experience but also promotes a more nuanced and insightful interpretation of the graphed information. Below are the input commands, along with the corresponding Figure 2.  
> library(plotly)  
> p <- plot( x = or1, predictor = \"fasting\", ref.value = 100, ref.label = \"Reference Label\", main = \"Smooth odds ratio for Fasting blood glucose\", xlab = \"Fasting blood glucose levels\", ylab = \"Log Odds Ratio (Ln OR)\", lty = c(1,2,2,3,3), xlim = c(60, 450), round.x = 1, conf.level = c(0.8, 0.95) )  
> tmat <- p$estimates > xref <- p$xref > mdata <- or1$dataset > jj <- match(sort(unique(mdata$fasting), mdata$fasting)  
Plotly to get shaded (two-levels) confidence bands > fig <- plot_ly(x=mdata$fasting[jj], y=tmat[jj,5], type ='scatter', mode = 'lines', line = list(color = 'transparent'), showlegend = FALSE, name = '80%UCI') > fig <- fig %>% add_trace(y = \"tmat[jj,3], type ='scatter', mode = 'lines', fill = 'tonexty', fillcolor = 'rgba(0,100,80,0.3)', line = list(color = 'transparent'), showlegend = FALSE, name = '95%UCI') > fig <- fig %>% add_trace(y = \"tmat[jj,2], type ='scatter', mode = 'lines', fill = 'tonexty', fillcolor='rgba(0,100,80,0.3)',line = list(color = 'transparent'),  showlegend = FALSE, name = '95%LCI')  > fig <- fig %>% add_trace(y = ~tmat[jj,4], type ='scatter',  mode = 'lines',  fill = 'tonety', fillcolor='rgba(0,100,80,0.3)',  line = list(color = 'transparent'),  showlegend = FALSE, name = '80%LCI')  > fig <- fig %>% add_trace(y = ~tmat[jj,1], type ='scatter',  mode = 'lines',  line = list(color='rgb(0,100,80)'),  showlegend = FALSE, name = 'LnOR')  > fig <- fig %>% add_annotations( x = xref,  y = floor_to(min(tmat[jj,]), to=0.5),  xref = \"x\", yref = \"y\",  axref = \"x\", ayref = \"y\",  text = paste(\"Ref. value =\",xref),  showarrow = T,  ax = xref,  ay = max(tmat[jj,])/2)  > fig <- fig %>% layout(#title = \"\",  plot_bgcolor='rgb(229,229,229)',  xaxis = list(title = \"Fasting glucose levels\",  gridcolor = 'rgb(255,255,255)',  showgrid = TRUE,  showline = FALSE,  showticklabels = TRUE,  tickcolor = 'rgb(127,127,127)',  ticks = 'outside',  zeroline = FALSE),  yaxis = list(title = \"Log Odds Ratio (Ln OR)\",  gridcolor = 'rgb(255,255,255)',  showgrid = TRUE,  showline = FALSE,  showticklabels = TRUE,  tickcolor = 'rgb(127,127,127)',  ticks = 'outside',  #range = c(-0.5,3.5),  zeroline = FALSE))  > fig  
Figures 1 and 2 illuminate the intricate relationship between fasting blood glucose levels and the odds of death among Acute Coronary Syndrome (ACS) patients.