Skip to content

Instantly share code, notes, and snippets.

View boennecd's full-sized avatar
💭
Coding

boennecd

💭
Coding
View GitHub Profile
/* 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){
@boennecd
boennecd / duplication-mat.R
Created April 30, 2019 07:49
Methods to create duplication matrix in R
#####
# simple version which stores the indices in a full matrix and then copy
# them back later
f1 <- function(n){
stopifnot(is.integer(n), n > 1L)
nq <- n * (n + 1L) / 2L
o <- matrix(0L, n, n)
o[lower.tri(o, diag = TRUE)] <- 1:nq
o[upper.tri(o)] <- t(o)[upper.tri(o)]