Learn R Programming

npsurv (version 0.3-3)

plot.Uhaz: Plot Functions for U-shaped Hazard Estimation

Description

plot.Uhaz and plot.uh are wrapper functions that can be used to invoke plot.hazuh, plot.chazuh, plot.survuh, plot.denuh or plot.graduh.

plothazuh plots a U-shaped hazard function.

plotchazuh plots a cumulative hazard function that has a U-shaped hazard function.

plotsurvuh plots the survival function that has a U-shaped hazard function.

plotdenuh plots the density function that has a U-shaped hazard function.

plotgraduh plots the gradient function that has a U-shaped hazard function.

Usage

## S3 method for class 'Uhaz':
plot(x, ...)
## S3 method for class 'uh':
plot(x, data, fn=c("haz","grad","surv","den","chaz"), ...)
plothazuh(h, add=FALSE, col="darkblue", lty=1, xlim, ylim,
          lwd=2, pch=19, len=500, vert=FALSE, add.knots=TRUE,
          xlab="Time", ylab="Hazard", ...)
plotchazuh(h, add=FALSE, lwd=2, len=500, col="darkblue",
           pch=19, add.knots=TRUE, vert=FALSE, xlim, ylim, ...)
plotdenuh(h, add=FALSE, lty=1, lwd=2, col="darkblue",
          add.knots=TRUE, pch=19, ylim, len=500, vert=FALSE, ...)
plotsurvuh(h, add=FALSE, lty=1, lwd=2, len=500, vert=FALSE,
           col="darkblue", pch=19, add.knots=TRUE, xlim, ylim, ...)
plotgraduh(h, data, w=1, len=500, xlim, ylim, vert=TRUE,
           add=FALSE, xlab="Time", ylab="Gradient",
           col0="red3", col1="blue3", col2="green3", order=0, ...)

Arguments

x
an object of class Uhaz, i.e., an output of function Uhaz, or an object of class uh..
h
an object of class uh.
data
vector or matrix that stores observations, or an object of class icendata.
w
additional weights/multiplicities for the observations stored in x.
fn
function to be plotted. It can be

= haz, for hazard function;

= chaz, for cumulative hazard function;

= den, for density function;

= surv, for survival function;

= gradien

xlim, ylim
numeric vectors of length 2, giving the x and y coordinates ranges.
xlab, ylab
x- or y-axis labels.
add
= TRUE, adds the curve to the existing plot;

= FALSE, plots the curve in a new one.

col
color used for plotting the curve.
lty
line type for plotting the curve.
lwd
line width for plotting the curve.
len
number of points used to plot a curve.
add.knots
logical, indicating if knots are also plotted.
pch
point character/type for plotting knots.
vert
logical, indicating if grey vertical lines are plotted to show the interval that separates the two discrete measures.
col0
color for gradient function 0, i.e., for the hazard-constant part, or alpha.
col1
color for gradient function 1, i.e., for the hazard-decreasing part.
col2
color for gradient function 1, i.e., for the hazard-increasing part.
order
= 0, the gradient functions are plotted;

= 1, their first derivatives are plotted;

= 2, their second derivatives are plotted.

...
arguments for other graphical parameters (see par).

Details

A U-shaped hazard function is given by

$$h(t) = \alpha + \sum_{j = 1}^k \nu_j(\tau_j - t)_+^p + \sum_{j = 1}^{m} \mu_j (t-\eta_j)_+^p,$$

where $\alpha,\nu_j,\mu_j \ge 0$, $\tau_1 < \cdots < \tau_k \le \eta_1 < \cdots < \eta_m,$ and $p \ge 0$.

References

Wang, Y. and Fani, S. (2015). Nonparametric maximum likelihood computation of a U-shaped hazard function. (In preparation)

See Also

icendata, uh, npsurv.

Examples

Run this code
## Angina Pectoris Survival Data
data(ap)
plot(r<-Uhaz(ap))              # hazard function for a convex hazard
plot(r, fn="c")                # cumulative hazard function
plot(r, fn="s")                # survival function
plot(r, fn="d")                # density function
plot(r, ap, fn="g")            # gradient functions
plot(r, ap, fn="g", order=1)   # first derivatives of gradient functions
plot(r, ap, fn="g", order=2)   # second derivatives of gradient functions

## New Zealand Mortality in 2000
data(nzmort)
i = nzmort$ethnic == "maori"
x = nzmort[i,1:2]                            # Maori mortality
h = Uhaz(x[,1]+0.5, x[,2], deg=2)$h          # smooth U-shaped hazard
plot(h)                        # hazard function
plot(h, fn="d")                # density function
plot(h, fn="s")                # survival function

x2 = nzmort[!i,1:2]                          # Non-Maori mortality
h2 = Uhaz(x2[,1]+0.5, x2[,2], deg=2)$h
plot(h2, fn="s", add=TRUE, col="green3")

Run the code above in your browser using DataLab