| 88 | | if not check_dependency('rpy'): |
| 89 | | raise ImportError("gamma_hazard requires RPy (http://rpy.sourceforge.net/)") |
| 90 | | |
| 91 | | from rpy import r |
| 92 | | |
| 93 | | # scipy.special.gammaincc has numerical problems |
| 94 | | #Hpre = -log(scipy.special.gammaincc(a,(x-dt)/b)) |
| 95 | | #Hpost = -log(scipy.special.gammaincc(a,(x+dt)/b)) |
| 96 | | |
| 97 | | # reverting to the good old r.pgamma |
| 98 | | Hpre = -r.pgamma(x-dt,shape=a,scale=b,lower=False,log=True) |
| 99 | | Hpost = -r.pgamma(x+dt,shape=a,scale=b,lower=False,log=True) |
| 100 | | val = 0.5*(Hpost-Hpre)/dt |
| 101 | | |
| 102 | | return val |
| | 88 | if check_dependency('rpy'): |
| | 89 | from rpy import r |
| | 90 | |
| | 91 | # scipy.special.gammaincc has numerical problems |
| | 92 | #Hpre = -log(scipy.special.gammaincc(a,(x-dt)/b)) |
| | 93 | #Hpost = -log(scipy.special.gammaincc(a,(x+dt)/b)) |
| | 94 | |
| | 95 | # reverting to the good old r.pgamma |
| | 96 | Hpre = -r.pgamma(x-dt,shape=a,scale=b,lower=False,log=True) |
| | 97 | Hpost = -r.pgamma(x+dt,shape=a,scale=b,lower=False,log=True) |
| | 98 | val = 0.5*(Hpost-Hpre)/dt |
| | 99 | |
| | 100 | return val |
| | 101 | |
| | 102 | elif check_dependency('rpy2'): |
| | 103 | |
| | 104 | from rpy2.robjects import r |
| | 105 | |
| | 106 | # scipy.special.gammaincc has numerical problems |
| | 107 | #Hpre = -log(scipy.special.gammaincc(a,(x-dt)/b)) |
| | 108 | #Hpost = -log(scipy.special.gammaincc(a,(x+dt)/b)) |
| | 109 | |
| | 110 | # reverting to the good old r.pgamma |
| | 111 | Hpre = -r.pgamma(x-dt,shape=a,scale=b,lower=False,log=True)[0] |
| | 112 | Hpost = -r.pgamma(x+dt,shape=a,scale=b,lower=False,log=True)[0] |
| | 113 | val = 0.5*(Hpost-Hpre)/dt |
| | 114 | |
| | 115 | return val |
| | 116 | else: |
| | 117 | raise ImportError("gamma_hazard requires RPy or RPy2 (http://rpy.sourceforge.net/)") |