Skip to content

Instantly share code, notes, and snippets.

@hadley
Created November 19, 2012 14:55
Show Gist options
  • Select an option

  • Save hadley/4111095 to your computer and use it in GitHub Desktop.

Select an option

Save hadley/4111095 to your computer and use it in GitHub Desktop.
#include <Rcpp.h>
using namespace Rcpp;
double vacc3a(double age, int female, int ily){
double p = 0.25 + 0.3 * 1 / (1 - exp(0.004 * age)) + 0.1 * ily;
p = p * (female ? 1.25 : 0.75);
p = max(p, 0.0);
p = min(p, 1.0);
return p;
}
// [[Rcpp::export]]
NumericVector vacc3(NumericVector age, LogicalVector female, NumericVector ily) {
int n = age.size();
NumericVector out(n);
for(int i = 0; i < n; ++i) {
out[i] = vacc3a(age[i], female[i], ily[i]);
}
return out;
}
// [[Rcpp::export]]
NumericVector vacc4(NumericVector age, LogicalVector female, NumericVector ily) {
NumericVector p(age.size());
p = 0.25 + 0.3 * 1 / (1 - exp(0.004 * age)) + 0.1 * ily;
p = p * (female ? 1.25 : 0.75);
p = pmax(0,p);
p = pmin(1,p);
return p;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment