File: LaplaceDistribution.R

package info (click to toggle)
r-cran-distr 2.9.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,344 kB
  • sloc: ansic: 199; sh: 13; makefile: 2
file content (27 lines) | stat: -rw-r--r-- 861 bytes parent folder | download | duplicates (2)
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

################################
##
## Class: Laplace or Double Exponential distribution
##
################################


## wrapped access methods
setMethod("rate", "DExp", function(object) rate(param(object)))

## wrapped replace methods
setMethod("rate<-", "DExp", function(object, value) new("DExp", rate = value))

DExp <- function(rate = 1) {D <- new("DExp", rate = rate)
                            D@Symmetry <- SphericalSymmetry(0)
                            D}

setMethod("*", c("DExp","numeric"),
          function(e1, e2){
            if (length(e2)>1) stop("length of operator must be 1")
            if(isTRUE(all.equal(e2,0))) 
               return(new("Dirac", location = 0, .withArith = TRUE))
            else  
               return(new("DExp", rate = rate(e1) / abs(e2), .withArith = TRUE))
          })