Learn R Programming

reda (version 0.3.1)

rateReg: Recurrent Events Regression Based on Counts and Rate Function

Description

The default model is the gamma frailty model with one piece constant baseline rate function, which is equivalent to negative binomial regression with the same shape and rate parameter in the gamma prior. Spline (including piecewise constant) baseline rate function can also be specified and applied to model fitting. Both B-spline and M-spline bases are available. rateReg returns the fitted model through a rateReg-class object.

Usage

rateReg(formula, data, subset, df = NULL, knots = NULL,
        degree = 0L, na.action, spline = c("bSplines", "mSplines"),
        start = list(), control = list(), contrasts = NULL, ...)

Arguments

formula

Survr object produced by function Survr.

data

An optional data frame, list or environment containing the variables in the model. If not found in data, the variables are taken from environment(formula), usually the environment from which function rateReg is called.

subset

An optional vector specifying a subset of observations to be used in the fitting process.

df

An optional nonnegative integer to specify the degree of freedom of baseline rate function. If argument knots or degree are specified, df will be neglected whether it is specified or not.

knots

An optional numeric vector that represents all the internal knots of baseline rate function. The default is NULL, representing no any internal knots.

degree

An optional nonnegative integer to specify the degree of spline bases.

na.action

A function that indicates what should the procedure do if the data contains NAs. The default is set by the na.action setting of options. The "factory-fresh" default is na.omit. Other possible values inlcude na.fail, na.exclude, and na.pass. help(na.fail) for details.

spline

An optional character that specifies the flavor of splines. The possible option is bSplines for B-splines or mSplines for M-splines. Partial matching on the names is allowed.

start

An optional list of starting values for the parameters to be estimated in the model. See more in Section details.

control

An optional list of parameters to control the maximization process of negative log likelihood function and adjust the baseline rate function. See more in Section details.

contrasts

An optional list, whose entries are values (numeric matrices or character strings naming functions) to be used as replacement values for the contrasts replacement function and whose names are the names of columns of data containing factors. See contrasts.arg of model.matrix.default for details.

...

Other arguments for future usage.

Value

A rateReg-class object, whose slots include

  • call: Function call of rateReg.

  • formula: Formula used in the model fitting.

  • nObs: Number of observations.

  • spline: A list contains

    • spline: The name of splines used.

    • knots: Internal knots specified for the baseline rate function.

    • Boundary.knots: Boundary knots specified for the baseline rate function.

    • degree: Degree of spline bases specified in baseline rate function.

    • df: Degree of freedom of the model specified.

  • estimates: Estimated coefficients of covariates and baseline rate function, and estimated rate parameter of gamma frailty variable.

  • control: The control list specified for model fitting.

  • start: The initial guess specified for the parameters to be estimated.

  • na.action: The procedure specified to deal with missing values in the covariate.

  • xlevels: A list that records the levels in each factor variable.

  • contrasts: Contrasts specified and used for each factor variable.

  • convergCode: code returned by function nlm, which is an integer indicating why the optimization process terminated. help(nlm) for details.

  • logL: Log likelihood of the fitted model.

  • fisher: Observed Fisher information matrix.

Details

Function Survr in the formula response by default first checks the dataset and will report an error if the dataset does not fall into recurrent event data framework. Subject's ID will be pinpointed if its observation violates any checking rule. See Survr for all the checking rules.

Function rateReg first constructs the design matrix from the specified arguments: formula, data, subset, na.action and constrasts before model fitting. The constructed design matrix will be checked again to fit the recurrent event data framework if any observation with missing covariates is removed.

The model fitting process involves minimization of negative log likelihood function, which calls function nlm from package stats internally. help(nlm) for more details.

The argument start is an optional list that allows users to specify the initial guess for the parameter values for the minimization of negative log likelihood function. The available numeric vector elements in the list include

  • beta: Coefficient(s) of covariates, set to be 0.1 by default.

  • theta: Parameter in Gamma(theta, 1 / theta) for frailty random effect, set to be 0.5 by default.

  • alpha: Coefficient(s) of baseline rate function, set to be 0.05 by default.

The argument control is an optional list that allows users to control the process of minimization of negative log likelihood function and to specify the boundary knots, intercept for baseline rate function. The available elements in the list include

  • gradtol: A positive scalar giving the tolerance at which the scaled gradient is considered close enough to zero to terminate the algorithm. The default value is 1e-6.

  • stepmax: A positive scalar that gives the maximum allowable scaled step length. The default value is 1e5.

  • steptol: A positive scalar providing the minimum allowable relative step length. The default value is 1e-6.

  • iterlim: A positive integer specifying the maximum number of iterations to be performed before the program is terminated. The default value is 1e2.

  • Boundary.knots: A length-two numeric vector to specify the boundary knots for baseline rate funtion. By default, the left boundary knot is zero and the right one takes the largest censoring time from data.

  • verbose: A optional logical value with default TRUE. Set it to be FALSE to supress any possible message from this function.

References

Fu, H., Luo, J., & Qu, Y. (2016). Hypoglycemic events analysis via recurrent time-to-event (HEART) models. Journal Of Biopharmaceutical Statistics, 26(2), 280--298.

See Also

summary,rateReg-method for summary of fitted model; coef,rateReg-method for estimated covariate coefficients; confint,rateReg-method for confidence interval of covariate coefficients; baseRate,rateReg-method for estimated coefficients of baseline rate function; mcf,rateReg-method for estimated MCF from a fitted model; plot,rateRegMcf-method for plotting estimated MCF.

Examples

Run this code
# NOT RUN {
library(reda)

## constant rate function
(constFit <- rateReg(Survr(ID, time, event) ~ group + x1, data = simuDat))

## six pieces' piecewise constant rate function
(piecesFit <- rateReg(Survr(ID, time, event) ~ group + x1,
                      data = simuDat, subset = ID %in% 1:50,
                      spline = "bSplines", knots = seq(28, 140, by = 28)))

## fit rate function with cubic spline
(splineFit <- rateReg(Survr(ID, time, event) ~ group + x1, data = simuDat,
                      spline = "mSpl", knots = c(56, 84, 112), degree = 3))

## more specific summary
summary(constFit)
summary(piecesFit)
summary(splineFit)

## model selection based on AIC or BIC
AIC(constFit, piecesFit, splineFit)
BIC(constFit, piecesFit, splineFit)

## estimated covariate coefficients
coef(piecesFit)
coef(splineFit)

## confidence intervals for covariate coefficients
confint(piecesFit)
confint(splineFit, "x1", 0.9)
confint(splineFit, 1, 0.975)

## estimated baseline rate function
splinesBase <- baseRate(splineFit)
plot(splinesBase, conf.int = TRUE)

## estimated baseline mean cumulative function (MCF) from a fitted model
piecesMcf <- mcf(piecesFit)
plot(piecesMcf, conf.int = TRUE, col = "blueviolet")

## estimated MCF for given new data
newDat <- data.frame(x1 = rep(0, 2), group = c("Treat", "Contr"))
splineMcf <- mcf(splineFit, newdata = newDat, groupName = "Group",
                 groupLevels = c("Treatment", "Control"))
plot(splineMcf, conf.int = TRUE, lty = c(1, 5))

## example of further customization by ggplot2
# }
# NOT RUN {
library(ggplot2)
plot(splineMcf) +
    geom_ribbon(aes(x = time, ymin = lower,
                    ymax = upper, fill = Group),
                data = splineMcf@MCF, alpha = 0.2) +
    xlab("Days")
# }

Run the code above in your browser using DataLab