Movatterモバイル変換


[0]ホーム

URL:


wsMed

ThewsMed function is designed for two conditionwithin-subject mediation analysis, incorporating SEM models through thelavaan package and Monte Carlo simulation methods. Thisdocument provides a detailed description of the function’s parameters,workflow, and usage, along with an example demonstration.

Installation

You can install the development version of wsMed fromGitHub with:

# install.packages("pak")pak::pak("Yangzhen1999/wsMed")

Alternatively, if you prefer using devtools, you can install wsMed asfollows:

# install.packages("devtools")devtools::install_github("Yangzhen1999/wsMed")

Example

This is a basic example which shows you how to solve a commonproblem:

library(wsMed)# Load example datadata(example_data)set.seed(123)example_dataN<- mice::ampute(data = example_data,prop =0.1,)$amp# Perform within-subject mediation analysis (Parallel mediation model)result<-wsMed(data = example_dataN,#datasetM_C1 =c("A1","B1"),# A1/B1 is A/B mediator variable in condition 1M_C2 =c("A2","B2"),# A2/B2 is A/B mediator variable in condition 2Y_C1 ="C1",# C1 is outcome variable in condition 1Y_C2 ="C2",# C2 is outcome variable in condition 2form ="P",# Parallel mediationC_C1 ="D1",# within-subject covariate (e.g., measured under D1)C_C2 ="D2",# within-subject covariate (e.g., measured under C2)C ="D3",# between-subject covariatesNa ="MI",# Use multiple imputation for missing datastandardized =TRUE,# Request standardized path coefficients and effects)# Print summary resultsprint(result)

Main Function Overview

ThewsMed() function automates the full workflow fortwo-condition within-subject mediation analysis. Its main steps are:

  1. Validate inputs – check dataset structure,mediation model type (form), and missing-datasettings.

  2. Prepare data – compute difference scores(Mdiff,Ydiff) and centered averages(Mavg) from the two-condition variables.

  3. Build the model – generate SEM syntax accordingto the chosen structure:

  4. Fit the model – estimate parameters whilehandling missing data:

  5. Compute inference – provide confidence intervalsusing:

  6. Optional: Standardization – ifstandardized = TRUE, return standardized effects withCIs.

  7. Optional: Covariates – automatically center andinclude:


[8]ページ先頭

©2009-2025 Movatter.jp