File: GammaDistribution.R

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

################################
##
## Class: GammaParameter
##
################################


## Access Methods
setMethod("shape", "GammaParameter", function(object) object@shape)
setMethod("scale", "GammaParameter", 
           function(x, center = TRUE, scale = TRUE) x@scale)
           ### odd arg-list due to existing function in base package 

## Replace Methods
setReplaceMethod("shape", "GammaParameter", 
                  function(object, value){ object@shape <- value; object})
setReplaceMethod("scale", "GammaParameter", 
                  function(object, value){ object@scale <- value; object})


validGammaParameter <- function(object){
  if(length(shape(object)) != 1)
    stop("shape has to be a numeric of length 1")    
  if(shape(object) <= 0)
    stop("shape has to be positive")
  if(length(scale(object)) != 1)
    stop("scale has to be a numeric of length 1")    
  if(scale(object) <= 0)
    stop("scale has to be positive")
  else return(TRUE)
}

setValidity("GammaParameter", validGammaParameter)


################################
##
## Class: gamma distribution
##
################################

Gammad <- function(shape = 1, scale = 1) 
          new("Gammad", shape = shape, scale = scale)

## wrapped access methods
setMethod("shape", "Gammad", function(object) shape(param(object)))
setMethod("scale", "Gammad", 
           function(x, center = TRUE, scale = TRUE) scale(param(x)))
           ### odd arg-list due to existing function in base package 

## wrapped replace methods
setMethod("shape<-", "Gammad", 
           function(object, value) 
                    new("Gammad", shape = value, scale = scale(object)))
setMethod("scale<-", "Gammad", 
           function(object, value) 
                    new("Gammad", shape = shape(object), scale = value))