Learn R Programming

Package "unvs.med"

Version: 1.0.0

Authorship

Copyrights reserved by:

First author (creator): Zhou Tianbao (Michael Zhou) michaelzhou@buaa.edu.cn{.email}, <ORCID: 0000-0001-6782-626X>;

Second author (advisor): Li Xinghao lixinghao@bjfu.edu.cn{.email};

Corresponding author (supervisor): Liu Lin*, liulin@pku.edu.cn{.email}

Institution: School of Government, Peking University, Beijing, China.

Introduction

This package realizes a universal estimation approach that accommodates multi-category variables and effect scales, making up for the deficiencies of the existing approaches when dealing with non-binary exposures and complex models. The estimation via bootstrapping can simultaneously provide results of causal mediation on RD, OR and RR scales with tests of the effects' difference. The estimation is also applicable to many other settings, e.g., moderated mediation, inconsistent covariates, panel data, etc. The high flexibility and compatibility make it possible to apply for any type of model, greatly meeting the needs of current empirical researches.

Installation

Users can install the development version of package "unvs.med" through R code:

install.packages("unvs.med")

Example

This is an example based on the test data which shows you how to estimate causal mediation effects through this package:

library(unvs.med)
data(testdata)
# Fitting mediator's model
med_model=glm(med~exp+C1+C2+C3, data=testdata, family=binomial)

# Fitting outcome's model
out_model=lm(out~med*exp+C1+C2+C3, data=testdata) 

# Running formal estimation via bootstrapping
r11 = FormalEstmed (med_model=med_model, out_model=out_model,
data=testdata, exposure = "exp") 

# Viewing results in short form and on RD scales
summary(r11) 

## Plot of PNED and TNDE on RD scales
plot(r11)

Copy Link

Version

Install

install.packages('unvs.med')

Monthly Downloads

575

Version

1.1.0

License

GPL-3

Maintainer

Tianbao Zhou

Last Published

January 27th, 2026

Functions in unvs.med (1.1.0)

cond_cov

Modifications of Data and Models for Moderated Mediation
ident_Y_type

Identification of Outcome's type
Statistics

Statistics of Estimated Value of Causal Mediation Effects
FormalEstmed

Formal Estimation for Causal Mediation Effects (The Main Function)
BootEstimation_MT

Bootstrapping Estimation for Causal Mediation Effects via Multi-threading Process
SingleEstimation

Single-time Estimation for Causal Mediation Effects
plot.unvs.med

Visualization of Mediation Effects
confirmingX

Confirmation of the Exposure
ident_M_type

Identification of Mediator's type
BootEstimation_for

Bootstrapping Estimation for Causal Mediation Effects via Ordinary "for" Loop
testdata

Test Dataset for Causal Mediation Analysis
summary.unvs.med

Summary of Formal Estimation for Causal Mediation Effects
um.test1

Test of Mediation Effects Within One Single Object
potentialoutcome_numX

Estimation of Potential Outcomes Based on the Universal Approach (for Numeric Exposure)
um.test2

Test of Mediation Effects Between Two Objects
potentialoutcome_facX

Estimation of Potential Outcomes Based on the Universal Approach (for factor Exposure)