Skip to content

Instantly share code, notes, and snippets.

@boennecd
Created January 22, 2020 08:36
Show Gist options
  • Save boennecd/770cd7db6f0fa1b6829311ef005436b7 to your computer and use it in GitHub Desktop.
Save boennecd/770cd7db6f0fa1b6829311ef005436b7 to your computer and use it in GitHub Desktop.
/* Weibull_mix.cpp */
#include <Rcpp.h>
using Rcpp::NumericVector;
/* Computes the survival probability of a Weibull mixture. No checks are
* made on the length of the input vectors. */
// [[Rcpp::export]]
NumericVector Surv_Weibull_mix(
NumericVector const t, NumericVector const ps, NumericVector const gs,
NumericVector const ls){
std::size_t const n = t.size(), n_comp = ps.size();
NumericVector out(n);
for(std::size_t i = 0; i < n_comp; ++i){
double const *to = &t[0L];
for(auto o = out.begin(); o != out.end(); ++o, ++to)
*o += ps[i] * std::exp(- ls[i] * std::pow(*to, gs[i]));
}
return out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment