Skip to content

Instantly share code, notes, and snippets.

@sean-mcclure
Created June 12, 2022 23:33
Show Gist options
  • Save sean-mcclure/7c5dd6f4eeb7f3b3d4c8f2a86f8abb61 to your computer and use it in GitHub Desktop.
Save sean-mcclure/7c5dd6f4eeb7f3b3d4c8f2a86f8abb61 to your computer and use it in GitHub Desktop.
Survival Probability for Group Survival (data for plotly.js)
function survival_probability(options) {
var group_size = 1;
if(options.hasOwnProperty("custom_beta")) {
var betas = [options.custom_beta]
} else {
var betas = [100, 50, 25];
}
x_values = [-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1];
plot_data = [];
betas.forEach(function(beta) {
y_values = [];
[-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1].forEach(function(x) {
const arr = Array(group_size).fill(Math.pow(x, 2));
const sum = arr.reduce(function(pv, cv) {
return pv + cv;
}, 0);
/**** equation ****/
const result = 100 - (beta * sum);
/******************/
y_values.push(result);
})
var inner = {
x: x_values,
y: y_values,
type: "scatter",
name: "beta " + beta
}
plot_data.push(inner)
})
return (plot_data)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment