-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpauc.cpp
More file actions
32 lines (30 loc) · 839 Bytes
/
pauc.cpp
File metadata and controls
32 lines (30 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <Rcpp.h>
using namespace Rcpp;
// Below is a simple example of exporting a C++ function to R. You can
// source this function into an R session using the Rcpp::sourceCpp
// function (or via the Source button on the editor toolbar)
//
// Learn more about how to use Rcpp at:
//
// http://www.rcpp.org/
// http://adv-r.had.co.nz/Rcpp.html
//
// and browse examples of code using Rcpp at:
//
// http://gallery.rcpp.org/
//
// [[Rcpp::export]]
double pauc(NumericVector idv, NumericVector dv, NumericVector range) {
double tfirst = range[0];
double tlast = range[1];
dv = dv[idv >= tfirst];
idv = idv[idv >= tfirst];
dv = dv[idv <= tlast];
idv = idv[idv <= tlast];
double auc = 0;
int n = idv.size() - 1;
for(int i = 0; i < n; ++i) {
auc += (dv[i] + dv[i+1])*(idv[i+1] - idv[i])/2;
}
return auc;
}