Description Usage Arguments Details Value Examples
View source: R/nll_functions.R
Function calculating negative log-likelihood (nll) for the observed patterns of mortality in infected and uninfected treatments when it assumed there is unobserved variation in virulence.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | nll_frailty(
a1 = a1,
b1 = b1,
a2 = a2,
b2 = b2,
theta = theta,
data = data,
time = time,
censor = censor,
infected_treatment = infected_treatment,
d1 = "Weibull",
d2 = "Weibull",
d3 = ""
)
|
a1, b1 |
location and scale parameters describing background mortality |
a2, b2 |
location and scale parameters describing mortality due to infection |
theta |
parameter describing variance of unobserved variation in virulence |
data |
name of data frame containing survival data |
time |
name of data frame column identifying time of event; time > 0 |
censor |
name of data frame column idenifying if event was death (0) or right-censoring (1) |
infected_treatment |
name of data frame column identifying if data are from an infected (1) or uninfected (0) treatment |
d1, d2 |
names of probability distributions chosen to describe background mortality and mortality due to infection, respectively; both default to the Weibull distribution |
d3 |
name of probability distribution chosen to describe unobserved frailty; choice of 'gamma' or 'inverse Gaussian' |
The function assumes the unobserved variation in the rate of mortality due to infection is continuously distributed and follows either the gamma distribution or the inverse Gaussian distribution, with mean = 1 and variance = theta.
The nll is based on five parameter functions for the location and scale parameters for background mortality and mortality due to infection, respectively, plus a parameter estimating the variance of the unobserved variation in virulence.
numeric
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 | ### Example 1: unobserved variation in virulence described by gamma distribution
# step #1: parameterise nll function to be passed to 'mle2'
m01_prep_function <- function(a1 = a1, b1 = b1, a2 = a2, b2 = b2, theta = theta){
nll_frailty(
a1 = a1, b1 = b1, a2 = a2, b2 = b2, theta = theta,
data = data_lorenz,
time = t,
censor = censored,
infected_treatment = g,
d1 = "Gumbel",
d2 = "Weibull",
d3 = "Gamma"
)}
# step #2: send 'prep_function' to 'mle2' for maximum likelihood estimation
m01 <- mle2(
m01_prep_function,
start = list(a1 = 20, b1 = 5, a2 = 3, b2 = 0.1, theta = 2)
)
summary(m01)
### Example 2: unobserved variation in virulence described by inverse Gaussian distribution
m02_prep_function <- function(a1 = a1, b1 = b1, a2 = a2, b2 = b2, theta = theta){
nll_frailty(
a1 = a1, b1 = b1, a2 = a2, b2 = b2, theta = theta,
data = data_lorenz,
time = t,
censor = censored,
infected_treatment = g,
d1 = "Gumbel",
d2 = "Weibull",
d3 = "Inverse Gaussian"
)}
m02 <- mle2(
m02_prep_function,
start = list(a1 = 20, b1 = 5, a2 = 3, b2 = 0.1, theta = 2)
)
summary(m02)
# compare model estimates by AICc
AICc(m01, m02, nobs = 256)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.