knitr::opts_chunk$set(collapse = T, comment = "#>") library(modelr) data("mobi", package = "semPLS")
There are now many packages available for R to build, estimate and make predictions on PLS SEM models. However, the syntax of these models is disparate and complicated and often discourages practitioners from use.
The goal of modelr is to provide a natural syntax for researchers to describe PLS structural equation models and that provides functionality across many different PLS SEM estimation and prediction packages, such as semPLS, matrixPLS and simplePLS.
The description of the model often takes longer and requires dozens of lines of code, however modelr seeks to automate this process and make modelling such features as interactions and mediations much simpler.
There are 3 basic steps in the PLS SEM model description:
Describe the structural (inner) model
Describe the measurement (outer) model
Describe interactions
The modelr package makes these steps fast and easy:
By providing easily readable and writable syntax, describing the model becomes simpler - and you can quickly change paths and structures allowing for multiple model comparisons.
It provides simple "verbs", functions that correspond to the most common data manipulation tasks, to help you translate those thoughts into code.
It automates such tedious tasks as creating interaction terms which usually require multiple lines of code and can be difficult to read and follow.
This document introduces you to modelr's basic set of tools, and shows you how to apply them to your models. Other vignettes provide more details on specific topics:
vignette#2: bla bla bla
vignette#3: bla bla bla
To explore the basic syntax of modelr, we'll start with the data bundled with the semPLS package - mobi
data frame. The data set is used as measurement instrument for the european customer satisfaction index (ECSI) adapted to the mobile phone market, see Tenenhaus et al. (2005).
data("mobi", package = "semPLS") dim(mobi) head(mobi)
PLS SEM estimation and prediction packages generally take a source - target type matrix as parameters for each of the structural model and the measurement model. They require the practitioner to create any interaction terms by hand prior to model description. Modelr makes use of simple and natural verbs to describe the model.
Modelr verbs for measurement model description:
multi_items()
reflect()
(or form()
)measure()
These verbs are highly intuitive and provide for human-readable code that allows a practitioner to understand a measurement model on first glance and easily make changes to compare different measurement models.
multi_items()
or single item measurement items with single_item()
single_item()
provides a verb to describe a single measurement item, while
multi_items()
provides a verb to describe multiple measurement items in one simple line of human-readable code.
For example, we can describe the manifest variables: IMAG1, IMAG2, IMAG3, IMAG4 and IMAG5:
multi_items("IMAG", 1:5)
This is equivalent to the more verbose code in base R:
c("IMAG1", "IMAG2", "IMAG3", "IMAG4", "IMAG5")
multi_items()
is used in conjunction with reflect()
or form()
to describe a factor.
form()
or reflect()
form()
and reflect()
provide a verb to describe a factor in one simple line of human-readable code.
For example, we can describe the reflective factor "Image" with manifest variables IMAG1, IMAG2, IMAG3, IMAG4 and IMAG5:
reflect("Image", multi_items("IMAG", 1:5))
or
form("Image", multi_items("IMAG", 1:5))
This is equivalent to the more verbose code in base R:
c("Image", "IMAG1", "Image", "IMAG2", "Image", "IMAG3", "Image", "IMAG4", "Image", "IMAG5")
for reflective factors or:
c("IMAG1", "Image", "IMAG2", "Image", "IMAG3", "Image", "IMAG4", "Image", "IMAG5", "Image")
for formative factors.
multi_items()
is used in conjunction with reflect()
or form()
to describe a factor.
measure()
is used in conjunction with multiple factor descriptions to describe the entire measurement model.
measure()
measure()
compiles the measurement model source-target matrix from the user specified factor descriptions described in the parameters.
For example, we can create a source-target matrix measurement model for the mobi
data:
mobi_mm <- measure( reflect("Image", multi_items("IMAG", 1:5)), reflect("Expectation", multi_items("CUEX", 1:3)), reflect("Quality", multi_items("PERQ", 1:7)), reflect("Value", multi_items("PERV", 1:2)), form("Satisfaction", multi_items("CUSA", 1:3)), form("Complaints", single_item("CUSCO")), form("Loyalty", multi_items("CUSL", 1:3)) )
The output of this code is:
mobi_mm
This is equivalent to the more verbose code in base R:
mobi_mm <- matrix(c("Image","IMAG1", "Image","IMAG2", "Image","IMAG3", "Image","IMAG4", "Image","IMAG5", "Expectation","CUEX1", "Expectation","CUEX2", "Expectation","CUEX3", "Quality", "PERQ1", "Quality", "PERQ2", "Quality", "PERQ3", "Quality", "PERQ4", "Quality", "PERQ5", "Quality", "PERQ6", "Quality", "PERQ7", "Value","PERV1", "Value","PERV2", "CUSA1", "Satisfaction", "CUSA2", "Satisfaction", "CUSA3", "Satisfaction", "CUSCO", "Complaints", "CUSL1", "Loyalty", "CUSL2", "Loyalty", "CUSL3", "Loyalty"),nrow=24,ncol=2,byrow =TRUE, dimnames = list(1:24,c("source","target")))
That was a mouthful of code! The modelr()
syntax is far more human-readable and the use of the verbs really makes the meaning explicit. Modifications to the modelr()
measurement model description are quick and easy and intuitive.
Modelr verbs for structural model description:
paths()
structure()
These verbs are highly intuitive and provide for human-readable code that allows a practitioner to understand the structural model on first glance and easily make changes to compare different structural models.
paths()
paths()
provides a verb to describe single or multiple structural paths.
For example, we can describe the structural model paths:
paths(from = "Image", to = c("Expectation", "Satisfaction", "Loyalty")) paths(from = "Value", to = c("Satisfaction"))
This is equivalent to the more verbose code in base R:
c("Image", "Expectation", "Image", "Satisfaction", "Image", "Loyalty") c("Value","Satisfaction")
paths()
is used in conjunction with structure()
to describe the full structural model.
structure()
structure()
compiles the structural model source-target matrix from the user specified structural path descriptions described in the parameters.
For example, we can create a source-target matrix structural model for the mobi
data:
mobi_sm <- structure( paths(from = "Image", to = c("Expectation", "Satisfaction", "Loyalty")), paths(from = "Expectation", to = c("Quality", "Value", "Satisfaction")), paths(from = "Quality", to = c("Value", "Satisfaction")), paths(from = "Value", to = c("Satisfaction")), paths(from = "Satisfaction", to = c("Complaints", "Loyalty")), paths(from = "Complaints", to = "Loyalty") )
The output of this code is:
mobi_sm
This is equivalent to the more verbose code in base R:
mobi_sm <- matrix(c("Image","Expectation", "Image","Satisfaction", "Image","Loyalty", "Expectation","Quality", "Expectation","Value", "Expectation","Satisfaction", "Quality","Value", "Quality","Satisfaction", "Value", "Satisfaction", "Satisfaction", "Complaints", "Satisfaction", "Loyalty", "Complaints", "Loyalty"),nrow=12,ncol=2,byrow =TRUE, dimnames = list(1:12,c("source","target")))
Used in conjunction with the measurement model verbs, the description and comparison of your models can really be more intuitive and readable.
Modelr verbs for creating Interaction Terms:
interact()
interaction_combo()
Most PLS SEM packages require practitioners to create interaction terms by hand which can be a time-consuming and arduous task - not to mention presenting an opporunity for errors to enter the model. These verbs are highly intuitive and provide for human-readable code that allows a practitioner to quickly describe and "read" interaction terms and make changes and comparisons on the fly.
interaction_combo()
interaction_combo()
provides a verb to describe single interaction item.
For example, we can describe the following interaction items:
interaction_combo("Image", "Expectation") interaction_combo("Image", "Value")
These functions return functions themselves which are not resolved until passed as parameters to the interact()
function.
interact()
interact()
provides a verb to describe all interactions in a specific model. The function itself returns a function which is not resolved until passed as a parameter to the modelr()
function.
For example, we can describe the following interaction items in a model:
mobi_xm <- interact( interaction_combo("Image", "Expectation"), interaction_combo("Image", "Value") )
The output of this code is:
mobi_xm
As previously mentioned, a function which is not resolved until passed to modelr()
.
modelr()
Modelr verbs for PLS SEM model estimation:
modelr()
This verb is used to estimate your final PLS model using the semPLS function.
It takes as parameters the structural model described by structure()
, the measurement model described by measure()
and an optional interactions function as described by interact()
.
For example, we can estimate the PLS SEM model based upon the structural and measurement model with interactions as described previously in this vignette.
# modelr syntax for creating measurement model mobi_mm <- measure( reflect("Image", multi_items("IMAG", 1:5)), reflect("Expectation", multi_items("CUEX", 1:3)), reflect("Value", multi_items("PERV", 1:2)), reflect("Satisfaction", multi_items("CUSA", 1:3)) ) # interaction factors must be created after the measurement model is defined mobi_xm <- interact( interaction_combo("Image", "Expectation"), interaction_combo("Image", "Value") ) # structural model: note that name of the interactions factor should be # the names of its two main factors joined by a '.' in between. mobi_sm <- structure( paths(to = "Satisfaction", from = c("Image", "Expectation", "Value", "Image.Expectation", "Image.Value")) ) mobi_pls <- modelr(mobi, mobi_mm, mobi_xm, mobi_sm)
The output of this code is:
mobi_pls print_paths(mobi_pls) plot_scores(mobi_pls)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.