Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

score_and_hessian_matrix_functions

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 α0, α1, α2, α3, σ1^2, α4, αXY, σ2^2 under the GLM setting and α0, α1, α2, α3, σ1, α4, αXY, σ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 α0, α1, α2, α3, σ1^2, α4, αXY, σ2^2 under the GLM setting and of α0, α1, α2, α3, σ1, α4, αXY, σ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 x 8) score matrix.

The hessian function returns the (n x 8 x 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)

CIEE

Estimating and Testing Direct Effects in Directed Acyclic Graphs using Estimating Equations

v0.1.1
GPL-2
Authors
Stefan Konigorski [aut, cre], Yildiz E. Yilmaz [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.