Create Project, Load, and Inspect Data in SEMinR

Create Project, Load, and Inspect Data

Create Project, Load and Inspect Data SEMinR

This session on on SEMinR Package will focus on Create a Project, Load, and Inspect the Data in SEMinR

Understanding SEMinR Package

  • SEMinR is a software package developed for the R statistical environment (R Core Team, 2021) that brings a user-friendly syntax to creating and estimating structural equation models.
  • SEMinR is open source, which means that anyone can inspect, modify, and enhance the source code.
  • Users of SEMinR can also interact with the developers and each other at the Facebook group (https:// www.facebook.com/ groups/seminr).
  • The SEMinR syntax enables applied practitioners of PLS-SEM to use terminology that is very close to their familiar modeling terms (e.g., reflective, composite, and interactions), instead of specifying underlying matrices and covariances.
# Download and install the SEMinR package
# You only need to do this once to equip
# Rstudio on your computer with SEMinR
install.packages(“seminr”)
# Make the SEMinR library ready to use
# You must do this every time you restart Rstudio and wish to use SEMinR
library(seminr)

SEMinR

There are four steps to specify and estimate a structural equation model using SEMinR:

  • Loading and cleaning the data
  • Specifying the measurement models
  • Specifying the structural model
  • Estimating, bootstrapping, and summarizing the model

Step 1: Loading and Cleaning the Data

  • When estimating a PLS-SEM model, SEMinR expects you to have already loaded your data into an object. This data object is usually a data.frame class object.
  • The read.csv() function allows you to load data into R if the data file is in a .csv (comma-separated value) or .txt (text) format. Note that there are other packages that can be used to load data in Microsoft Excel’s .xlsx format or other popular data formats.
  • Comma-separated value (CSV) files are a type of text file, whose lines contain the data of each subject or case of your dataset.
  • The values are typically separated by commas but can also be separated by other special characters (e.g., semicolons).
  • The first line of the file typically consists of variable names, called the header line, and is also separated by commas or other special characters.
  • Thus, a variable will have its name in the first row and its values will be in all the following lines of data at the same position.
  • Many software packages, such as Microsoft Excel and SPSS, can export data into a .csv format.
  • We can load data from a .csv file using the read.csv().
  • Remember that you can use the ? operator to find help about a function in R (e.g., use ?read. csv).
  • Table shows several arguments for the read.csv().
  • In this section, we will demonstrate how to load a .csv file into the Rstudio global environment.
  • The comma (,) is used as a separator character, and the missing values are coded as −99.
  • If you wish to import this file to the global environment, you can use the read.csv() function,
#Step 1 
library(seminr)
# Load the Data
data <- read.csv(file = "Data.csv", header = TRUE, sep = ",")

When Data file is not in the same folder as R Script

#Data File not in the Sample Folder
datas <- read.csv(file = "D:\\SEMinR\\Data.csv", header = TRUE, sep = ",")

Important

  • Inspect the loaded data to ensure that the correct numbers of columns (indicators), rows (observations or cases), and column headers (indicator names) appear in the loaded data.
  • Note that SEMinR uses the asterisk (“*”) character when naming interaction terms as used in, for example, moderation analysis, so please ensure that asterisks are not present in the indicator names.
  • Duplicate indicator names will also cause errors in SEMinR. Finally, missing values should be represented with a missing value indicator (such as −99, which is commonly used), so they can be appropriately identified and treated as missing values.
  • We will use head() function to inspect the data.
  • It is clear from inspecting the head of the data object () that the file has been loaded correctly and has the value “-99” set for the missing values.
  • With the data loaded correctly, we now turn to the measurement model specification.
#To Inspect Data
head(data)

Review of the Steps

Following is a brief review of the steps that have been discussed in SEMinR tutorials. 

  • Load the Library – library ()
  • Load the Data – read.csv
  • Review the Data – head()

Complete Code

#Loading the Library
library(seminr)
# Load the Data
datas <- read.csv(file = "Data.csv", header = TRUE, sep = ",")
#To Inspect Data
head(datas)

Reference

Hair Jr, J. F., Hult, G. T. M., Ringle, C. M., Sarstedt, M., Danks, N. P., & Ray, S. (2021). Partial Least Squares Structural Equation Modeling (PLS-SEM) Using R: A Workbook.

Partial Least Squares Structural Equation Modeling (PLS-SEM) Using R

The tutorials on SEMinR are based on the mentioned book. The book is open source and available for download under this link.

Download PDF

 

Video Tutorial