File: zeta.R

package info (click to toggle)
r-cran-boolnet 2.1.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: ansic: 12,452; sh: 16; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 800 bytes parent folder | download | duplicates (6)
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

# Distribution function of the Zeta distribution
dzeta <- function(k,gamma=2.5,approx_cutoff=100)
{
  zeta_approx <- sum(sapply(seq_len(approx_cutoff),function(x)1/(x^gamma)))
  sapply(k,function(k_i)
  {
    1/(k_i^gamma * zeta_approx)
  })
}

# Quantile function of the Zeta distribution
qzeta <- function(p,maxK,gamma=2.5,approx_cutoff=100)
{
  vals <- cumsum(dzeta(seq_len(maxK),gamma,approx_cutoff))
  sapply(p,function(p_i)
  {
    indices <- which(vals > p_i)
    if (length(indices) == 0)
      return(NA)
    else
      return(indices[1])
  })
}

# Draw random numbers from the Zeta distribution
rzeta <- function(n,maxK,gamma=2.5,approx_cutoff=100)
{
  maxP <- cumsum(dzeta(seq_len(maxK),gamma,approx_cutoff))
  p <- runif(min=0,max=maxP,n=n)
  return(qzeta(p,maxK,gamma,approx_cutoff))
}