Prentice definition (originally from Stacy 1962) of PDF for generalised gamma:
for
Wikipedia PDF definition =
Stacy & Mihram | Prentice | Wikipedia | |
---|---|---|---|
|
|||
rth moment | $E(X^r) = \begin{cases} a^r\frac{\Gamma((p\nu + r)/p)}{\Gamma(\nu)}, & r/p > -\nu\ \infty, & \textup{otherwise} \end{cases}$ eqn (3) | ||
Mean | $E(X) = \begin{cases} a\frac{\Gamma((p\nu + 1)/p)}{\Gamma(\nu)}, & r/p > -\nu\ \infty, & \textup{otherwise} \end{cases}$ | ||
Mode |
|
||
Model | $\begin{array}{c} y = log(x) \ log(a) + b^{-1}w \end{array}$ |
Stacy to Prentice | Prentice to Wiki | Stacy to Wiki | Lawless to Wiki |
---|---|---|---|
- | - |
Lawless 1980:
Starting with Prentice PDF defined as:
In log link space:
Substitutions | Lawless to Prentice |
---|---|
Lawless 1980 | |
---|---|
Original special cases from Prentice, where
Special cases | Conditions |
---|---|
Exponential | |
Weibull | |
Gamma | |
~ Lognormal |
Not sure what to do with this note or why I wrote this down:
- With Prentice using Q parameterisation:
$\left { \frac{b}{\Gamma \frac{1}{Q^{2}}} \right }a^{\frac{-b}{Q^2}}x^{\frac{b}{Q^2}-1}exp{(-(\frac{x}{a})^b)}$
I think that this is only an issue for the PDF? Not for flexsurv::rgengamma
.
I do not know about for anything else.
From flexsurv documentation:
# Where mu is the mean
dgengamma(x, mu, sigma, Q=0) = dlnorm(x, mu, sigma)
dgengamma(x, mu, sigma, Q=1) = dweibull(x, shape=1/sigma, scale=exp(mu))
dgengamma(x, mu, sigma, Q=sigma) = dgamma(x, shape=1/sigma^2, rate=exp(-mu) / sigma^2)
Stacy & Mihram 1965 definition of the rth moment:
$E(X^r) = \begin{cases} a^r\Gamma((p\nu + r)/p), & r/p > -\nu\ \infty, & \textup{otherwise} \end{cases}$
Note to self, for the mean,
If we rewrite the equation from Stacy & Mihram 1965 using the notation of Lawless 1980 (and match what is the gengamma MS draft: (i.e.,
And then use the parameterisations:
- Lawless eqn (2):
$u = log(a)$ such that$a = e^u$ - And the Lawless parameterisation in eqn(3) and also using the Q parameterisation:
$Q = k^{-1/2}$ also$k = Q^{-2}$ we can get:
sigma | mu |
---|---|
-----> OOOOH
A reminder that
We get:
$\begin{align}
mean = \frac{\Gamma (\frac{k\beta + 1}{\beta})}{\Gamma k}\cdot e^{\mu - \frac{\sigma\log(Q^{-2})}{Q}} \nonumber \end{align}$
alternatively, to solve for
k <- q^(-2)
beta <- Q / sigma
# This works
mu <- log(mean) - lgamma((k * beta + 1) / beta) + lgamma(k) + (sigma * log(q^(-2)) /q)
mean <- (gamma((k * beta + 1) / beta) / gamma(k)) * exp(mu - (sigma * log(Q^(-2)) / Q))
Calculate PDF in R/cpp
# In R
Q <- 0.2
sigma <- 0.9
mean <- 0.34
mu <- mu_from_mean(mean = mean, Q = Q, sigma = sigma)
x <- 2
# From flexsurv
y = log(x)
w = (y - mu) / sigma
abs_Q = abs(Q)
qi = 1 / (Q^2)
qw = Q * w
-log(sigma * x) + log(abs_Q) * (1 - 2 * qi) + qi * (qw - exp(qw)) - lgamma(qi)
# Rewrite in terms of Q
-log(sigma * x) + log(abs(Q)) * (1 - 2 * Q^-2) + (Q^-2) * (Q * w - exp(Q * w)) - lgamma(Q^-2)
# Simplify
- log(sigma * x) + log(abs(Q)^(1 - 2 * Q^-2)) + (Q^-2) * (Q * w - exp(Q * w)) - lgamma(Q^-2)
log(abs(Q)^(1 - 2 * Q^-2) / (sigma * x)) + (Q^-2) * (Q * w - exp(Q * w)) - lgamma(Q^-2)
log(abs(Q)^(1 - 2 * Q^-2) / (sigma * x * gamma(Q^-2))) + (Q^-2) * (Q * w - exp(Q * w))
log(abs(Q)^(1 - 2 * Q^-2) / (sigma * x * gamma(Q^-2)) * exp((Q^-2) * (Q * w - exp(Q * w))))
exp(log(abs(Q)^(1 - 2 * Q^-2) / (sigma * x * gamma(Q^-2)) * exp((Q^-2) * (Q * w - exp(Q * w)))))
(abs(Q)^(1 - 2 * Q^-2) / (sigma * x * gamma(Q^-2))) * exp((Q^-2) * (Q * w - exp(Q * w)))
((abs(Q)^(1) / (abs(Q)^ (2 * Q^-2))) / (sigma * x * gamma(Q^-2))) * exp((Q^-2) * (Q * w - exp(Q * w)))
# Use abs(Q) = (Q^2) ^ (1/2)
((abs(Q)^(1) / (((Q^2)^(1/2))^(2 * Q^-2))) / (sigma * x * gamma(Q^-2))) * exp((Q^-2) * (Q * w - exp(Q * w)))
# Simplify exponents
((abs(Q) / (Q^ (2 * (Q^-2)))) / (sigma * x * gamma(Q^-2))) * exp((Q^-2) * (Q * w - exp(Q * w)))
# Match gen gamma MS draft Table 5 PDF equation:
((abs(Q) * (Q^ -(2 * (Q^-2)))) / (sigma * x * gamma(Q^-2))) * exp((Q^-2) * (Q * w - exp(Q * w)))
# Question for Jim, I don't clearly see where this equation comes from based on Stacy & Mihram, Prentice, and Lawless
simplify before exponentiating:
exponentiate:
From Prentice: transformation of k can give us
Model:
Can also be written as:
where density function for
Variance function:
Gamma distribution:
sdmTMB gamma parameterisation:
s1 = exp(ln_phi(m)); // shape
Lognormal distribution:
mu = 1
sigma2 = 0.5
.mean = exp(mu + sigma2 / 2)
.var = (exp(sigma2) - 1) * exp(2 * mu + sigma2)
.sd = sqrt((exp(sigma2) - 1) * exp(2 * mu + sigma2))
sd / mean