score_and_hessian_matrix_functions {CIEE}R Documentation

Score and hessian matrix based on the estimating functions.

Description

Functions to compute the score and hessian matrices of the parameters based on the estimating functions, under the GLM and AFT setting for the analysis of a normally-distributed or censored time-to-event primary outcome. The score and hessian matrices are further used in the functions sandwich_se, ciee and ciee_loop to obtain robust sandwich error estimates of the parameter estimates of \alpha_0, \alpha_1, \alpha_2, \alpha_3, \sigma_1^2, \alpha_4, \alpha_{XY}, \sigma_2^2 under the GLM setting and \alpha_0, \alpha_1, \alpha_2, \alpha_3, \sigma_1, \alpha_4, \alpha_{XY}, \sigma_2^2 under the AFT setting.

Usage

deriv_obj(setting = "GLM", logL1 = NULL, logL2 = NULL, Y = NULL,
  X = NULL, K = NULL, L = NULL, C = NULL, estimates = NULL)

scores(derivobj = NULL)

hessian(derivobj = NULL)

Arguments

setting

String with value "GLM" or "AFT" indicating whether the matrices are computed under the GLM or AFT setting.

logL1

Expression of the function logL1 generated by the est_funct_expr function.

logL2

Expression of the function logL2 generated by the est_funct_expr function.

Y

Numeric input vector for the primary outcome.

X

Numeric input vector for the exposure variable.

K

Numeric input vector for the intermediate outcome.

L

Numeric input vector for the observed confounding factor.

C

Numeric input vector for the censoring indicator under the AFT setting (must be coded 0 = censored, 1 = uncensored).

estimates

Numeric input vector with point estimates of the parameters \alpha_0, \alpha_1, \alpha_2, \alpha_3, \sigma_1^2, \alpha_4, \alpha_{XY}, \sigma_2^2 under the GLM setting and of \alpha_0, \alpha_1, \alpha_2, \alpha_3, \sigma_1, \alpha_4, \alpha_{XY}, \sigma_2^2 under the AFT setting. Under the AFT setting, estimates must also contain the mean of the estimated true survival times "y_adj_bar".

derivobj

Output of the deriv_obj function used as input in the scores and hessian functions.

Details

For the computation of the score and hessian matrices, first, the help function deriv_obj is used. In a first step, the expression of all first and second derivatives of the parameters is computed using the expressions of logL1 and logL2 from the est_funct_expr as input. Then, the numerical values of all first and second derivatives are obtained for the observed data Y, X, K, L (and C under the AFT setting) and point estimates (estimates) of the parameters, for all observed individuals.

Second, the functions scores and hessian are used to extract the relevant score and hessian matrices with respect to logL1 and logL2 from the output of deriv_obj and piece them together. For further details, see the vignette.

Value

The deriv_obj function returns a list with objects logL1_deriv, logL2_deriv which contain the score and hessian matrices based on logL1, logL2, respectively.

The scores function returns the (n \times 8) score matrix.

The hessian function returns the (n \times 8 \times 8) hessian matrix.

Examples


# Generate data including Y, K, L, X under the GLM setting
dat <- generate_data(setting = "GLM")

# Obtain estimating functions' expressions
estfunct <- est_funct_expr(setting = "GLM")

# Obtain point estimates of the parameters
estimates <- get_estimates(setting = "GLM", Y = dat$Y, X = dat$X,
                           K = dat$K, L = dat$L)

# Obtain matrices with all first and second derivatives
derivobj <- deriv_obj(setting = "GLM", logL1 = estfunct$logL1,
                      logL2 = estfunct$logL2, Y = dat$Y, X = dat$X,
                      K = dat$K, L = dat$L, estimates = estimates)
names(derivobj)
head(derivobj$logL1_deriv$gradient)

# Obtain score and hessian matrices
scores(derivobj)
hessian(derivobj)


[Package CIEE version 0.1.1 Index]