Created
November 19, 2012 14:55
-
-
Save hadley/4111095 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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