afttest: Model Diagnostics for Semiparametric AFT Models

View source: R/afttest.R

afttestR Documentation

Model Diagnostics for Semiparametric AFT Models

Description

Performs model-checking procedures for a semiparametric AFT model. This is a generic function with methods for formulas and fitted objects from the aftgee package.

Usage

afttest(object, ...)

Arguments

object

A formula or a fitted model object (e.g., from aftsrr or aftgee).

...

Other arguments passed to methods. See the documentation for afttest.formula and afttest.aftsrr for details.

Value

An object of class afttest or htest. An object is a list containing at least the following components:

beta

a vector of beta estimates based on estMethod

hypothesis

null hypothesis for each testType

SE_process

estimated standard error of the observed process

obs_process

observed process

apprx_process

approximated process

obs_std_process

standardized observed process

apprx_std_process

standardized approximated processes

p_value

obtained by the unstandardized test

p_std_value

obtained by the standardized test

DF

a data frame of observed failure time, right censoring indicator, covariates (scaled), time-transformed residual based on beta estimates

npath

the number of sample paths

testType

testType

eqType

eqType

estMethod

estMethod

npathsave

npathsave

For an omnibus test, the observed process and the realizations are composed of the n by n matrix where rows represent the t and columns represent the x in the time-transformed residual order. The observed process and the simulated processesfor checking a functional form and a link function are given by the n by 1 vectorwhich is a function of x in the time-transformed residual order.

Examples

library(survival)
library(aftgee)
library(afttest)

datgen <- function(n = 100) {
  z1 <- rbinom(n, 1, 0.5)
  z2 <- rnorm(n)
  e <- rnorm(n)
  tt <- exp(2 + z1 + z2 + 0.5 * z2^2 + e)
  cen <- runif(n, 0, 100)
  data.frame(Time = pmin(tt, cen), status = 1 * (tt < cen),
             z1 = z1, z2 = z2, id = 1:n)
}
set.seed(1)
simdata <- datgen(300)

# --------------------------------------------------
# Method 1: Formula (Runs quickly for CRAN tests)
# --------------------------------------------------
result_form <- afttest(Surv(Time, status) ~ z1 + z2, data = simdata,
                       npath = 50, testType = "covForm", estMethod = "rr",
                       eqType = "ns", covTested = "z2", npathsave = 50,
                       linApprox = TRUE, seed = 1)
print(result_form)
plot(result_form, std = TRUE)


# --------------------------------------------------
# Method 2: Fitted aftsrr object (Induced Smoothing)
# --------------------------------------------------
fit_srr <- aftsrr(Surv(Time, status) ~ z1 + z2, data = simdata, 
                  eqType = "is", rankWeights = "gehan")
result_srr <- afttest(fit_srr, data = simdata, npath = 100, testType = "covForm", 
                      covTested = "z2", npathsave = 50, 
                      linApprox = TRUE, seed = 1)
summary(result_srr)
plot(result_srr, std = FALSE)

# --------------------------------------------------
# Method 3: Fitted aftgee object (Least Squares)
# --------------------------------------------------
fit_gee <- aftgee(Surv(Time, status) ~ z1 + z2, data = simdata)
result_gee <- afttest(fit_gee, data = simdata, npath = 100, testType = "covForm", 
                      covTested = "z2", npathsave = 50, 
                      linApprox = TRUE, seed = 1)
print(result_gee)

# --------------------------------------------------
# Method 4: Standard Resampling (linApprox = FALSE)
# --------------------------------------------------
result_resamp <- afttest(Surv(Time, status) ~ z1 + z2, data = simdata,
                         npath = 100, testType = "covForm", estMethod = "rr",
                         eqType = "ns", covTested = "z2", npathsave = 50,
                         linApprox = FALSE, seed = 1)
summary(result_resamp)


afttest documentation built on March 22, 2026, 5:06 p.m.