Type: Package
Title: Piecewise Lifetime Models
Version: 1.0
Date: 2026-02-02
Maintainer: Diego Gallardo <dgallardo@ubiobio.cl>
Description: Provides functions for estimation and data generation for several piecewise lifetime distributions. The package implements the power piecewise Weibull model, which includes the piecewise Rayleigh and piecewise exponential models as special cases. See Feigl and Zelen (1965) <doi:10.2307/2528247> for methodological details.
Depends: R (≥ 4.0.0), stats
Imports: survival, pracma, segmented, msm, nloptr
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
NeedsCompilation: no
Packaged: 2026-02-02 03:12:31 UTC; Diego
Author: Diego Gallardo [aut, cre], Yolanda Gomez [aut], Hector Gomez [aut], Barry Arnold [aut]
Repository: CRAN
Date/Publication: 2026-02-04 18:10:02 UTC

Choose a Partition for a Power Piecewise Weibull Model

Description

Selects a time partition for the power piecewise Weibull model, given a maximum number of allowed partitions. For choose.pweibull, the user may specify whether the \lambda's are equal (default FALSE), whether the \alpha's are equal (default FALSE), and whether \alpha is fixed (default FALSE). For choose2.pweibull, the procedure selects the best combination among:

Usage

choose.pweibull(formula, data, criteria = "AIC", L.max = 5, t = NULL, 
    prec = 1e-04, max.iter = 1000, lambda.identical = FALSE, 
    alpha.identical = FALSE, alpha.fixed = FALSE)

choose2.pweibull(formula, data, criteria = "AIC", L.max = 5, t = NULL, 
    prec = 1e-04, max.iter = 1000, alpha.fixed = c(1, 2))

Arguments

formula

A model formula of class "formula" describing the survival model to be fitted. Details about model specification are given in Details.

data

An optional data frame, list, or environment containing the variables in the model. If not found in data, variables are taken from environment(formula).

criteria

Model selection criterion: "AIC" (default) or "BIC".

L.max

Maximum number of partitions to consider (default 5).

t

Optional fixed time partition. If provided, both choose.pweibull and choose2.pweibull evaluate only the model combinations with the specified partition.

prec

Numerical tolerance for the estimation algorithm (default 1e-4).

max.iter

Maximum number of iterations for the estimation algorithm (default 1000).

lambda.identical

Logical; should the \lambda's be constrained to be equal? (default FALSE).

alpha.identical

Logical; should the \alpha's be constrained to be equal? (default FALSE).

alpha.fixed

If FALSE (default), \alpha is estimated. If a positive numeric value is supplied, all \alpha's are fixed at that value. For choose2.pweibull, this may be a vector of fixed values.

Details

The hazard function of the power piecewise Weibull model is

h(t \mid \boldsymbol{\lambda}, \boldsymbol{\alpha}) = \lambda_\ell \alpha_\ell t^{\alpha_\ell - 1}, \qquad t \in (a_{\ell-1}, a_\ell),\; \ell = 1,\ldots,L,

where 0 = a_0 < a_1 < \cdots < a_L < \infty is the time partition, \boldsymbol{\lambda} = (\lambda_1,\ldots,\lambda_L) and \boldsymbol{\alpha} = (\alpha_1,\ldots,\alpha_L).

The special cases include:

Value

A list with components:

estimate

A matrix of parameter estimates and standard errors for the selected partition.

logLik

Log-likelihood evaluated at the parameter estimates.

t

Selected time partition.

AIC

Akaike Information Criterion.

BIC

Bayesian Information Criterion.

L.sel

Number of selected partitions.

AIC.L

AIC values for L = 1, \ldots, L.max.

BIC.L

BIC values for L = 1, \ldots, L.max.

Author(s)

Diego I. Gallardo, Yolanda M. Gomez, Hector W. Gomez, and Barry C. Arnold.

References

Feigl P., Zelen M. (1965). Estimation of exponential survival probabilities with concomitant information. Biometrics, 21, 826-838.

Friedman M. (1982). Piecewise exponential models for survival data with covariates. Annals of Statistics, 10, 101-113.

Gomez Y. M., Gallardo D. I., Arnold B. C. (2018). The power piecewise exponential model. Journal of Statistical Computation and Simulation, 88, 825-840.

Examples



library(survival)
set.seed(3100)

n  <- 200
x1 <- rnorm(n)
x2 <- rnorm(n)

## drawing covariates
lambda <- c(0.05, 0.03)
rate   <- exp(cbind(x1, x2) %*% c(0.5, -0.5))

time2 = c()
for (i in 1:n)
  time2[i] <- rpweibull(1, rate = lambda * rate[i], alpha = c(1, 1), t = c(0, 10))

delta <- rbinom(n, size = 1, prob = 0.75)
cc    <- runif(n, 0, max(time2))
time  <- ifelse(delta == 1, time2, cc)

data  <- data.frame(time = time, x1 = x1, x2 = x2, delta = delta)

choose.pweibull(survival::Surv(time, delta) ~ x1 + x2, data = data, L.max = 3)


Parameter Estimation for the Power Piecewise Weibull Model

Description

Fits the power piecewise Weibull model and returns parameter estimates, standard errors, likelihood measures, and the selected time partition.

Usage

fit.pweibull(formula, data, L = 1, t = NULL, prec = 1e-04, max.iter = 1000,
    lambda.identical = FALSE, alpha.identical = FALSE, alpha.fixed = FALSE)

Arguments

formula

A model formula of class "formula" describing the survival model to be fitted. Details on model specification are given in Details.

data

An optional data frame, list, or environment containing the variables in the model. If not found in data, variables are taken from environment(formula).

L

Number of partitions to be used. Ignored if t is specified.

t

A fixed time partition. Ignored if L is supplied.

prec

Numerical tolerance used in the estimation procedure (default 1e-4).

max.iter

Maximum number of iterations allowed in the estimation algorithm (default 1000).

lambda.identical

Logical; should the \lambda's be constrained to be equal? (default FALSE).

alpha.identical

Logical; should the \alpha's be constrained to be equal? (default FALSE).

alpha.fixed

Should \alpha be fixed at a known value? If FALSE (default), \alpha is estimated. If a positive number is provided, all \alpha_\ell are fixed at that value.

Details

The hazard function of the power piecewise Weibull model is given by

h(t \mid \boldsymbol{\lambda}, \boldsymbol{\alpha}) = \lambda_\ell \alpha_\ell t^{\alpha_\ell - 1}, \qquad t \in (a_{\ell-1}, a_\ell),\; \ell = 1, \ldots, L,

where 0 = a_0 < a_1 < \cdots < a_L < \infty defines the time partition, \boldsymbol{\lambda} = (\lambda_1, \ldots, \lambda_L) and \boldsymbol{\alpha} = (\alpha_1, \ldots, \alpha_L).

Special cases include:

Value

A list with components:

estimate

A matrix containing parameter estimates and corresponding standard errors.

logLik

Log-likelihood evaluated at the estimated parameters.

t

The time partition used.

AIC

Akaike Information Criterion.

BIC

Bayesian Information Criterion.

Author(s)

Diego I. Gallardo, Yolanda M. Gomez, Hector W. Gomez, and Barry C. Arnold.

References

Feigl P., Zelen M. (1965). Estimation of exponential survival probabilities with concomitant information. Biometrics, 21, 826-838.

Friedman M. (1982). Piecewise exponential models for survival data with covariates. Annals of Statistics, 10, 101-113.

Gomez Y. M., Gallardo D. I., Arnold B. C. (2018). The power piecewise exponential model. Journal of Statistical Computation and Simulation, 88, 825-840.

Examples


library(survival)
set.seed(3100)

n  <- 200
x1 <- rnorm(n)
x2 <- rnorm(n)

## design matrix
x  <- model.matrix(~ x1 + x2)[, -1]

lambda <- c(0.05, 0.03)
rate   <- exp(cbind(x1, x2) %*% c(0.5, -0.5))

time <- numeric(n)
for (i in 1:n)
  time[i] <- rpweibull(1, rate = lambda * rate[i], alpha = c(1, 1), t = c(0, 10))

delta <- rep(1, n)

data <- data.frame(time = time, delta = delta, x1 = x1, x2 = x2)

fit.pweibull(survival::Surv(time, delta) ~ x1 + x2, data = data, L = 2)


The Power Piecewise Weibull Distribution

Description

Density, distribution function, quantile function, and random generation for the power piecewise Weibull distribution.

Usage

dpweibull(x, rate = 1, alpha = 1, t = 0, log = FALSE)

ppweibull(q, rate = 1, alpha = 1, t = 0, lower.tail = TRUE, log.p = FALSE)

qpweibull(p, rate = 1, alpha = 1, t = 0, lower.tail = TRUE, log.p = FALSE)

rpweibull(n = 1, rate = 1, alpha = 1, t = 0)

Arguments

x

Vector of quantiles for the density function.

q

Vector of quantiles for the distribution function.

p

Vector of probabilities for the quantile function.

n

Number of observations to generate. If length(n) > 1, the length is taken as the number of observations.

rate

A numeric vector of length L containing the rate parameters \lambda_1, \ldots, \lambda_L.

alpha

A numeric vector of length L containing the shape parameters \alpha_1, \ldots, \alpha_L.

t

A non-decreasing vector defining the time partition (0 = a_0, a_1, \ldots, a_L).

log

Logical; if TRUE, probabilities are returned on the log scale.

lower.tail

Logical; if TRUE (default), probabilities are P(T \le q); otherwise P(T > q).

log.p

Logical; if TRUE, probabilities p are given on the log scale.

Details

The hazard function of the power piecewise Weibull model is

h(t \mid \boldsymbol{\lambda}, \boldsymbol{\alpha}) = \lambda_\ell \alpha_\ell t^{\alpha_\ell - 1}, \qquad t \in (a_{\ell - 1}, a_\ell),\; \ell = 1, \ldots, L,

where 0 = a_0 < a_1 < \cdots < a_{L - 1} < a_L < \infty defines the partition of time, \boldsymbol{\lambda} = (\lambda_1, \ldots, \lambda_L), and \boldsymbol{\alpha} = (\alpha_1, \ldots, \alpha_L).

Special cases include:

Value

dpweibull returns the density, ppweibull returns the distribution function, qpweibull returns the quantile function, and rpweibull generates random deviates.

For rpweibull, the result has length n. For the other functions, the result has length equal to the maximum of the lengths of the numerical arguments. Arguments are recycled as needed.

Only the first elements of the logical arguments log, lower.tail, and log.p are used.

References

Feigl P., Zelen M. (1965). Estimation of exponential survival probabilities with concomitant information. Biometrics, 21, 826-838.

Friedman M. (1982). Piecewise exponential models for survival data with covariates. Annals of Statistics, 10, 101-113.

Gomez Y. M., Gallardo D. I., Arnold B. C. (2018). The power piecewise exponential model. Journal of Statistical Computation and Simulation, 88, 825-840.

Examples

set.seed(3100)
## Random sample
rpweibull(n = 10, rate = c(0.05, 0.03), alpha = c(1, 1.5), t = c(0, 10))
## Distribution function
ppweibull(c(5, 10, 20), rate = c(0.05, 0.03), alpha = c(1, 1.5), t = c(0, 10))