library(EstimationTools)
#--------------------------------------------------------------------------------
# Example 1: Estimation in simulated normal distribution
n <- 1000
x <- runif(n = n, -5, 6)
y <- rnorm(n = n, mean = -2 + 3 * x, sd = exp(1 + 0.3* x))
norm_data <- data.frame(y = y, x = x)
# It does not matter the order of distribution parameters
formulas <- list(sd.fo = ~ x, mean.fo = ~ x)
support <- list(interval = c(-Inf, Inf), type = 'continuous')
norm_mod <- maxlogLreg(formulas, y_dist = y ~ dnorm, support = support,
data = norm_data,
link = list(over = "sd", fun = "log_link"))
summary(norm_mod)
#--------------------------------------------------------------------------------
# Example 2: Fitting with censorship
# (data from https://www.itl.nist.gov/div898/handbook/apr/section4/apr413.htm)
failures <- c(55, 187, 216, 240, 244, 335, 361, 373, 375, 386)
fails <- c(failures, rep(500, 10))
status <- c(rep(1, length(failures)), rep(0, 10))
Wei_data <- data.frame(fails = fails, status = status)
# Formulas with linear predictors
formulas <- list(scale.fo=~1, shape.fo=~1)
support <- list(interval = c(0, Inf), type = 'continuous')
# Bounds for optimization. Upper bound set with default values (Inf)
start <- list(
scale = list(Intercept = 100),
shape = list(Intercept = 10)
)
lower <- list(
scale = list(Intercept = 0),
shape = list(Intercept = 0)
)
mod_weibull <- maxlogLreg(formulas, y_dist = Surv(fails, status) ~ dweibull,
support = c(0, Inf), start = start,
lower = lower, data = Wei_data)
summary(mod_weibull)
#--------------------------------------------------------------------------------
Run the code above in your browser using DataLab