Skip to content

Instantly share code, notes, and snippets.

@guymac
Last active December 28, 2015 19:39
Show Gist options
  • Save guymac/7551493 to your computer and use it in GitHub Desktop.
Save guymac/7551493 to your computer and use it in GitHub Desktop.
Groovy code used to analyze the risk formula used in the new cholesterol guidelines.
A = 0.91436
B = 61.1816
C = [ 12.344, 11.853, 2.664, 7.99, 1.769, 1.764 ]
TC = 180 // mg/dL
BPS = 120 // systolic
import static java.lang.Math.log // ln
import static java.lang.Math.exp // e^x
/**
* @param t age (years)
* @param x TC (mg/dL)
* @param y HDL (mg/dL)
* @param z BP
* @return 1o-year ASCVD risk %
*/
def risk10(t, x, y, z)
{
p = C[0]*log(t) + C[1]*log(x)
p += -C[2]*log(t)*log(x) - C[3]*log(y)
p += C[4]*log(t)*log(y) + C[5]*log(z)
return 100 * (1 - A ** exp(p - B))
}
@Grab(group='jfree', module='jcommon', version='1.0.16')
@Grab(group='jfree', module='jfreechart', version='1.0.13')
import static org.jfree.chart.plot.PlotOrientation.VERTICAL
import static javax.swing.WindowConstants.EXIT_ON_CLOSE
import org.jfree.chart.ChartFactory
import org.jfree.chart.ChartPanel
import org.jfree.chart.plot.ValueMarker
import org.jfree.data.category.DefaultCategoryDataset
import groovy.swing.SwingBuilder
dataset = new DefaultCategoryDataset()
for (age in 40..60)
{
for (hdl in [40,50,60,70,80])
{
dataset.setValue(risk10(age, TC, hdl, BPS), "HDL = $hdl", age)
}
}
labels = ["10-Year ASCVD Risk vs. Time", "Age", "Risk %"]
options = [true, true, true]
chart = ChartFactory.createLineChart(*labels, dataset,
VERTICAL, *options)
chart.plot.addRangeMarker(new ValueMarker(7.5))
frame = new SwingBuilder().frame(defaultCloseOperation:EXIT_ON_CLOSE)
{
panel(id:'canvas') { widget(new ChartPanel(chart)) }
}
frame.pack()
frame.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment