Score and hessian matrix based on the estimating functions.
Score and hessian matrix based on the estimating functions.
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,σ12,α4,\alphaXY,σ22
under the GLM setting and α0,α1,α2,α3,σ1,α4,\alphaXY,σ22
under the AFT setting.
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,σ12,
α4,\alphaXY,σ22
under the GLM setting and of α0,α1,α2,α3,σ1,α4,\alphaXY,σ22
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.
Returns
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 (nx8)
score matrix.
The hessian function returns the (nx8x8)
hessian matrix.
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.
Examples
# Generate data including Y, K, L, X under the GLM settingdat <- generate_data(setting ="GLM")# Obtain estimating functions' expressionsestfunct <- est_funct_expr(setting ="GLM")# Obtain point estimates of the parametersestimates <- get_estimates(setting ="GLM", Y = dat$Y, X = dat$X, K = dat$K, L = dat$L)# Obtain matrices with all first and second derivativesderivobj <- 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 matricesscores(derivobj)hessian(derivobj)