Let . Since
integration from zero to gives . Letting and imposing unit total probability gives
The probability density function is positive for because . Consequently the cumulative distribution function is increasing, starts at zero and tends to one. This verifies that the derived normalizing constant defines a probability distribution. The family is the exponential-logarithmic distribution with the complementary mixing parameter .
Solving gives . Hence the quantile function is
For such , , making the logarithm's argument lie in and the output positive. Its endpoint limits are and . Substitution into (i)'s cumulative distribution function recovers .
The following R function performs inverse transform sampling with vectorized numerical computation. It checks finite real scalar parameters, including a nonnegative integer sample count, and gives beta its requested default.
r_sample_f <- function(n, p, beta = 1) {
  scalar <- function(v) {
    is.numeric(v) && !is.complex(v) && length(v) == 1L &&
      is.finite(v)
  }
  if (!scalar(n) || n < 0 || n != floor(n))
    stop("n must be a nonnegative integer")
  if (!scalar(p) || p <= 0 || p >= 1)
    stop("p must lie strictly between 0 and 1")
  if (!scalar(beta) || beta <= 0)
    stop("beta must be positive")
  if (n == 0) return(numeric(0))
  v <- runif(n)
  (log1p(-p) - log(-expm1(v * log(p)))) / beta
}
Here is again a uniform distribution draw, so the expression is the quantile function from (ii). The function expm1(t) evaluates accurately when is small, avoiding cancellation in ; log1p(-p) evaluates . For default bounds, runif excludes both endpoints, so this implementation does not deliberately generate the infinite endpoint of the quantile function. It returns a numeric vector of length n, including an empty vector when n = 0. [ref] [ref]
A numerical power series evaluation needs a stopping rule. For and integer , the absolute remainder after terms satisfies the polylogarithm series remainder bound
Indeed for , and the remaining powers sum as a geometric series. This also covers negative . The code sums terms in vectors of at most 4096 entries, checking the bound after each block; there is no loop over individual terms.
polylog <- function(a, z, tol = 1e-10, max_terms = 1000000) {
  scalar <- function(v) {
    is.numeric(v) && !is.complex(v) && length(v) == 1L &&
      is.finite(v)
  }
  if (!scalar(a) || a < 0 || a != floor(a))
    stop("a must be a nonnegative integer")
  if (!scalar(z) || abs(z) >= 1)
    stop("z must be real with abs(z) < 1")
  if (!scalar(tol) || tol <= 0 || tol >= 1)
    stop("tol must lie strictly between 0 and 1")
  if (!scalar(max_terms) || max_terms < 1 ||
      max_terms != floor(max_terms))
    stop("max_terms must be a positive integer")
  if (z == 0) return(0)
  r <- abs(z)
  N <- 0
  ans <- 0
  repeat {
    if (N >= max_terms)
      stop("requested truncation tolerance not reached")
    B <- min(4096, max_terms - N)
    k <- seq.int(N + 1, N + B)
    ans <- ans + sum(z^k * exp(-a * log(k)))
    N <- N + B
    log_bound <- (N + 1) * log(r) - a * log(N + 1) - log1p(-r)
    if (log_bound <= log(tol)) return(ans)
  }
}
This accepts every positive integer order in the question, and also order zero if is the convention adopted. The bound controls absolute truncation error; floating-point rounding is a separate source of error. Close to , convergence can be slow. If the resource limit is reached, the function reports failure instead of silently claiming the requested accuracy. Useful exact checks are and .
Let and , evaluated from the given polylogarithm formulas. Generate a large sample of independent and identically distributed random variables with r_sample_f, and compute its sample mean and sample variance using mean and var. The central limit theorem gives the first standardized check:
For the second check, the correct asymptotic variance of the sample variance involves the fourth central moment :
The denominator is not unless the probability distribution has the requisite fourth central moment, as does the normal distribution. Here the probability density function decays exponentially, so all required moments are finite.
To compute , expand the denominator of the probability density function as a geometric series and integrate each nonnegative term. The gamma function integral gives the raw moments
Thus and . The following R code implements both checks for chosen interior parameters and large n:
p <- 0.4
beta <- 1.3
n <- 100000
raw_m <- vapply(1:4, function(j) {
  -factorial(j) * polylog(j + 1, 1 - p) / (beta^j * log(p))
}, numeric(1))
m <- raw_m[1]
v <- raw_m[2] - m^2
mu4 <- raw_m[4] - 4 * m * raw_m[3] +
  6 * m^2 * raw_m[2] - 3 * m^4
x <- r_sample_f(n, p, beta)
c(mean_check = sqrt(n) * (mean(x) - m) / sqrt(v),
  variance_check = sqrt(n) * (var(x) - v) / sqrt(mu4 - v^2))
For each check separately, an absolute value below is consistent with its approximate confidence interval. Repeat with many independent samples: the two standardized statistics should each resemble a standard normal distribution, with about outside that range. Also vary , and n; a systematic discrepancy that grows with suggests a bias. The two checks from the same sample are generally dependent, so passing both is not itself a joint statement, nor can a finite test prove that a generator is correct.
The second central limit theorem follows from the central limit theorem for the sample variance: differs by a quantity tending to zero in probability from .
Taking the logarithm of the normalized probability density function, then summing over the independent observations, gives the log-likelihood
Both and are parameters being inferred, so their contributions to the normalizing constant must be retained. The following R implementation validates the arguments and returns one number:
ll_f <- function(p, beta, x) {
  scalar <- function(v) {
    is.numeric(v) && !is.complex(v) && length(v) == 1L &&
      is.finite(v)
  }
  if (!scalar(p) || p <= 0 || p >= 1)
    stop("p must lie strictly between 0 and 1")
  if (!scalar(beta) || beta <= 0)
    stop("beta must be positive")
  if (!is.numeric(x) || is.complex(x) || !is.null(dim(x)) ||
      any(!is.finite(x)) || any(x <= 0))
    stop("x must be a vector of finite positive numbers")
  if (length(x) == 0L) return(0)
  t <- log1p(-p) - beta * x
  length(x) * (log(beta) - log(-log(p))) +
    sum(t - log(-expm1(t)))
}
Here and -expm1(t) computes accurately near zero. The empty-data likelihood function is one, so its log-likelihood is zero. Invalid parameter values produce errors in this evaluator; the next algorithm rejects candidates outside the parameter support before calling it.
Assume and a current state with , . The unnormalized posterior density is
Thus the log-posterior, up to an additive constant, is the log-likelihood plus the beta distribution and exponential distribution log prior densities. The exponential distribution rate is , since is its mean. [ref] [ref]
Choose a symmetric joint random-walk Metropolis algorithm proposal: and , for independent standard normal distribution draws. Its scale depends only on fixed hyperparameters, so forward and reverse proposal probability density functions agree. Reject immediately outside ; otherwise accept with Metropolis–Hastings acceptance probability
The following function makes exactly one proposal, with rejection retaining both old parameters:
MHstep <- function(x, p, beta, a, b, mu) {
  p_new <- rnorm(1, mean = p, sd = 0.1)
  beta_new <- rnorm(1, mean = beta, sd = mu / 2)
  if (p_new <= 0 || p_new >= 1 || beta_new <= 0)
    return(list(p = p, theta = beta))
  logpost <- function(pp, bb) {
    ll_f(pp, bb, x) + dbeta(pp, a, b, log = TRUE) +
      dexp(bb, rate = 1 / mu, log = TRUE)
  }
  logA <- logpost(p_new, beta_new) - logpost(p, beta)
  if (log(runif(1)) <= min(0, logA)) {
    p <- p_new
    beta <- beta_new
  }
  list(p = p, theta = beta)
}
The returned field theta contains the updated value of beta. The original PDF really asks for p and theta, although no parameter is defined in this question. This choice preserves its literal interface while making the intended second parameter explicit. A caller therefore advances with state <- MHstep(x, p, beta, a, b, mu), p <- state$p, and beta <- state$theta.
The proposal is an unrestricted symmetric normal distribution followed by rejection outside the support. Repeatedly drawing until a valid proposal appears would instead truncate and renormalize the proposal, requiring a proposal-density correction. The code uses immediate rejection and needs no such correction. The displayed scales are valid fixed choices; practical efficiency can be improved using a separate tuning phase.
Use several complementary Markov chain Monte Carlo convergence diagnostics, monitoring both and rather than judging the chain solely by its length:
A million iterations and stable-looking plots do not prove convergence. Agreement across dispersed chains, exploration of all visible modes and adequate effective sample size of a Markov chain provide stronger evidence. Estimate the Monte Carlo standard error using the chain's autocorrelation; the independent random variables formula from 3(b)(ii) does not apply directly to these dependent draws.

Articles by others on the same topic (0)

There are currently no matching articles.