Introduction to user interface functions

Kazuki Yoshida

2020-11-16

Data preparation

The package require all variables to be numerical. So a multi-category factor needs to be converted to multiple dichotomous indicators. For survival outcome models, the indicator variable is for event (1 = event, 0 = censored).

library(regmedint)
library(tidyverse)
## Prepare dataset
data(vv2015)

regmedint object

Following typical modeling workflow in R (e.g., lm and glm), a constructor function is used to create a model fit object. The summary method is the main user function for examining the results in the object. Lower-level methods such as coef, vcov, and confint are also provided for flexibility. The print method is mainly for meaningful implicit printing when only the object name is evaluated. All methods for the regmedint object has arguments a0, a1, m_cde, and c_cond. These are used to re-evaluate the results without re-fitting the underlying models.

regemedint() object constructor

regmedint_obj <- regmedint(data = vv2015,
                           ## Variables
                           yvar = "y",
                           avar = "x",
                           mvar = "m",
                           cvar = c("c"),
                           eventvar = "event",
                           ## Values at which effects are evaluated
                           a0 = 0,
                           a1 = 1,
                           m_cde = 1,
                           c_cond = 0.5,
                           ## Model types
                           mreg = "logistic",
                           yreg = "survAFT_weibull",
                           ## Additional specification
                           interaction = TRUE,
                           casecontrol = FALSE)

summary() for regmedint

summary(regmedint_obj)
## ### Mediator model
## 
## Call:
## glm(formula = m ~ x + c, family = binomial(link = "logit"), data = data)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.5143  -1.1765   0.9177   1.1133   1.4602  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)
## (Intercept)  -0.3545     0.3252  -1.090    0.276
## x             0.3842     0.4165   0.922    0.356
## c             0.2694     0.2058   1.309    0.191
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 138.59  on 99  degrees of freedom
## Residual deviance: 136.08  on 97  degrees of freedom
## AIC: 142.08
## 
## Number of Fisher Scoring iterations: 4
## 
## ### Outcome model
## 
## Call:
## survival::survreg(formula = Surv(y, event) ~ x * m + c, data = data, 
##     dist = "weibull")
##               Value Std. Error     z       p
## (Intercept) -1.0424     0.1903 -5.48 4.3e-08
## x            0.4408     0.3008  1.47    0.14
## m            0.0905     0.2683  0.34    0.74
## c           -0.0669     0.0915 -0.73    0.46
## x:m          0.1003     0.4207  0.24    0.81
## Log(scale)  -0.0347     0.0810 -0.43    0.67
## 
## Scale= 0.966 
## 
## Weibull distribution
## Loglik(model)= -11.4   Loglik(intercept only)= -14.5
##  Chisq= 6.31 on 4 degrees of freedom, p= 0.18 
## Number of Newton-Raphson Iterations: 5 
## n= 100 
## 
## ### Mediation analysis 
##              est         se         Z           p       lower      upper
## cde  0.541070807 0.29422958 1.8389409 0.065923882 -0.03560858 1.11775019
## pnde 0.488930417 0.21049248 2.3227928 0.020190284  0.07637274 0.90148809
## tnie 0.018240025 0.03706111 0.4921608 0.622605663 -0.05439841 0.09087846
## tnde 0.498503455 0.21209540 2.3503737 0.018754573  0.08280410 0.91420281
## pnie 0.008666987 0.02730994 0.3173565 0.750973092 -0.04485951 0.06219348
## te   0.507170442 0.21090051 2.4047853 0.016181972  0.09381303 0.92052785
## pm   0.045436278 0.01725694 2.6329276 0.008465238  0.01161329 0.07925926
## 
## Evaluated at:
## avar: x
##  a1 (intervened value of avar) = 1
##  a0 (reference value of avar)  = 0
## mvar: m
##  m_cde (intervend value of mvar for cde) = 1
## cvar: c
##  c_cond (covariate vector value) = 0.5
## 
## Note that effect estimates can vary over m_cde and c_cond values when interaction = TRUE.
summary(regmedint_obj, exponentiate = TRUE)
## ### Mediator model
## 
## Call:
## glm(formula = m ~ x + c, family = binomial(link = "logit"), data = data)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.5143  -1.1765   0.9177   1.1133   1.4602  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)
## (Intercept)  -0.3545     0.3252  -1.090    0.276
## x             0.3842     0.4165   0.922    0.356
## c             0.2694     0.2058   1.309    0.191
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 138.59  on 99  degrees of freedom
## Residual deviance: 136.08  on 97  degrees of freedom
## AIC: 142.08
## 
## Number of Fisher Scoring iterations: 4
## 
## ### Outcome model
## 
## Call:
## survival::survreg(formula = Surv(y, event) ~ x * m + c, data = data, 
##     dist = "weibull")
##               Value Std. Error     z       p
## (Intercept) -1.0424     0.1903 -5.48 4.3e-08
## x            0.4408     0.3008  1.47    0.14
## m            0.0905     0.2683  0.34    0.74
## c           -0.0669     0.0915 -0.73    0.46
## x:m          0.1003     0.4207  0.24    0.81
## Log(scale)  -0.0347     0.0810 -0.43    0.67
## 
## Scale= 0.966 
## 
## Weibull distribution
## Loglik(model)= -11.4   Loglik(intercept only)= -14.5
##  Chisq= 6.31 on 4 degrees of freedom, p= 0.18 
## Number of Newton-Raphson Iterations: 5 
## n= 100 
## 
## ### Mediation analysis 
##              est         se         Z           p       lower      upper
## cde  0.541070807 0.29422958 1.8389409 0.065923882 -0.03560858 1.11775019
## pnde 0.488930417 0.21049248 2.3227928 0.020190284  0.07637274 0.90148809
## tnie 0.018240025 0.03706111 0.4921608 0.622605663 -0.05439841 0.09087846
## tnde 0.498503455 0.21209540 2.3503737 0.018754573  0.08280410 0.91420281
## pnie 0.008666987 0.02730994 0.3173565 0.750973092 -0.04485951 0.06219348
## te   0.507170442 0.21090051 2.4047853 0.016181972  0.09381303 0.92052785
## pm   0.045436278 0.01725694 2.6329276 0.008465238  0.01161329 0.07925926
##      exp(est) exp(lower) exp(upper)
## cde  1.717845  0.9650179   3.057967
## pnde 1.630571  1.0793648   2.463266
## tnie 1.018407  0.9470547   1.095136
## tnde 1.646256  1.0863290   2.494786
## pnie 1.008705  0.9561318   1.064168
## te   1.660586  1.0983544   2.510615
## pm         NA         NA         NA
## 
## Evaluated at:
## avar: x
##  a1 (intervened value of avar) = 1
##  a0 (reference value of avar)  = 0
## mvar: m
##  m_cde (intervend value of mvar for cde) = 1
## cvar: c
##  c_cond (covariate vector value) = 0.5
## 
## Note that effect estimates can vary over m_cde and c_cond values when interaction = TRUE.
summary(regmedint_obj, m_cde = 0, c_cond = 1)
## ### Mediator model
## 
## Call:
## glm(formula = m ~ x + c, family = binomial(link = "logit"), data = data)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.5143  -1.1765   0.9177   1.1133   1.4602  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)
## (Intercept)  -0.3545     0.3252  -1.090    0.276
## x             0.3842     0.4165   0.922    0.356
## c             0.2694     0.2058   1.309    0.191
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 138.59  on 99  degrees of freedom
## Residual deviance: 136.08  on 97  degrees of freedom
## AIC: 142.08
## 
## Number of Fisher Scoring iterations: 4
## 
## ### Outcome model
## 
## Call:
## survival::survreg(formula = Surv(y, event) ~ x * m + c, data = data, 
##     dist = "weibull")
##               Value Std. Error     z       p
## (Intercept) -1.0424     0.1903 -5.48 4.3e-08
## x            0.4408     0.3008  1.47    0.14
## m            0.0905     0.2683  0.34    0.74
## c           -0.0669     0.0915 -0.73    0.46
## x:m          0.1003     0.4207  0.24    0.81
## Log(scale)  -0.0347     0.0810 -0.43    0.67
## 
## Scale= 0.966 
## 
## Weibull distribution
## Loglik(model)= -11.4   Loglik(intercept only)= -14.5
##  Chisq= 6.31 on 4 degrees of freedom, p= 0.18 
## Number of Newton-Raphson Iterations: 5 
## n= 100 
## 
## ### Mediation analysis 
##              est         se         Z          p       lower      upper
## cde  0.440756562 0.30083077 1.4651313 0.14288511 -0.14886090 1.03037403
## pnde 0.492306223 0.21015655 2.3425690 0.01915149  0.08040695 0.90420550
## tnie 0.018077074 0.03653416 0.4947991 0.62074191 -0.05352857 0.08968272
## tnde 0.501765186 0.21433402 2.3410432 0.01922994  0.08167823 0.92185214
## pnie 0.008618111 0.02707487 0.3183067 0.75025232 -0.04444765 0.06168388
## te   0.510383297 0.21212172 2.4060870 0.01612443  0.09463237 0.92613422
## pm   0.044816400 0.01671605 2.6810406 0.00733936  0.01205355 0.07757925
## 
## Evaluated at:
## avar: x
##  a1 (intervened value of avar) = 1
##  a0 (reference value of avar)  = 0
## mvar: m
##  m_cde (intervend value of mvar for cde) = 0
## cvar: c
##  c_cond (covariate vector value) = 1
## 
## Note that effect estimates can vary over m_cde and c_cond values when interaction = TRUE.
summary(regmedint_obj, m_cde = 0, c_cond = 1, level = 0.99)
## ### Mediator model
## 
## Call:
## glm(formula = m ~ x + c, family = binomial(link = "logit"), data = data)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -1.5143  -1.1765   0.9177   1.1133   1.4602  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)
## (Intercept)  -0.3545     0.3252  -1.090    0.276
## x             0.3842     0.4165   0.922    0.356
## c             0.2694     0.2058   1.309    0.191
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 138.59  on 99  degrees of freedom
## Residual deviance: 136.08  on 97  degrees of freedom
## AIC: 142.08
## 
## Number of Fisher Scoring iterations: 4
## 
## ### Outcome model
## 
## Call:
## survival::survreg(formula = Surv(y, event) ~ x * m + c, data = data, 
##     dist = "weibull")
##               Value Std. Error     z       p
## (Intercept) -1.0424     0.1903 -5.48 4.3e-08
## x            0.4408     0.3008  1.47    0.14
## m            0.0905     0.2683  0.34    0.74
## c           -0.0669     0.0915 -0.73    0.46
## x:m          0.1003     0.4207  0.24    0.81
## Log(scale)  -0.0347     0.0810 -0.43    0.67
## 
## Scale= 0.966 
## 
## Weibull distribution
## Loglik(model)= -11.4   Loglik(intercept only)= -14.5
##  Chisq= 6.31 on 4 degrees of freedom, p= 0.18 
## Number of Newton-Raphson Iterations: 5 
## n= 100 
## 
## ### Mediation analysis 
##              est         se         Z          p        lower      upper
## cde  0.440756562 0.30083077 1.4651313 0.14288511 -0.334132138 1.21564526
## pnde 0.492306223 0.21015655 2.3425690 0.01915149 -0.049021181 1.03363363
## tnie 0.018077074 0.03653416 0.4947991 0.62074191 -0.076028699 0.11218285
## tnde 0.501765186 0.21433402 2.3410432 0.01922994 -0.050322656 1.05385303
## pnie 0.008618111 0.02707487 0.3183067 0.75025232 -0.061122126 0.07835835
## te   0.510383297 0.21212172 2.4060870 0.01612443 -0.036006037 1.05677263
## pm   0.044816400 0.01671605 2.6810406 0.00733936  0.001758718 0.08787408
## 
## Evaluated at:
## avar: x
##  a1 (intervened value of avar) = 1
##  a0 (reference value of avar)  = 0
## mvar: m
##  m_cde (intervend value of mvar for cde) = 0
## cvar: c
##  c_cond (covariate vector value) = 1
## 
## Note that effect estimates can vary over m_cde and c_cond values when interaction = TRUE.

coef() for regmedint

coef(regmedint_obj)
##         cde        pnde        tnie        tnde        pnie          te 
## 0.541070807 0.488930417 0.018240025 0.498503455 0.008666987 0.507170442 
##          pm 
## 0.045436278 
## attr(,"args")
## attr(,"args")$a0
## [1] 0
## 
## attr(,"args")$a1
## [1] 1
## 
## attr(,"args")$m_cde
## [1] 1
## 
## attr(,"args")$c_cond
## [1] 0.5
coef(regmedint_obj, m_cde = 0, c_cond = 1)
##         cde        pnde        tnie        tnde        pnie          te 
## 0.440756562 0.492306223 0.018077074 0.501765186 0.008618111 0.510383297 
##          pm 
## 0.044816400 
## attr(,"args")
## attr(,"args")$a0
## [1] 0
## 
## attr(,"args")$a1
## [1] 1
## 
## attr(,"args")$m_cde
## [1] 0
## 
## attr(,"args")$c_cond
## [1] 1

vcov() for regmedint

vcov(regmedint_obj)
##             cde       pnde        tnie       tnde         pnie         te
## cde  0.08657105         NA          NA         NA           NA         NA
## pnde         NA 0.04430708          NA         NA           NA         NA
## tnie         NA         NA 0.001373526         NA           NA         NA
## tnde         NA         NA          NA 0.04498446           NA         NA
## pnie         NA         NA          NA         NA 0.0007458327         NA
## te           NA         NA          NA         NA           NA 0.04447903
## pm           NA         NA          NA         NA           NA         NA
##               pm
## cde           NA
## pnde          NA
## tnie          NA
## tnde          NA
## pnie          NA
## te            NA
## pm   0.000297802
## attr(,"args")
## attr(,"args")$a0
## [1] 0
## 
## attr(,"args")$a1
## [1] 1
## 
## attr(,"args")$m_cde
## [1] 1
## 
## attr(,"args")$c_cond
## [1] 0.5
vcov(regmedint_obj, m_cde = 0, c_cond = 1)
##             cde       pnde        tnie       tnde         pnie         te
## cde  0.09049915         NA          NA         NA           NA         NA
## pnde         NA 0.04416578          NA         NA           NA         NA
## tnie         NA         NA 0.001334745         NA           NA         NA
## tnde         NA         NA          NA 0.04593907           NA         NA
## pnie         NA         NA          NA         NA 0.0007330485         NA
## te           NA         NA          NA         NA           NA 0.04499562
## pm           NA         NA          NA         NA           NA         NA
##                pm
## cde            NA
## pnde           NA
## tnie           NA
## tnde           NA
## pnie           NA
## te             NA
## pm   0.0002794262
## attr(,"args")
## attr(,"args")$a0
## [1] 0
## 
## attr(,"args")$a1
## [1] 1
## 
## attr(,"args")$m_cde
## [1] 0
## 
## attr(,"args")$c_cond
## [1] 1

confint() for regmedint

confint(regmedint_obj)
##            lower      upper
## cde  -0.03560858 1.11775019
## pnde  0.07637274 0.90148809
## tnie -0.05439841 0.09087846
## tnde  0.08280410 0.91420281
## pnie -0.04485951 0.06219348
## te    0.09381303 0.92052785
## pm    0.01161329 0.07925926
## attr(,"args")
## attr(,"args")$a0
## [1] 0
## 
## attr(,"args")$a1
## [1] 1
## 
## attr(,"args")$m_cde
## [1] 1
## 
## attr(,"args")$c_cond
## [1] 0.5
confint(regmedint_obj, m_cde = 0, c_cond = 1)
##            lower      upper
## cde  -0.14886090 1.03037403
## pnde  0.08040695 0.90420550
## tnie -0.05352857 0.08968272
## tnde  0.08167823 0.92185214
## pnie -0.04444765 0.06168388
## te    0.09463237 0.92613422
## pm    0.01205355 0.07757925
## attr(,"args")
## attr(,"args")$a0
## [1] 0
## 
## attr(,"args")$a1
## [1] 1
## 
## attr(,"args")$m_cde
## [1] 0
## 
## attr(,"args")$c_cond
## [1] 1
confint(regmedint_obj, m_cde = 0, c_cond = 1, level = 0.99)
##             lower      upper
## cde  -0.334132138 1.21564526
## pnde -0.049021181 1.03363363
## tnie -0.076028699 0.11218285
## tnde -0.050322656 1.05385303
## pnie -0.061122126 0.07835835
## te   -0.036006037 1.05677263
## pm    0.001758718 0.08787408
## attr(,"args")
## attr(,"args")$a0
## [1] 0
## 
## attr(,"args")$a1
## [1] 1
## 
## attr(,"args")$m_cde
## [1] 0
## 
## attr(,"args")$c_cond
## [1] 1

Methods for summary_regmedint

The summary method for the regmedint object returns an object of class summary_regmedint. To extract the mediation analysis result table as a matrix, use the coef method.

coef() for summary_regmedint

coef(summary(regmedint_obj))
##              est         se         Z           p       lower      upper
## cde  0.541070807 0.29422958 1.8389409 0.065923882 -0.03560858 1.11775019
## pnde 0.488930417 0.21049248 2.3227928 0.020190284  0.07637274 0.90148809
## tnie 0.018240025 0.03706111 0.4921608 0.622605663 -0.05439841 0.09087846
## tnde 0.498503455 0.21209540 2.3503737 0.018754573  0.08280410 0.91420281
## pnie 0.008666987 0.02730994 0.3173565 0.750973092 -0.04485951 0.06219348
## te   0.507170442 0.21090051 2.4047853 0.016181972  0.09381303 0.92052785
## pm   0.045436278 0.01725694 2.6329276 0.008465238  0.01161329 0.07925926