Get AI summaries of any video or article — Sign up free
02. SEMinR Lecture Series - Introduction to SEMinR, R and R Studio thumbnail

02. SEMinR Lecture Series - Introduction to SEMinR, R and R Studio

Research With Fawad·
4 min read

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.

TL;DR

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?

Because installation and loading are separate steps. install.packages() places the package in the local software library on the computer, but it does not automatically load it into the current RStudio session. Each session requires library(packageName) to make functions available. Without library(seminr) (or library(swirl)), SEMinR functions won’t be recognized and code won’t run.

What’s the practical difference between a function, an argument, and a code block in R?

A function is a self-contained module of code that performs a specific task. An argument is the information passed into a function so it can execute correctly (for example, specifying inputs to an analysis function). A code block is a set of lines grouped together as a unit. These terms matter because SEMinR scripts repeatedly call functions with arguments to define and estimate models.

How do comments help when writing R scripts for SEMinR?

Comments document intent and are not executed by R. They’re written with the hash symbol (#). In SEM scripts, comments can clarify what a line is doing—such as labeling where the measurement model or structural model is defined—without affecting computation.

What should be understood before starting SEM analysis in R with SEMinR?

Learners should understand measurement models and structural models, plus the underlying SEM building blocks: constructs, variables, and bootstrapping. The lecture emphasizes that these concepts are prerequisites, since SEMinR code and outputs rely on them repeatedly.

How can learners get function-level help inside RStudio?

By using the question-mark help syntax. For example, typing ?read.csv brings up a help page with usage, argument details, examples, and other information like memory usage. This same approach works for SEMinR functions via ?seminr.

What’s the role of vignettes when direct documentation isn’t found?

When ?seminr doesn’t show documentation for a specific package namespace, double question marks can surface vignettes (e.g., ??seminr). Vignettes function like user guides, offering structured explanations and examples for using SEMinR effectively.

Review Questions

  1. What steps are required to make SEMinR functions available in a fresh RStudio session, and why?
  2. Define code, function, argument, code block, and comment in the context of R scripts used for SEMinR.
  3. How do ?functionName and ??packageName differ as help tools in RStudio?

Key Points

  1. 1

    Install packages using install.packages() with internet access, but load them each session using library() to make functions available for computation.

  2. 2

    RStudio’s workflow for SEMinR depends on correctly managing packages: installed packages are not automatically loaded into the environment.

  3. 3

    R scripts replace drag-and-drop workflows by using structured code that defines models, runs algorithms, and reports results.

  4. 4

    Understanding SEM building blocks—measurement models, structural models, constructs, variables, and bootstrapping—is necessary before running SEMinR analyses.

  5. 5

    R syntax fundamentals (functions, arguments, code blocks, and # comments) are repeatedly used in SEMinR scripts and tutorials.

  6. 6

    RStudio’s built-in help system (e.g., ?read.csv, ?seminr, ??seminr) provides usage, arguments, examples, and vignettes for deeper learning.

  7. 7

    Community resources like Stack Overflow can complement official documentation when troubleshooting or seeking examples.

Highlights

Installed packages don’t automatically become usable; library() must be called in every new session for SEMinR functions to work.
Comments in R (#) are for documentation only—they don’t run—making scripts easier to interpret when defining measurement and structural models.
RStudio help can be summoned instantly with ?functionName, and vignettes can be accessed with ??packageName for broader guidance.
Before touching SEMinR code, learners are urged to master measurement models, structural models, constructs, variables, and bootstrapping.
R scripts (ending in .R) act like project files for analyses, replacing drag-and-drop model building with reproducible code.

Topics

  • RStudio Layout
  • R Packages
  • SEMinR Setup
  • Measurement vs Structural Models
  • R Help and Vignettes