TransfoParam_GR1A.R 910 Bytes
Newer Older
1
2
TransfoParam_GR1A <- function(ParamIn, Direction) {
  
3
4
5
  ## number of model parameters
  NParam <- 1L
  NParam <- 2L
6
7
  
  
8
9
10
11
12
13
14
15
16
17
18
  ## check arguments
  isVecParamIn <- is.vector(ParamIn)
  if (isVecParamIn) {
    ParamIn <- matrix(ParamIn, nrow = 1)
  }  
  if (!inherits(ParamIn, "matrix")) {
    stop("'ParamIn' must be of class 'matrix'")
  }
  if (!inherits(Direction, "character") | length(Direction) != 1 | any(!Direction %in% c("RT", "TR"))) {
    stop("'Direction' must be a character vector of length 1 equal to 'RT' or 'TR'")
  }
19
  if (ncol(ParamIn) != NParam) {
20
    stop(sprintf("the GR1A model requires %i parameters", NParam))
21
22
  }
  
23
24

  ## transformation
25
  if (Direction == "TR") {
26
    ParamOut <- (ParamIn + 10.0) / 8
27
28
  }
  if (Direction == "RT") {
29
    ParamOut <-  ParamIn * 8 - 10.0
30
31
  }
  
32
33
34
35
  
  ## check output
  if (isVecParamIn) {
    ParamOut <- as.vector(ParamOut)
36
  }
37
  
38
39
  return(ParamOut)
  
Delaigue Olivier's avatar
Delaigue Olivier committed
40
}