Learn R Programming

R package processR

The processR package aims to be a user-friendly way to perform moderation, mediation, moderated mediation and moderated moderation in R. This package is inspired from famous PROCESS macro for SPSS and SAS created by Andrew Hayes.

processR is under the GPL-3 license. For a commercial license, please [contact me](mailto: cardiomoon@gmail.com).

PROCESS macro and R package processR

Andrew F. Hayes was not involved in the development of this R package or application and cannot attest to the quality of the computations implemented in the code you are using. Use at your own risk.

Installation

You can install the processR package from github.

if(!require(devtools)) install.packages("devtools")
devtools::install_github("cardiomoon/processR")

What does this package cover ?

The processR package covers moderation, mediation, moderated mediation and moderated moderation with R. Supporting models are as follows.

library(processR)
sort(pmacro$no)
 [1]  0.0  1.0  2.0  3.0  4.0  4.2  5.0  6.0  6.3  6.4  7.0  8.0  9.0 10.0
[15] 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0 21.0 22.0 23.0 24.0
[29] 28.0 29.0 30.0 31.0 35.0 36.0 40.0 41.0 45.0 49.0 50.0 58.0 59.0 60.0
[43] 61.0 62.0 63.0 64.0 65.0 66.0 67.0 74.0 75.0 76.0

Currently, 52 models are supported.

Example: Moderated Mediation (PROCESS macro model 8)

I will explain functions of processR package by a example.

Concept Diagram and Statistical Diagram

You can draw concept diagram and statistical diagram easily. For example, you can draw the concept diagram for PROCESS macro model 8.

pmacroModel(8)

You can draw statistical diagram of this model.

statisticalDiagram(8)

Full vignette

You can see full vignette for model 8 at http://rpubs.com/cardiomoon/468602

Shiny App

I have developed a shiny app. You can test the app at https://cardiomoon.shinyapps.io/processR. I will appreciate any comment.

How to perform this analysis with shiny app

You can see how to perform this analysis at http://rpubs.com/cardiomoon/468600

Sample powerpoint file

In the shiny app, you can download the analysis results as a powerpoint file. You can download the sample file model8.pptx - view with office web viewer.

Copy Link

Version

Install

install.packages('processR')

Monthly Downloads

56

Version

0.2.7

License

GPL-2

Issues

Pull Requests

Stars

Forks

Maintainer

KeonWoong Moon

Last Published

January 23rd, 2023

Functions in processR (0.2.7)

addLine

Add line feed to string
addArrows

Add covariates to arrows
addLabels

add name to labels
addCatVars

Add dummy vars to data.frame
adjustxpos

Adjust x position
caskets

CASKETS dataset
changeLabelName

Change Label Names
checkEqVars

Check dependent variables in a equation
bda.mediation.test

The Sobel mediation test
centerPrint

Print a string in center
adjustypos

Adjust y position
appendLabels

Append labels from vars, moderator and covar
conceptDiagram

Make conceptDiagram
compareVIFTable

Make table comparing correlation, tolerance, vif of mean-centered and standardized models
conceptDiagram2

Make concept Diagram
condPlotCat

Make conditional effect plot with data including a categorical variable
corTable

Make a table with correlation
corTable2

Make a table with correlation
corPlot

Draw correlation plot
convertPvalue

convert vector of p values to string
condPlot

Draw conditional effect plot
catMediation

Make Mediation Equation with one categorical variable
compareMCTable

Make table comparing effects of mean-centering and standardization of model
condPlot2

Draw conditional plot for moderated moderation
drawArrows

Draw arrows
conditionalEffectPlot

Make conditional effect plot
divideEquation

divide equation
compareVIF

Compare correlation, tolerance, vif of mean-centered and standardized models
adjustPosNodes

Adjust position of nodes
discriminantValidityTable2

make discriminant Validity Table in flextable format
condPlotCat2

Draw direct and indirect effect plot
disaster

Disaster dataset
drawtext

Draw node
drawCatModel

Draw statistical diagram including categorical X
estimatesTable

convert parameterEstimates to data.frame
education

Data Set for education and income
eq2df

Convert equation to data.frame
eq2fit

Make a list of objects of class lm
estimatesTable2

convert parameterEstimates to flextable
fit2table

Make estimatesTable with a list of lm object
extractRange

Extract range from a data.frame
extractX

Extract group by string
fit2vif

Summarizing correlation, tolerance and variance inflation factors of a model
findName

convert name with list
densityPlot

Draw Smoothed Kernel density plot
deleteSingleNumber

remove coefficient number of equation
getArrows

Get arrows data with no
drawModel

Draw statistical diagram with an object of class lavaan or a list of class lm
eq2var

make data.frame with equation
extractModerator

Extract name of moderator from string
getNodes

Get nodes data with model no
getRatioTable

Get coding table for dummy variables
equations2var

make data.frame with equation
getAspectRatio

Get aspect information of a ggplot
drawStatDiagram

draw StatDiagram
getMeanSd

get mean and sd
extractNumber

extract number from string
checkEquationVars

Check dependent variables in equations
countM

Count the group names start with "M"
covar2df

Make data.frame with covariates
compareMC

Compare effects of mean-centering and standardization of model
drawConcept

Draw Concept Diagram
findNames

convert a vector of names with list
getRepValues

Get representative values
drawCovar

Draw covariate
extractLatentVar

Extract Latent Variables Data
extractLatentVarName

Extract Latent Variables Names
getBootData

Get bootstrapped values
fun2eq

Make equation from function
get2ndIndirect

get2ndIndirect effect
labels2table

Make table with labels
getYhat

Get predicted value from object of class "lm"
label2name

Change label into name
getYhat1

Get Yhat value from simple mediation
makeCoefLabel

Change regression coefficient name
getCoef

Get coef summary table
getEq2p

get slope and intercept with 2 points
makeEquation2

Make mediation equations 2
meanSummary

Make mean summary table
makeEquation1

Make mediation equations 1
makeEquation

Make mediation equations 3
makeCEDf

Make data summarizing conditional effects
makeAnovaDf

Make data summarizing ANOVA results
getCatSlopeDf

Make data summarizing regression slopes and intercepts
meanSummaryTable

Make mean summary table
modSummary3

Summary of moderation effect
makeCatModel

Make simple regression model with one categorical variable
makeCatEquation3

Make equation for sem and lm for multiple X or multiple Y
matrix2df

Make data.frame with matrix
matrix2no

Calculate the dimension of matrix
modSummary2

Make table summarizing moderation effect
moderator2pos

get position from moderator
modSummary2Table

Make flextable summarizing moderation effect
makeIndirectEquationCat

Make indirect equation for categorical variables
glbwarm

Global Warming dataset
ggCor

Draw a heatmap of correlation test
moderator2df

Make data.frame from a list of moderator
modelsSummaryTable

Make Summary Table for Model Coefficients
modSummary3Table

Make flextable summarizing moderation effect
modmedEquation

Make moderated mediation equation
est2Nodes

Make nodes from estimatesTable
discriminantValidityTable

make discriminant Validity Table
est2Arrows

Make arrows from estimatesTable
estress

ESTRESS: Economic stress dataset
extractIMM

extract index of moderated mediation from string
mycat

append something to file
fit2alpha

Make a Cronbach alpha table
fit2df2

Make a data.frame for conceptDiagram
myarrow2

Draw arrow with adjustment of a position
makeIndirectEquationCat2

Make indirect equation for categorical variables
makeCatEquation2

Make equation for sem and lm for multiple X or multiple Y
makeIndirectEquation

Make indirect equation
makeEquation3

Make mediation equations 3
makeCatEquation

Make equation for sem and lm for categorical variables
medSummaryTable2

Make a table summarizing the mediation effects
medSummaryTable1

Make a table summarizing the mediation effects
modelFitTable2

Extract model fit measures to flextable
multipleMediation

Make Mediation Equation with multiple X or multiple Y
medSummary

Summarize the mediation effects
modelsSummary

Make Summary for Model Coefficients
medSummaryTable

Make a table summarizing the mediation effects
print.compareVIF

S3 method of class compareVIF
productEq

Make products of equations
reliabilityTable2

make reliability Table in flextable format
print.modmedSummary2

S3 method print for an object of class modmedSummary2
matrixPlot

Draw matrix plot
mediationBK

Perform mediation analysis by Baron and Kenny Method
modmedSummary

Summarize the moderated mediation
pmi

PMI: Presumed Media Influence dataset
getInfo

Get information of a model
getHelmert

Get Helmert Coding of column j of group with length of unique values (count-1)
interactStr

make interaction equation
meanCentering

Perform mean centering
myarrow

Draw arrow
parrows

Arrow Data Set for drawing statistical diagram of process macro model
parallelMatrix

Make bmatrix for parallel multiple mediator model
modelFitTable

Extract model fit measures to data.frame
modelFitGuideTable2

Model fit guide table
modelFitGuideTable

Model fit guide table
modSummaryTable

Make flextable summarizing moderation effect
mycor

Perform correlation and linear regression for a data.frame
myflatten

flatten string
modSummary

Make moderation effect summary
modelsSummary2

Make Summary for Model Coefficients
jnPlot

Draw johnson_neyman plot
pmacro

Data Set for process macro model
makeLabel

Make Labels
modmedSummaryTable

Make a table summarizing the moderated mediation
pastecolon

paste two character with colon
moreModels

more models data
makePPTx

make powerpoint presentation
pmacroModel

draw conceptual diagram of process macro model
mylm

Correlation and Fitting linear model function for function "mycor"
print.mediationBK

S3 method for class mediationBK
myformat

Format a numeric vector
print.medSummary2

S3 method print for an object of class medSummary2
r2diff

Calculate difference of R2 and adjusted R2
pformat

Make p value format
seekGroup1

Find group with variable name
str_detect2

Extension of str_detect to list
seekGroup2

Find group with variable name
str_setdiff

Remove matched pattern from string
r2pptx

Make powerpoint presentation from R file
print.modSummary

S3 method of class modSummary
tripleInteraction

Make triple interaction equation
p2asterisk

Convert p values to asterisk
p2chr

Convert p values to character
modelsSummary2Table

Make Summary Table 2 for Model Coefficients
plotCoef

Make Slopes Plot
plot.mediationBK

S3 method for class mediationBK
print.modelSummary

S3 method print for object modelSummary
print.modelSummary2

S3 method print for object modelSummary2
modmedSummary2Table

make table summarizing moderated mediation effect
unfold

Unfold equations
print.meanSummary

S3 method of class meanSummary
print.medSummary

S3 method print for an object of class medSummary
nodes

Node Data Set for drawing statistical diagram of process macro model
numberSubscript

Make number subscript
protest

Protest dataset
removeParentheses

Remove parentheses
rightPrint

Print a string in right alignment
seekVar

Seek var form covariates
qqPlot

Draw quantile-quantile plot
seekNameVars

select names of variables from list var
print.modmedSummary

S3 method print for an object of class modmedSummary
standardize

Standardize variable
showModels

Run process macro shiny app
sumEquation

summation of equations
summary.mediationBK

S3 method for class mediationBK
strGrouping

Make Grouping equation
seekGroup

Find group with variable name
str2vector

Make character vector from string
theme_clean2

Clean theme for ggCor
treatInteraction

unfold interaction
reliabilityTable

make reliability Table
regEquation

Make regression equation
teachers

Teacher Efficacy Data
setPositionNodes

Set Position of nodes
vars2df

Make data.frame from a list of vars
separateEq

Separate equation
vif

Variance Inflation Factors Calculates variance-inflation and generalized variance-inflation factors for linear, generalized linear, and other models.
teams

Teams data set
standardizeDf

standardize data
treatModerator

Treat moderator name with mean value
statisticalDiagram

Draw statistical diagram
tripleEquation

Make equation with triple interaction
ztable.modelSummary

S3 method for class 'modelSummary'
ztable.compareMC

S3 method for class compareMC
addPlus

Add `+` mark to string
addNodes

Add covariates to nodes
addLatentNodes

Add latent nodes information to nodes
addCovarEquation

Add covariates to equation
addTripleInteraction

Add triple interaction
adjustNodes

Adjust y position of nodes