Introduction to user interface functions

Kazuki Yoshida, Yi Li

2024-01-06

Data preparation

The package require all variables to be numerical. So a multi-categorical factor needs to be converted to dummy variables or multiple dichotomous indicators. For survival outcome models, the indicator variable is for the 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)
## 
## 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 + 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.06592388 -0.03560858 1.11775019
## pnde 0.488930417 0.21049248 2.3227928 0.02019028  0.07637274 0.90148809
## tnie 0.018240025 0.03706111 0.4921608 0.62260566 -0.05439841 0.09087846
## tnde 0.498503455 0.21209540 2.3503737 0.01875457  0.08280410 0.91420281
## pnie 0.008666987 0.02730994 0.3173565 0.75097309 -0.04485951 0.06219348
## te   0.507170442 0.21090051 2.4047853 0.01618197  0.09381303 0.92052785
## pm   0.045436278 0.09119614 0.4982259 0.61832484 -0.13330488 0.22417743
## 
## 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)
## 
## 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 + 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.06592388 -0.03560858 1.11775019
## pnde 0.488930417 0.21049248 2.3227928 0.02019028  0.07637274 0.90148809
## tnie 0.018240025 0.03706111 0.4921608 0.62260566 -0.05439841 0.09087846
## tnde 0.498503455 0.21209540 2.3503737 0.01875457  0.08280410 0.91420281
## pnie 0.008666987 0.02730994 0.3173565 0.75097309 -0.04485951 0.06219348
## te   0.507170442 0.21090051 2.4047853 0.01618197  0.09381303 0.92052785
## pm   0.045436278 0.09119614 0.4982259 0.61832484 -0.13330488 0.22417743
##      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)
## 
## 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 + 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.08889613 0.5041434 0.61416060 -0.12941682 0.21904962
## 
## 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)
## 
## 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 + 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.33413214 1.21564526
## pnde 0.492306223 0.21015655 2.3425690 0.01915149 -0.04902118 1.03363363
## tnie 0.018077074 0.03653416 0.4947991 0.62074191 -0.07602870 0.11218285
## tnde 0.501765186 0.21433402 2.3410432 0.01922994 -0.05032266 1.05385303
## pnie 0.008618111 0.02707487 0.3183067 0.75025232 -0.06112213 0.07835835
## te   0.510383297 0.21212172 2.4060870 0.01612443 -0.03600604 1.05677263
## pm   0.044816400 0.08889613 0.5041434 0.61416060 -0.18416486 0.27379767
## 
## 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.008316736
## 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.007902522
## 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.13330488 0.22417743
## 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.12941682 0.21904962
## 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.33413214 1.21564526
## pnde -0.04902118 1.03363363
## tnie -0.07602870 0.11218285
## tnde -0.05032266 1.05385303
## pnie -0.06112213 0.07835835
## te   -0.03600604 1.05677263
## pm   -0.18416486 0.27379767
## 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.06592388 -0.03560858 1.11775019
## pnde 0.488930417 0.21049248 2.3227928 0.02019028  0.07637274 0.90148809
## tnie 0.018240025 0.03706111 0.4921608 0.62260566 -0.05439841 0.09087846
## tnde 0.498503455 0.21209540 2.3503737 0.01875457  0.08280410 0.91420281
## pnie 0.008666987 0.02730994 0.3173565 0.75097309 -0.04485951 0.06219348
## te   0.507170442 0.21090051 2.4047853 0.01618197  0.09381303 0.92052785
## pm   0.045436278 0.09119614 0.4982259 0.61832484 -0.13330488 0.22417743