install.packages("gitcreds")
gitcreds::gitcreds_delete() # clears a bad cached token
remotes::install_github("khnhan/spyce")
This package analyzes right-censored covariate under outcome-dependent censoring.
The semiparametric estimator SPYCE is implemented via get_SPYCE_... functions. This package provides other estimators for analyzing the same data: complete case estimator (CC), imputation estimator, inverse probability weighting estimator (IPW), and the maximum likelihood estimator (MLE). The estimated asymptotic variance for the estimators can be computed with corresponding variance_... functions. Conditional Kaplan-Meier estimator as an auxiliary tool for nonparametric estimators can also be implemented with this package.
The full data is
-
$Y$ : outcome -
$X$ : time-to-event covariate -
$C$ : censoring time -
$Z$ : baseline covariates
Due to right-censoring, the observed data is
The functions get_... find an estimator of variance_... compute the estimated asymptotic variance of the estimators.
- With
z_datapresent, then$Y\mid X,Z \sim N\big(\beta_0+\beta_1 X+\beta_2 Z+\beta_3 ZX,\ \sigma^2\big)$ . - Without
z_data, then$Y\mid X \sim N\big(\beta_0+\beta_1 X,\ \sigma^2\big)$ .
Possible choices of estimators are
-
...SPYCE_param12: SPYCE with parametrically estimated$\eta_1$ and$\eta_2$ -
...SPYCE_nonparam12: SPYCE with nonparametrically estimated$\eta_1$ and$\eta_2$ -
...CC: complete case (CC) estimator -
...imputation_param1: imputation estimator with parametrically estimated$\eta_1$ -
...imputation_nonparam1: imputation estimator with nonparametrically estimated$\eta_1$ -
...IPW_param2: inverse probability weighting (IPW) estimator with parametrically estimated$\eta_2$ -
...IPW_nonparam2: inverse probability weighting (IPW) estimator with nonparametrically estimated$\eta_2$ -
...MLE_param1: maximum likelihood estimator (MLE) with parametrically estimated$\eta_1$ -
...MLE_nonparam1: maximum likelihood estimator (MLE) with nonparametrically estimated$\eta_1$
Each of the estimators supports four modes:
-
CASE A: estimate
$(\beta,\sigma)$ withz_data -
CASE B: estimate
$(\beta,\sigma)$ withoutz_data -
CASE C: estimate
$\beta$ withz_dataand fixed$\sigma$ -
CASE D: estimate
$\beta$ withoutz_dataand fixed$\sigma$
For SPYCE, imputation, IPW, and MLE, there are two choices for nuisance model estimation: parametric estimation and nonparametric estimation. Each estimation method provides a different workflow.
The parametric estimation of nuisance models uses maximum likelihood estimation with truncated normal distribution. The workflow is:
- Make
y_data,w_data,delta_dataas the same-length vectors. For CASE A and CASE C, makez_dataas the same-length binary vector. - Assign
sigma_fixedfor CASE C and CASE D. - Supply proper initial values
initfor optimization. If undetermined, use linear regression estimators with complete case data usinglm(y_data[delta_data == 1] ~ w_data[delta_data == 1])(CASE B and CASE D) orlm(y_data[delta_data == 1] ~ w_data[delta_data == 1] + z_data[delta_data == 1])(CASE A and CASE C). - Provide proper
w_minandw_max, the range for$X$ and$C$ . This will be used in a truncated normal distribution for maximum likelihood estimation. - If needed, put extra options
nleqslv_argsthat will be used in optimizernleqslv::nleqslvfunction. - Compute the estimator using
get_...function. Save the final estimates. - To find asymptotic variance of the estimator, use
variance_...function with the saved final estimates.
The nonparametric estimation of nuisance models uses inverse probability weighting with kernel estimation, where conditional survival function values are used for inverse probability weighting. Conditional survival function values can be computed using conditional_Kaplan_Meier function.
The workflow is:
- Make
y_data,w_data,delta_dataas the same-length vectors. For CASE A and CASE C, makez_dataas the same-length binary vector. - Assign
sigma_fixedfor CASE C and CASE D. - Supply proper initial values
initfor optimization. If undetermined, use linear regression estimators with complete case data usinglm(y_data[delta_data == 1] ~ w_data[delta_data == 1](CASE B and CASE D) orlm(y_data[delta_data == 1] ~ w_data[delta_data == 1] + z_data[delta_data == 1](CASE A and CASE C). - Supply conditional survival function values in
surv_c_valsand/orsurv_x_valsfor each observation$(W_i,Y_i,Z_i)$ . You may useconditional_Kaplan_Meierfunction. - If needed, put extra options
nleqslv_argsthat will be used in optimizernleqslv::nleqslvfunction. - Compute the estimator using
get_...function. Save the final estimates. - To find asymptotic variance of the estimator, use
variance_...function with the saved final estimates.
More detailed examples are provided in help() document of each function.