1 Getting started: Rprojects, Rmarkdown, Git-Github


2 Steps to download repositories from Github and create a version controlled R-project

  1. Create a Github account and connect R-Studio with Git
  2. Go to the Lab10 repository link to Fork and Clone (copy address) the repository:
  3. Within R-studio create a New project and choose the Version Control Option (Git)
  4. Paste the repository address copied (cloned) from Github and save locally on your computer
  5. After making changes in your branch of the repository to update the version on Github follow the following sequence of steps: Stage, Commit (add commit message), Pull, and then Push

3 Outline


DATA SOURCE: This lab exercise utilizes a subset of the HSLS public-use dataset: High School Longitudinal Study of 2009 (Ingels et al., 2011) \(\color{blue}{\text{See website: nces.ed.gov}}\)

FURTHER READING: A description of the models run in this lab exercise can be found in chapter 16 (page 411) in Kline, 2016. All specifications for invariance with the WLS estimator follow the recomendations found in this book. \(\color{blue}{\text{Example Mplus Syntax}}\)


3.1 When to use the Weighted Least Squared (WSL) method?

  1. you have ordinal indicators (e.g., Likert scales)
  2. you have categorical indicators (e.g., binary, or nominal)
  3. you have a combination of ordinal, categorical, and/or continuous indicators
  4. you have skewed continuous indicators

3.2 How to specify the Robust WSL estimator (WLSMV) in Mplus

Include the following lines of syntax:

  • categorical = X1 X2 X3... ; identify any categorical indicators
  • estimator = wlsmv;
  • parameterization = theta; to allow for error variances to be freely estimated across groups

3.3 Interpretation of \(\chi^2\) with WLS estimator

  • Cannot do normal chi-square difference tests (use the DIFFTEST option)
  • The scaled Satorra-Bentler correction is required

# load packages
library(MplusAutomation)
library(haven)
library(rhdf5)
library(tidyverse)
library(here)
library(corrplot)
library(kableExtra)
library(reshape2)
library(semPlot)
library(gt)

4 Prepare data


4.1 Read in data

data_raw <- read_csv(here("data", "hsls_fa_data_subset.csv"))

4.2 Reverse code for factor interpretation

hsls_data <- data_raw 

cols = c("S1MPERS1", "S1MPERS2", "S1MUSELI", "S1MUSECL", "S1MUSEJO",
         "S1MTESTS", "S1MTEXTB", "S1MSKILL", "S1MASSEX", "S1MENJNG",
         "S1SPERS1", "S1SPERS2", "S1SUSELI", "S1SUSECL", "S1SUSEJO",
         "S1STESTS", "S1STEXTB", "S1SSKILL", "S1SASSEX", "S1SENJNG")

hsls_data[ ,cols] <-  5 - hsls_data[ ,cols]

4.3 Check correlations of science indicators

sci_cor <- cor(hsls_data[27:38], use = "pairwise.complete.obs")
#sci_cor

corrplot(sci_cor, 
         method = "circle",
         type = "upper")