forked from jansteinfeld/PP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper_func.cpp
More file actions
executable file
·60 lines (41 loc) · 920 Bytes
/
helper_func.cpp
File metadata and controls
executable file
·60 lines (41 loc) · 920 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <Rcpp.h>
using namespace Rcpp;
// Helper functions
// [[Rcpp::export]]
NumericMatrix ansol(IntegerMatrix awm, IntegerVector maxsc) {
// awm = response matrix
// maxsc = max score possible
int npers = awm.nrow();
int nitem = awm.ncol();
NumericMatrix pperg(npers,2);
for(int pe = 0; pe < npers; pe++)
{
int sumresp = 0; // sum of responses
int summax = 0; // sum of maximal scores
for(int it = 0; it < nitem; it++)
{
if(IntegerVector::is_na(awm(pe,it)))
{
continue;
} else
{
sumresp += awm(pe,it);
summax += maxsc(it);
}
}
// wenn max oder 0
if(sumresp == summax)
{
pperg(pe,0) = R_PosInf;
pperg(pe,1) = NA_REAL;
} else if(sumresp == 0)
{
pperg(pe,0) = R_NegInf;
pperg(pe,1) = NA_REAL;
} else
{
continue;
}
}
return pperg;
}