score_and_hessian_matrix_functions {CIEE}  R Documentation 
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 normallydistributed or censored timetoevent
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.
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)
setting 
String with value 
logL1 
Expression of the function 
logL2 
Expression of the 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,

derivobj 
Output of the 
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.
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.
# 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)