plot.afttest: Plotting Method for Semiparametric AFT Model Diagnostics

View source: R/generic.R

plot.afttestR Documentation

Plotting Method for Semiparametric AFT Model Diagnostics

Description

Plotting Method for Semiparametric AFT Model Diagnostics

Usage

## S3 method for class 'afttest'
plot(x, npath = 50, std = TRUE, quantile = NULL, ...)

Arguments

x

An object of class afttest.

npath

A numeric value specifying the number of approximated processes to plot. The default is set to 50.

std

A logical value specifying if the graph is based on the standardized test statistics (TRUE) or unstandardized (FALSE). The default is TRUE.

quantile

A numeric vector specifying 5 quantiles within the range [0,1]. The default is set to c(0.1, 0.25, 0.5, 0.75, 0.9).

...

Other arguments passed to methods for future extension.

Value

plot.afttest returns a plot based on the testType:

omnibus

an x of the omnibus test is the form of n by n matrix, some quantiles of x, which are used in weight, are plotted for graphs, i.e. 10%, 25%, 50%, 75%, and 90% are used by default.

link

an x of the link function test is the form of n by 1 matrix

covForm

an x of the functional form test is the form of n by 1 matrix

See the documentation of ggplot2 and gridExtra for details.

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.