Econistics Research and Consulting | Chapter 3 – Structure Detection / Index Making / Confirmatory Factor Analysis in R Studio
Econometrics, Data Science, Research Methods, Statistics, STATA, R,
25490 # Chapter 3 – Structure Detection / Index Making / Confirmatory Factor Analysis in R Studio

## 17 Jun Chapter 3 – Structure Detection / Index Making / Confirmatory Factor Analysis in R Studio

This tutorial explores the structure detection approach to reduce the variables into relevant sub-indices. This is a second method to reduce the dimensions to avoid multicollinearity when variables are forming theoretical groups. This method is the first step to estimate SEM model. This method can be used to constitute indexes of unequal weight-ages rather than the averaging method which has equal weight-ages.

library(psych) # for rotated factor analysis
library(polycor)
library(GPArotation)
library(tidyverse)

df <- read_excel(“D:/UMT notes/MPhil – MS courses/Applied Econometrics/lectures applied econometrics/lecture 6/data reduction using factor analysis/car_sales.xlsx”, skip = 1)

## Selecting variables

df1 <- df %>% select(type, price, engine_s, horsepow, wheelbas, width, length, curb_wgt, fuel_cap, mpg)

df1 <- drop_na (df1)
corrplot(cor(df1), method=”color”)

df1_hetcor <- hetcor(df1)
df1_c <- df1_hetcor\$correlations
df1_factor <- cortest.bartlett(df1_c)

# Bartlett Test

df1_factor
KMO(df1_c)

qgraph(cor(df1), title = “Q Graph of Indicators”, posCol=”darkgreen”, negCol=”darkmagenta”)
qgraph(cor(df1), title = “Q Graph of Indicators”, layout=”spring”, shape=”rectangle”, posCol=”darkgreen”, negCol=”darkmagenta”)

pa is principal axis factor approach
threefactor <- fa(df1, nfactors = 2, rotate =”Varimax”, fm = “pa”)
threefactor_common <- sort(threefactor\$communality, decreasing = TRUE)
data.frame(threefactor_common)

threefactor_unique <- sort(threefactor\$uniqueness, decreasing = TRUE)
data.frame(threefactor_unique)

library(psych) # for rotated factor analysis
library(polycor)
library(GPArotation)
library(tidyverse)

df <- read_excel(“D:/UMT notes/MPhil – MS courses/Applied Econometrics/lectures applied econometrics/lecture 6/data reduction using factor analysis/car_sales.xlsx”, skip = 1)

## Selecting variables

df1 <- df %>% select(type, price, engine_s, horsepow, wheelbas, width, length, curb_wgt, fuel_cap, mpg)

df1 <- drop_na (df1)
corrplot(cor(df1), method=”color”)

df1_hetcor <- hetcor(df1)
df1_c <- df1_hetcor\$correlations
df1_factor <- cortest.bartlett(df1_c)

# Bartlett Test

df1_factor
KMO(df1_c)

qgraph(cor(df1), title = “Q Graph of Indicators”, posCol=”darkgreen”, negCol=”darkmagenta”)
qgraph(cor(df1), title = “Q Graph of Indicators”, layout=”spring”, shape=”rectangle”, posCol=”darkgreen”, negCol=”darkmagenta”)

pa is principal axis factor approach
threefactor <- fa(df1, nfactors = 2, rotate =”Varimax”, fm = “pa”)
threefactor_common <- sort(threefactor\$communality, decreasing = TRUE)
data.frame(threefactor_common)

threefactor_unique <- sort(threefactor\$uniqueness, decreasing = TRUE)
data.frame(threefactor_unique)

paf <- fa.parallel(df1, fm = ‘pa’, fa = ‘fa’)
df3 <- threefactor\$scores
print(threefactor)