1 #include <config.h> 2 #include "Phi.h" 3 4 #include <JRmath.h> 5 6 #include <cfloat> 7 8 using std::vector; 9 10 namespace jags { 11 namespace bugs { 12 Phi()13 Phi::Phi () : LinkFunction ("phi", "probit") 14 { 15 } 16 inverseLink(double q) const17 double Phi::inverseLink(double q) const 18 { 19 if (!R_FINITE (q)) { 20 return q > 0 ? 1 : 0; 21 } 22 double p = pnorm(q, 0, 1, 1, 0); 23 if (p == 0) 24 return DBL_EPSILON; 25 else if (p == 1) 26 return 1 - DBL_EPSILON; 27 else 28 return p; 29 } 30 link(double mu) const31 double Phi::link(double mu) const 32 { 33 return qnorm (mu, 0, 1, 1, 0); 34 } 35 grad(double eta) const36 double Phi::grad(double eta) const 37 { 38 return dnorm (eta, 0, 1, 0); 39 } 40 41 }} 42