02. SEMinR Lecture Series - Introduction to SEMinR, R and R Studio
Based on Research With Fawad's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.
Install packages using install.packages() with internet access, but load them each session using library() to make functions available for computation.
Briefing
RStudio is introduced as the working hub for running SEMinR analyses in R, with a clear emphasis on how packages, libraries, and help resources fit together. The core workflow is: install needed packages (with internet access), load them into the current R session using the library() function, then run SEMinR code. Packages provide both standard statistical tools—like mean, standard deviation, and linear regression via linear model functions—and specialized functionality for SEMinR tasks such as PLS-SEM.
A major practical distinction is laid out between installing packages and loading them. Once installed, packages live in the local software library on the computer, but they are not automatically available in the RStudio environment for computation. Each new session requires explicitly loading packages with library(), otherwise SEMinR-related functions won’t be recognized and code will fail. The session demonstrates this with install.packages() for installing swirl (a learning package for R) and SEMinR for SEM work, followed by library(swirl) to activate it and library(seminr) to make SEMinR functions usable.
The lecture then shifts from interface mechanics to programming fundamentals that matter for SEMinR users. R code is presented as a structured language with syntax elements that recur throughout tutorials: code objects and functions, arguments passed into functions, code blocks, and comments. Comments—written with the hash (#) symbol—are used to document intent and are ignored by the interpreter. This matters because SEMinR analyses rely on correctly formatted scripts that define measurement models and structural models, along with constructs and variables.
Measurement model and structural model concepts are flagged as prerequisites for anyone starting SEM analysis in R. The session points learners to separate resources on the channel for understanding SEM basics, including constructs, variables, and bootstrapping—core ideas that will reappear when building and estimating models in SEMinR.
Finally, the lecture focuses on how to learn efficiently inside RStudio using built-in documentation. Help is accessed by typing a question mark before a function name (e.g., ?read.csv or ?seminr). When SEMinR documentation isn’t found directly, double question marks can surface vignettes (e.g., ??seminr), which act like user guides. The same help system provides usage details, argument lists, examples, and even memory usage information. For broader troubleshooting and examples, the session also points to open-access community resources such as Stack Overflow, reinforcing that R’s open-source ecosystem is a key advantage for learners building SEM skills with SEMinR.
Cornell Notes
SEMinR work in RStudio depends on a repeatable setup: install required packages with install.packages() (internet needed), then load them each session with library() so functions are available. The lecture distinguishes installation from loading—installed packages sit in the local library but won’t run until explicitly loaded. It also lays groundwork for reading and writing R scripts by defining recurring syntax elements: functions, arguments, code blocks, and comments (#), which document without executing. Before running SEMinR analyses, learners are urged to understand measurement models, structural models, constructs, variables, and bootstrapping. Finally, built-in help in RStudio (e.g., ?read.csv, ?seminr, ??seminr) and vignettes provide usage, arguments, examples, and guidance for learning.
Why does code fail even after a package is installed?
What’s the practical difference between a function, an argument, and a code block in R?
How do comments help when writing R scripts for SEMinR?
What should be understood before starting SEM analysis in R with SEMinR?
How can learners get function-level help inside RStudio?
What’s the role of vignettes when direct documentation isn’t found?
Review Questions
- What steps are required to make SEMinR functions available in a fresh RStudio session, and why?
- Define code, function, argument, code block, and comment in the context of R scripts used for SEMinR.
- How do ?functionName and ??packageName differ as help tools in RStudio?
Key Points
- 1
Install packages using install.packages() with internet access, but load them each session using library() to make functions available for computation.
- 2
RStudio’s workflow for SEMinR depends on correctly managing packages: installed packages are not automatically loaded into the environment.
- 3
R scripts replace drag-and-drop workflows by using structured code that defines models, runs algorithms, and reports results.
- 4
Understanding SEM building blocks—measurement models, structural models, constructs, variables, and bootstrapping—is necessary before running SEMinR analyses.
- 5
R syntax fundamentals (functions, arguments, code blocks, and # comments) are repeatedly used in SEMinR scripts and tutorials.
- 6
RStudio’s built-in help system (e.g., ?read.csv, ?seminr, ??seminr) provides usage, arguments, examples, and vignettes for deeper learning.
- 7
Community resources like Stack Overflow can complement official documentation when troubleshooting or seeking examples.