R Markdown

This is a blank R Markdown document that you can use as a space to write the code for your assignment in and save it as you go. Make sure that you have gone through “A2-Setup.Rmd” first.

As stated in the instructions document, you should not submit this R Markdown as your assignment. See submission details in the instructions document for more information.

# You can start writing code here and use separate R Chunks as needed

# You may wish to start by clearing out your Environment, and loading your data by adapting the following code:

load("ADDA_Assignment_2_1307187.RData")

load packages

library(tidyverse)      # Data wrangling
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.4     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(psych)          # Used to undertake the EFA and related analyses 
## 
## Attaching package: 'psych'
## 
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
library(GPArotation)    # Called by psych to run certain parts of the EFA 
## 
## Attaching package: 'GPArotation'
## 
## The following objects are masked from 'package:psych':
## 
##     equamax, varimin
library(EFA.dimensions) # Used for the RAWPAR function
## **************************************************************************************************
## EFA.dimensions 0.1.8.4
## 
## Please contact Brian O'Connor at brian.oconnor@ubc.ca if you have questions or suggestions.
## **************************************************************************************************
library(knitr)          # Used knitting the R Markdown document
library(dplyr)
library(ggplot2)
library(MVN)
library(lavaan)      # CFA/SEM
## This is lavaan 0.6-19
## lavaan is FREE software! Please report any bugs.
## 
## Attaching package: 'lavaan'
## 
## The following object is masked from 'package:psych':
## 
##     cor2cov
library(semPlot)     # For use of the `semPaths()` function to create the figure
library(kableExtra)
## 
## Attaching package: 'kableExtra'
## 
## The following object is masked from 'package:dplyr':
## 
##     group_rows

summary data/descriptive statistics

summary(data)
##        q1              q2              q3              q4       
##  Min.   :2.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:4.000   1st Qu.:3.000   1st Qu.:2.000   1st Qu.:3.000  
##  Median :5.000   Median :3.000   Median :3.000   Median :4.000  
##  Mean   :5.049   Mean   :3.273   Mean   :3.021   Mean   :3.569  
##  3rd Qu.:6.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000  
##  Max.   :8.000   Max.   :6.000   Max.   :6.000   Max.   :8.000  
##        q5              q6              q7              q8       
##  Min.   :1.000   Min.   :1.000   Min.   :2.000   Min.   :2.000  
##  1st Qu.:3.000   1st Qu.:4.000   1st Qu.:4.000   1st Qu.:4.000  
##  Median :4.000   Median :4.000   Median :5.000   Median :4.000  
##  Mean   :3.935   Mean   :4.416   Mean   :4.551   Mean   :4.501  
##  3rd Qu.:5.000   3rd Qu.:5.000   3rd Qu.:5.000   3rd Qu.:5.000  
##  Max.   :7.000   Max.   :7.000   Max.   :7.000   Max.   :8.000  
##        q9             q10             q11             q12       
##  Min.   :2.000   Min.   :1.000   Min.   :1.000   Min.   :2.000  
##  1st Qu.:4.000   1st Qu.:2.000   1st Qu.:3.000   1st Qu.:4.000  
##  Median :5.000   Median :3.000   Median :4.000   Median :5.000  
##  Mean   :4.779   Mean   :3.309   Mean   :4.239   Mean   :4.527  
##  3rd Qu.:5.000   3rd Qu.:4.000   3rd Qu.:5.000   3rd Qu.:5.000  
##  Max.   :8.000   Max.   :8.000   Max.   :8.000   Max.   :7.000  
##       q13             q14             q15             q16       
##  Min.   :2.000   Min.   :2.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:4.000   1st Qu.:4.000   1st Qu.:3.000   1st Qu.:4.000  
##  Median :5.000   Median :5.000   Median :3.000   Median :4.000  
##  Mean   :4.852   Mean   :4.595   Mean   :3.081   Mean   :4.242  
##  3rd Qu.:6.000   3rd Qu.:5.000   3rd Qu.:4.000   3rd Qu.:5.000  
##  Max.   :8.000   Max.   :7.000   Max.   :5.000   Max.   :7.000  
##       q17             q18             q19             q20       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:4.000   1st Qu.:3.000   1st Qu.:3.000   1st Qu.:3.000  
##  Median :5.000   Median :3.000   Median :3.000   Median :3.000  
##  Mean   :4.571   Mean   :3.187   Mean   :3.436   Mean   :3.403  
##  3rd Qu.:6.000   3rd Qu.:4.000   3rd Qu.:4.000   3rd Qu.:4.000  
##  Max.   :8.000   Max.   :6.000   Max.   :6.000   Max.   :6.000  
##       q21             q22             q23             q24            q25       
##  Min.   :2.000   Min.   :1.000   Min.   :1.000   Min.   :1.00   Min.   :1.000  
##  1st Qu.:4.000   1st Qu.:3.000   1st Qu.:4.000   1st Qu.:3.00   1st Qu.:4.000  
##  Median :5.000   Median :4.000   Median :4.000   Median :4.00   Median :4.000  
##  Mean   :4.522   Mean   :3.984   Mean   :4.475   Mean   :3.94   Mean   :4.361  
##  3rd Qu.:5.000   3rd Qu.:5.000   3rd Qu.:5.000   3rd Qu.:5.00   3rd Qu.:5.000  
##  Max.   :8.000   Max.   :8.000   Max.   :8.000   Max.   :7.00   Max.   :7.000  
##       q26             q27             q28            q29             q30       
##  Min.   :1.000   Min.   :1.000   Min.   :1.00   Min.   :1.000   Min.   :1.000  
##  1st Qu.:3.000   1st Qu.:2.000   1st Qu.:4.00   1st Qu.:4.000   1st Qu.:4.000  
##  Median :4.000   Median :3.000   Median :4.00   Median :4.000   Median :5.000  
##  Mean   :3.862   Mean   :3.086   Mean   :4.47   Mean   :4.335   Mean   :4.694  
##  3rd Qu.:5.000   3rd Qu.:4.000   3rd Qu.:5.00   3rd Qu.:5.000   3rd Qu.:6.000  
##  Max.   :7.000   Max.   :5.000   Max.   :7.00   Max.   :7.000   Max.   :8.000
describe(data)

assumption tests

multivariant normality

data_no <- data %>% 
  select(-q10, -q4, -q17, -q23, -q11, -q29, -q7, -q5, -q9, -q25, -q8, -q16, -q21, -q14)

mvn(data = data, mvnTest = "mardia")$multivariateNormality
mvn(data = data_no, mvnTest = "mardia")$multivariateNormality

univariant normaility

SkewKurtosis=function(x) {
  # Arguments 
  N=length(!is.na(x))
  m1=mean(x, na.rm = TRUE)
  dev=(x-m1)
  s1=sd(x)
  
  # Skew calculation
  skew=sum(dev^3)/(N*s1^3)
  seskew=sqrt(6/N)
  crskew = skew/seskew

  # Kurtosis calculation
  top_half = 1/N * sum((x - m1)^4)
  bottom_half = (1/N * sum((x - m1)^2))^2
  kurtosis = top_half / bottom_half - 3
  sekurtosis=sqrt(24/N)
  crkurtosis = kurtosis/sekurtosis
  
  # Print 
  result <- c(skew = skew, seskew = seskew, crskew = crskew, kurtosis= kurtosis, sekurtosis = sekurtosis, crkurtosis = crkurtosis)
  return(result)
}

spss_normality <- 
  mapply(SkewKurtosis, data[, names(data)]) %>%
  t() %>% 
  as.data.frame() %>% 
  rownames_to_column(var = "variable") %>% 
  mutate(across(where(is.numeric), \(x) round(x, digits = 3)))

# Univariate kurtosis and skew - similar to Amos 'Assessment of Normality' table. 
data %>% 
  describe(skew = FALSE) %>% 
  as_tibble() %>% 
  mutate(variable = rownames(describe(data))) %>%
  mutate_if(is.numeric, round, digits=3) %>%
  left_join(spss_normality, by = "variable") %>% 
  select(variable, min, max, skew, crskew, kurtosis, crkurtosis) %>% 
  print(n = Inf)
## # A tibble: 30 × 7
##    variable   min   max   skew crskew kurtosis crkurtosis
##    <chr>    <dbl> <dbl>  <dbl>  <dbl>    <dbl>      <dbl>
##  1 q1           2     8 -0.098 -0.785   -0.177     -0.71 
##  2 q2           1     6 -0.013 -0.102   -0.022     -0.087
##  3 q3           1     6  0.162  1.30     0.06       0.24 
##  4 q4           1     8  0.313  2.50     0.497      1.99 
##  5 q5           1     7  0.021  0.168    0.08       0.32 
##  6 q6           1     7 -0.078 -0.627   -0.004     -0.014
##  7 q7           2     7  0.01   0.082   -0.159     -0.636
##  8 q8           2     8  0.152  1.22    -0.203     -0.812
##  9 q9           2     8 -0.08  -0.644    0.445      1.78 
## 10 q10          1     8  0.275  2.20     0.084      0.335
## 11 q11          1     8 -0.092 -0.735   -0.372     -1.49 
## 12 q12          2     7 -0.197 -1.58    -0.144     -0.578
## 13 q13          2     8  0.131  1.05     0.121      0.485
## 14 q14          2     7  0.017  0.134    0.099      0.395
## 15 q15          1     5  0.08   0.644   -0.121     -0.483
## 16 q16          1     7 -0.022 -0.173   -0.107     -0.427
## 17 q17          1     8 -0.055 -0.439   -0.253     -1.01 
## 18 q18          1     6  0.117  0.935   -0.105     -0.42 
## 19 q19          1     6  0.011  0.086   -0.309     -1.24 
## 20 q20          1     6 -0.063 -0.502   -0.467     -1.87 
## 21 q21          2     8  0.124  0.992    0.018      0.074
## 22 q22          1     8  0.164  1.32     0.256      1.02 
## 23 q23          1     8  0.154  1.24    -0.034     -0.136
## 24 q24          1     7  0.159  1.28     0.02       0.082
## 25 q25          1     7  0.035  0.281   -0.001     -0.002
## 26 q26          1     7 -0.066 -0.527   -0.229     -0.917
## 27 q27          1     5  0.051  0.41    -0.328     -1.31 
## 28 q28          1     7 -0.106 -0.852   -0.178     -0.713
## 29 q29          1     7 -0.185 -1.48    -0.011     -0.043
## 30 q30          1     8  0.127  1.01    -0.241     -0.965

univariant outliers

long_data <- data %>%
  pivot_longer(cols = q1:q30, names_to = "Item", values_to = "Score")

ggplot(long_data, aes(x = Item, y = Score)) +
  geom_boxplot() +
  theme_minimal() +
  theme() +
  labs(title = "Boxplots of All 30 Items",
       x = "Item",
       y = "Score")

outlier_value <-  boxplot.stats(data$q2)$out
outlier_rownumber <- which(data$q2 %in% c(outlier_value))
q2out <- tibble(outlier_rownumber, outlier_value)

multivarient outliers

#mahlanobis distance - mulitvariant outliers
nvar <- 30 # Number of variables in the dataset determines the degrees of freedom for the Chi Square test to see whether the Mahalanobis d-squared values are significant

get_mahal_p2 = function(p1){
  amos_p2 <- numeric(length(p1))
  N <- length(p1)
  amos_p1 <- sort(p1)
  p1_index <- sort(p1, index.return=TRUE)$ix
  for (i in 1:length(amos_p1))
  {
    k <- i;
    p1_value <- amos_p1[i];
    start_value <- 1;
    while (k >= 1)
    {
      start_value = start_value - choose(N,N-k+1) * (1-p1_value)^(N-k+1) * (p1_value)^(k-1)
      k <- k-1;
    }
    amos_p2[i] <- start_value;
  }
  return(amos_p2[order(p1_index)])
}
data %>%
  mutate(`Observation number` = seq.int(from = 1, to = nrow(data)),
         `Mahalanobis d-squared` = mahalanobis(x = data, center = colMeans(data), cov = cov(data)),
         p1 = pchisq(`Mahalanobis d-squared`, df = nvar, lower.tail = FALSE),
         p2 = get_mahal_p2(as.numeric(unlist(p1)))) %>%
  mutate_if(is.numeric, round, digits=3) %>%
  arrange(desc(`Mahalanobis d-squared`)) %>%
  select(`Observation number`, `Mahalanobis d-squared`, p1, p2) %>%
  slice(1:50)   # This outputs rows 1 through to 50, though more can be retained if desired

factorability

#Factorability, multicolliniarity and singularity
cortest.bartlett(data, n = 385) 
## R was not square, finding R from data
## $chisq
## [1] 3887.582
## 
## $p.value
## [1] 0
## 
## $df
## [1] 435
#acceptable, p<0.01

#sampling - common variance
KMO_results <- KMO(data)

KMO_results$MSA %>% 
  round(3)
## [1] 0.888
#overall 0.88 meritorious Kaiser & rice (1974)

KMO_results$Image %>% 
  round(3)  %>% 
  kable()  %>% 
  kable_styling("striped", position = "left", full_width = FALSE)  %>%
  column_spec(1, bold = TRUE, color = "black")
q1 q2 q3 q4 q5 q6 q7 q8 q9 q10 q11 q12 q13 q14 q15 q16 q17 q18 q19 q20 q21 q22 q23 q24 q25 q26 q27 q28 q29 q30
q1 1.000 -0.027 -0.070 -0.029 -0.061 0.010 0.046 -0.009 0.049 0.044 -0.149 -0.040 -0.172 -0.076 -0.032 0.031 -0.234 -0.034 0.054 0.164 -0.094 0.069 -0.139 -0.106 0.002 0.009 -0.066 0.026 0.045 -0.189
q2 -0.027 1.000 -0.095 -0.026 0.003 -0.041 0.042 0.083 -0.041 -0.013 -0.013 0.078 -0.022 0.052 -0.113 0.061 0.036 -0.151 -0.011 -0.163 0.105 -0.025 0.006 -0.032 -0.010 -0.077 -0.185 -0.048 -0.108 -0.005
q3 -0.070 -0.095 1.000 -0.046 -0.005 -0.004 -0.048 0.041 -0.014 -0.064 -0.093 0.044 0.008 0.004 -0.199 -0.045 0.011 -0.209 -0.058 -0.188 0.055 0.010 -0.046 0.009 0.070 -0.049 0.001 0.029 0.072 0.041
q4 -0.029 -0.026 -0.046 1.000 -0.014 0.136 0.087 0.086 -0.064 -0.079 -0.030 0.022 0.072 0.014 -0.061 -0.019 -0.035 -0.118 -0.069 -0.033 0.027 -0.007 0.036 -0.092 0.014 -0.018 0.026 0.077 -0.137 -0.085
q5 -0.061 0.003 -0.005 -0.014 1.000 -0.067 0.017 0.045 -0.009 -0.063 0.022 -0.027 -0.008 0.066 -0.077 -0.070 0.055 -0.035 -0.092 -0.043 -0.005 0.045 0.005 -0.154 -0.092 -0.060 -0.061 0.006 -0.004 0.012
q6 0.010 -0.041 -0.004 0.136 -0.067 1.000 -0.122 -0.093 0.038 0.003 0.023 -0.262 0.093 -0.034 -0.017 -0.085 0.057 -0.071 -0.070 0.123 -0.132 -0.080 0.061 -0.027 0.063 0.055 0.162 -0.061 -0.126 0.036
q7 0.046 0.042 -0.048 0.087 0.017 -0.122 1.000 0.014 -0.094 -0.061 -0.026 -0.095 0.078 -0.112 -0.020 0.006 -0.040 0.037 0.059 -0.051 0.005 -0.157 -0.104 0.009 -0.066 0.083 -0.043 -0.138 -0.105 0.010
q8 -0.009 0.083 0.041 0.086 0.045 -0.093 0.014 1.000 0.018 -0.006 -0.011 -0.001 0.037 0.198 -0.041 -0.012 0.069 -0.080 0.025 -0.105 0.172 -0.069 0.028 -0.073 0.043 -0.012 -0.061 0.048 -0.038 -0.090
q9 0.049 -0.041 -0.014 -0.064 -0.009 0.038 -0.094 0.018 1.000 0.033 0.003 -0.028 -0.100 -0.156 0.013 0.103 0.025 0.007 0.037 0.057 -0.240 0.087 -0.035 0.075 -0.103 -0.062 -0.036 0.047 -0.006 0.008
q10 0.044 -0.013 -0.064 -0.079 -0.063 0.003 -0.061 -0.006 0.033 1.000 -0.015 0.092 0.054 -0.023 -0.118 -0.008 0.068 -0.074 -0.057 -0.061 0.022 0.056 0.009 -0.239 0.043 -0.051 -0.115 0.050 0.029 0.000
q11 -0.149 -0.013 -0.093 -0.030 0.022 0.023 -0.026 -0.011 0.003 -0.015 1.000 -0.031 -0.060 0.015 -0.111 0.051 -0.065 0.026 0.078 -0.034 -0.061 -0.008 -0.073 0.030 0.083 -0.071 0.076 0.006 -0.043 -0.163
q12 -0.040 0.078 0.044 0.022 -0.027 -0.262 -0.095 -0.001 -0.028 0.092 -0.031 1.000 -0.021 -0.028 -0.038 0.003 0.029 0.007 0.096 -0.037 -0.094 -0.194 0.042 -0.068 -0.033 0.034 -0.026 -0.272 -0.073 -0.019
q13 -0.172 -0.022 0.008 0.072 -0.008 0.093 0.078 0.037 -0.100 0.054 -0.060 -0.021 1.000 0.025 0.005 -0.029 -0.083 -0.019 -0.001 0.030 0.002 0.020 -0.075 -0.051 0.013 -0.023 0.031 -0.045 -0.117 -0.292
q14 -0.076 0.052 0.004 0.014 0.066 -0.034 -0.112 0.198 -0.156 -0.023 0.015 -0.028 0.025 1.000 0.015 0.141 0.087 -0.045 -0.018 0.020 -0.212 0.033 -0.072 -0.006 -0.242 0.015 -0.035 -0.004 -0.011 -0.073
q15 -0.032 -0.113 -0.199 -0.061 -0.077 -0.017 -0.020 -0.041 0.013 -0.118 -0.111 -0.038 0.005 0.015 1.000 -0.049 0.019 -0.143 -0.087 -0.138 0.028 -0.088 -0.035 0.079 -0.085 0.071 -0.188 0.035 -0.045 0.074
q16 0.031 0.061 -0.045 -0.019 -0.070 -0.085 0.006 -0.012 0.103 -0.008 0.051 0.003 -0.029 0.141 -0.049 1.000 0.060 -0.029 0.045 0.034 0.054 -0.118 0.022 -0.055 0.124 -0.116 -0.017 -0.082 0.072 -0.008
q17 -0.234 0.036 0.011 -0.035 0.055 0.057 -0.040 0.069 0.025 0.068 -0.065 0.029 -0.083 0.087 0.019 0.060 1.000 -0.074 -0.075 0.033 0.036 0.018 -0.071 -0.033 -0.065 0.009 -0.050 0.004 0.014 -0.162
q18 -0.034 -0.151 -0.209 -0.118 -0.035 -0.071 0.037 -0.080 0.007 -0.074 0.026 0.007 -0.019 -0.045 -0.143 -0.029 -0.074 1.000 -0.030 -0.095 0.020 0.065 0.022 0.014 0.075 -0.027 -0.147 -0.064 0.036 0.082
q19 0.054 -0.011 -0.058 -0.069 -0.092 -0.070 0.059 0.025 0.037 -0.057 0.078 0.096 -0.001 -0.018 -0.087 0.045 -0.075 -0.030 1.000 -0.023 -0.033 -0.079 -0.089 -0.246 -0.055 -0.079 -0.101 0.115 -0.006 -0.077
q20 0.164 -0.163 -0.188 -0.033 -0.043 0.123 -0.051 -0.105 0.057 -0.061 -0.034 -0.037 0.030 0.020 -0.138 0.034 0.033 -0.095 -0.023 1.000 -0.106 0.099 -0.004 0.015 0.005 -0.028 -0.084 0.025 -0.062 -0.054
q21 -0.094 0.105 0.055 0.027 -0.005 -0.132 0.005 0.172 -0.240 0.022 -0.061 -0.094 0.002 -0.212 0.028 0.054 0.036 0.020 -0.033 -0.106 1.000 -0.030 0.098 0.027 -0.058 0.015 -0.143 -0.044 -0.079 0.024
q22 0.069 -0.025 0.010 -0.007 0.045 -0.080 -0.157 -0.069 0.087 0.056 -0.008 -0.194 0.020 0.033 -0.088 -0.118 0.018 0.065 -0.079 0.099 -0.030 1.000 -0.033 -0.021 0.047 -0.009 0.016 -0.096 -0.123 0.042
q23 -0.139 0.006 -0.046 0.036 0.005 0.061 -0.104 0.028 -0.035 0.009 -0.073 0.042 -0.075 -0.072 -0.035 0.022 -0.071 0.022 -0.089 -0.004 0.098 -0.033 1.000 -0.012 0.077 0.029 -0.006 -0.054 -0.057 -0.194
q24 -0.106 -0.032 0.009 -0.092 -0.154 -0.027 0.009 -0.073 0.075 -0.239 0.030 -0.068 -0.051 -0.006 0.079 -0.055 -0.033 0.014 -0.246 0.015 0.027 -0.021 -0.012 1.000 -0.020 -0.361 0.007 -0.086 -0.050 0.083
q25 0.002 -0.010 0.070 0.014 -0.092 0.063 -0.066 0.043 -0.103 0.043 0.083 -0.033 0.013 -0.242 -0.085 0.124 -0.065 0.075 -0.055 0.005 -0.058 0.047 0.077 -0.020 1.000 -0.032 0.205 -0.077 -0.010 0.042
q26 0.009 -0.077 -0.049 -0.018 -0.060 0.055 0.083 -0.012 -0.062 -0.051 -0.071 0.034 -0.023 0.015 0.071 -0.116 0.009 -0.027 -0.079 -0.028 0.015 -0.009 0.029 -0.361 -0.032 1.000 -0.013 -0.069 0.057 0.103
q27 -0.066 -0.185 0.001 0.026 -0.061 0.162 -0.043 -0.061 -0.036 -0.115 0.076 -0.026 0.031 -0.035 -0.188 -0.017 -0.050 -0.147 -0.101 -0.084 -0.143 0.016 -0.006 0.007 0.205 -0.013 1.000 -0.013 -0.023 -0.034
q28 0.026 -0.048 0.029 0.077 0.006 -0.061 -0.138 0.048 0.047 0.050 0.006 -0.272 -0.045 -0.004 0.035 -0.082 0.004 -0.064 0.115 0.025 -0.044 -0.096 -0.054 -0.086 -0.077 -0.069 -0.013 1.000 -0.186 -0.006
q29 0.045 -0.108 0.072 -0.137 -0.004 -0.126 -0.105 -0.038 -0.006 0.029 -0.043 -0.073 -0.117 -0.011 -0.045 0.072 0.014 0.036 -0.006 -0.062 -0.079 -0.123 -0.057 -0.050 -0.010 0.057 -0.023 -0.186 1.000 0.069
q30 -0.189 -0.005 0.041 -0.085 0.012 0.036 0.010 -0.090 0.008 0.000 -0.163 -0.019 -0.292 -0.073 0.074 -0.008 -0.162 0.082 -0.077 -0.054 0.024 0.042 -0.194 0.083 0.042 0.103 -0.034 -0.006 0.069 1.000
#Low anti-image correlations less than absolute size of 0.3

#high MSAi 
KMO_results$MSAi %>% 
  round(3) %>% 
  kable(col.names = "MSAi")  %>% 
  kable_styling("striped", position = "left", full_width = FALSE)  %>%
  column_spec(1, bold = TRUE, color = "black")
MSAi
q1 0.825
q2 0.932
q3 0.939
q4 0.932
q5 0.928
q6 0.865
q7 0.891
q8 0.823
q9 0.844
q10 0.945
q11 0.851
q12 0.887
q13 0.820
q14 0.857
q15 0.918
q16 0.862
q17 0.860
q18 0.936
q19 0.916
q20 0.916
q21 0.849
q22 0.859
q23 0.853
q24 0.838
q25 0.864
q26 0.883
q27 0.908
q28 0.869
q29 0.820
q30 0.805

preferred solutions

parallel test

RAWPAR_output <-
  RAWPAR(data = data_no,          # Specify the name of your raw data
         factormodel = 'PCA', # Leave the option as 'PCA' here
         Ndatasets = 100,     # Number of sets of random data
         percentile = 95,     # Percentile of the random data
         Ncases = 1247,        # Specify the sample size
         verbose = TRUE)      # Required to display the output
## 
## 
## PARALLEL ANALYSIS
## 
## Randomization method: generated data
## 
## Type of correlations specified for the real data eigenvalues: Pearson
## 
## Type of correlations specified for the random data eigenvalues: pearson
## 
## Extraction Method: Principal Components
## 
## Variables = 16
## 
## Cases = 385
## 
## Ndatasets = 100
## 
## Percentile = 95
## 
## Compare the Real Data eigenvalues below to the corresponding
## random data Mean and Percentile eigenvalues
##    Root   Real Data    Mean   Percentile
##       1       4.737   1.362        1.435
##       2       2.361   1.288        1.338
##       3       1.740   1.230        1.278
##       4       1.211   1.179        1.213
##       5       0.727   1.129        1.167
##       6       0.648   1.086        1.115
##       7       0.586   1.048        1.077
##       8       0.568   1.011        1.043
##       9       0.524   0.970        1.004
##      10       0.490   0.933        0.973
##      11       0.463   0.895        0.924
##      12       0.435   0.856        0.885
##      13       0.406   0.819        0.850
##      14       0.377   0.777        0.813
##      15       0.368   0.734        0.766
##      16       0.358   0.682        0.725
## 
## The number of factors according to the parallel analysis = 3
## 
RAWPAR_output
## $eigenvalues
##  Root Real Data      Mean Percentile
##     1 4.7374371 1.3618805  1.4350858
##     2 2.3605052 1.2878706  1.3375657
##     3 1.7402950 1.2298930  1.2777305
##     4 1.2113429 1.1786306  1.2133784
##     5 0.7271847 1.1289619  1.1670642
##     6 0.6479845 1.0861187  1.1154472
##     7 0.5861679 1.0483630  1.0772129
##     8 0.5681592 1.0108843  1.0429748
##     9 0.5241456 0.9701263  1.0041104
##    10 0.4901179 0.9326786  0.9725842
##    11 0.4625913 0.8954996  0.9236346
##    12 0.4350556 0.8560368  0.8854171
##    13 0.4060664 0.8194630  0.8501011
##    14 0.3771119 0.7771653  0.8133320
##    15 0.3681223 0.7342353  0.7660262
##    16 0.3577127 0.6821924  0.7252751
## 
## $NfactorsPA
## [1] 3
#

#plotting the parallel test

plot <- RAWPAR_output$eigenvalues %>%
  data.frame()  %>%
  rename("Component.Number" = "Root",
         "Eigenvalue.Data" = "Real.Data",
         "Random.Mean" = "Mean",
         "Random.95" = "Percentile")

# Pivot longer the data so that it can be plotted in ggplot:
plot_long <- plot %>%
  pivot_longer(cols = c(Eigenvalue.Data, Random.Mean, Random.95), 
              names_to = "Group", 
              values_to = "Value")

# Plot the data:
plot_long %>%
 ggplot(mapping = aes(x = Component.Number, y = Value, group = Group, colour = Group) ) +
 geom_line() +
 geom_point() +
 theme_bw() +
 scale_x_continuous(breaks = seq(1, 24, 1)) +
 scale_y_continuous(breaks = seq(1, 7, 1)) +
 labs(
   x = "Component Number", 
   y = "Eigenvalue Size"
   )

MAP(data_no)
## 
## 
## MINIMUM AVERAGE PARTIAL (MAP) TEST
## 
## Number of cases = 385
## 
## Number of variables = 16
## 
## Specified kind of correlations for this analysis: Pearson
## 
## 
## Total Variance Explained (Initial Eigenvalues):
##              Eigenvalues    Proportion of Variance    Cumulative Prop. Variance
## Factor 1            4.74                      0.30                         0.30
## Factor 2            2.36                      0.15                         0.44
## Factor 3            1.74                      0.11                         0.55
## Factor 4            1.21                      0.08                         0.63
## Factor 5            0.73                      0.05                         0.67
## Factor 6            0.65                      0.04                         0.71
## Factor 7            0.59                      0.04                         0.75
## Factor 8            0.57                      0.04                         0.79
## Factor 9            0.52                      0.03                         0.82
## Factor 10           0.49                      0.03                         0.85
## Factor 11           0.46                      0.03                         0.88
## Factor 12           0.44                      0.03                         0.91
## Factor 13           0.41                      0.03                         0.93
## Factor 14           0.38                      0.02                         0.95
## Factor 15           0.37                      0.02                         0.98
## Factor 16           0.36                      0.02                         1.00
## 
## Velicer's Average Squared Correlations
##    root   Avg.Corr.Sq.   Avg.Corr.power4
##       0        0.08173           0.01656
##       1        0.03179           0.00323
##       2        0.02943           0.00291
##       3        0.02448           0.00254
##       4        0.02578           0.00392
##       5        0.03517           0.00690
##       6        0.04745           0.00962
##       7        0.06193           0.01596
##       8        0.07542           0.02147
##       9        0.09527           0.02966
##      10        0.12703           0.04615
##      11        0.15885           0.06604
##      12        0.21269           0.10616
##      13        0.30422           0.18733
##      14        0.46749           0.34400
##      15        1.00000           1.00000
## 
## The smallest average squared correlation is 0.02448
## 
## The smallest average 4rth power correlation is 0.00254
## 
## The number of components according to the original (1976) MAP Test is = 3
## 
## The number of components according to the revised (2000) MAP Test is = 3

factorability after removal

#Factorability, multicolliniarity and singularity
cortest.bartlett(data_no, n = 385) 
## R was not square, finding R from data
## $chisq
## [1] 2099.966
## 
## $p.value
## [1] 0
## 
## $df
## [1] 120
#acceptable, p<0.01

#sampling - common variance
KMO_results <- KMO(data_no)

KMO_results$MSA %>% 
  round(3)
## [1] 0.854
#overall 0.88 meritorious Kaiser & rice (1974)

EFA no rotation for variance

ml <-
  fa(r = data,
     nfactors = 5,
     rotate = "none",
     fm = "ml")

ml_communalities <-
  data.frame(ml$communality) 

# Reformat for ease of interpretation:
ml_communalities <-
  rename(ml_communalities,'Extraction Communality' = 'ml.communality')

# Put output in a table for visual inspection:
ml_communalities %>% 
  round(3)
ml_loadings <- ml$loadings %>%
  fa.sort() %>%     
  print(cut = 0.3)
## 
## Loadings:
##     ML1    ML2    ML3    ML5    ML4   
## q3   0.698                            
## q18  0.694                            
## q10  0.682                            
## q15  0.639                       0.354
## q27  0.637                            
## q2   0.633                            
## q20  0.606                       0.326
## q19  0.598                            
## q24  0.592  0.346               -0.482
## q26  0.540                            
## q4   0.536                            
## q12 -0.463  0.452  0.393              
## q5   0.435                            
## q25 -0.415               -0.375       
## q7  -0.352  0.325  0.333              
## q30        -0.592  0.390              
## q6  -0.373  0.532                     
## q22         0.482                     
## q17        -0.459  0.308              
## q28 -0.330  0.436  0.379              
## q13        -0.424  0.417              
## q16                                   
## q1         -0.460  0.474              
## q14 -0.390         0.443 -0.413       
## q21 -0.390         0.425              
## q29         0.351  0.387              
## q23        -0.335  0.385              
## q11                0.341              
## q9                 0.314 -0.344       
## q8                        0.324       
## 
##                  ML1   ML2   ML3   ML5   ML4
## SS loadings    5.972 2.714 2.283 1.187 1.066
## Proportion Var 0.199 0.090 0.076 0.040 0.036
## Cumulative Var 0.199 0.290 0.366 0.405 0.441

EFA ML oblique rotation no q10

data_no_q10 <- data %>% 
  select(-q10)

mlr <-
  fa(r = data_no_q10,
     nfactors = 5,
     rotate = "oblimin",
     fm = "ml")

# Extract communalities:
mlr_communalities <-
  data.frame(mlr$communality) 

# Reformat for ease of interpretation:
mlr_communalities <-
  rename(mlr_communalities, 'Extraction Communality' = 'mlr.communality')

# Put output in a table for visual inspection:
mlr_communalities %>% 
  round(3)
mlr_pattern <- mlr$loadings %>%
  fa.sort() %>%     
  print(cut = 0.3)
## 
## Loadings:
##     ML1    ML3    ML2    ML5    ML4   
## q15  0.791                            
## q20  0.704                            
## q18  0.697                            
## q3   0.685                            
## q27  0.666                            
## q2   0.644                            
## q4   0.339                            
## q12         0.737                     
## q28         0.680                     
## q22         0.637                     
## q6          0.621                     
## q29         0.550                     
## q7          0.537                     
## q30                0.755              
## q1                 0.685              
## q13                0.649              
## q17                0.578              
## q23                0.554              
## q11                0.486              
## q14                       0.713       
## q9                        0.586       
## q21                       0.586       
## q25                       0.529       
## q8                       -0.471       
## q16                      -0.449       
## q24                              0.853
## q26                              0.619
## q19                              0.427
## q5                               0.382
## 
##                  ML1   ML3   ML2   ML5   ML4
## SS loadings    3.362 2.624 2.428 2.005 1.596
## Proportion Var 0.116 0.090 0.084 0.069 0.055
## Cumulative Var 0.116 0.206 0.290 0.359 0.414
mlr_factcorr <- mlr$Phi %>%   # Factor correlations are stored in Phi
  as.matrix() %>%      
  print(digits = 3)
##        ML1    ML3     ML2    ML5     ML4
## ML1  1.000 -0.231  0.1237 -0.271  0.4646
## ML3 -0.231  1.000 -0.1947  0.258 -0.0780
## ML2  0.124 -0.195  1.0000  0.115  0.0324
## ML5 -0.271  0.258  0.1149  1.000 -0.2483
## ML4  0.465 -0.078  0.0324 -0.248  1.0000

EFA removal of items no rotation

ml <-
  fa(r = data_no,
     nfactors = 4,
     rotate = "none",
     fm = "ml")

ml_communalities <-
  data.frame(ml$communality) 

# Reformat for ease of interpretation:
ml_communalities <-
  rename(ml_communalities,'Extraction Communality' = 'ml.communality')

# Put output in a table for visual inspection:
ml_communalities %>% 
  round(3)
ml_loadings <- ml$loadings %>%
  fa.sort() %>%     
  print(cut = 0.3)
## 
## Loadings:
##     ML1    ML2    ML3    ML4   
## q3   0.705                     
## q18  0.704                     
## q2   0.658                     
## q27  0.657                     
## q15  0.656                0.337
## q20  0.623                     
## q24  0.616  0.442  0.323 -0.337
## q19  0.614                     
## q26  0.548                     
## q12 -0.425  0.583         0.368
## q6  -0.346  0.553              
## q28         0.521              
## q22         0.505              
## q13                0.573       
## q30        -0.440  0.557       
## q1                 0.548       
## 
##                  ML1   ML2   ML3   ML4
## SS loadings    4.207 1.789 1.253 0.951
## Proportion Var 0.263 0.112 0.078 0.059
## Cumulative Var 0.263 0.375 0.453 0.513

EFA removal of itmes rotation

mlr <-
  fa(r = data_no,
     nfactors = 4,
     rotate = "oblimin",
     fm = "ml")

# Extract communalities:
mlr_communalities <-
  data.frame(mlr$communality) 

# Reformat for ease of interpretation:
mlr_communalities <-
  rename(mlr_communalities, 'Extraction Communality' = 'mlr.communality')

# Put output in a table for visual inspection:
mlr_communalities %>% 
  round(2)
mlr_pattern <- mlr$loadings %>%
  fa.sort() %>%     
  print(cut = .3)
## 
## Loadings:
##     ML1    ML2    ML3    ML4   
## q15  0.817                     
## q18  0.729                     
## q3   0.703                     
## q20  0.689                     
## q27  0.671                     
## q2   0.661                     
## q12         0.830              
## q28         0.679              
## q6          0.610              
## q22         0.561              
## q30                0.742       
## q13                0.678       
## q1                 0.664       
## q24                       0.905
## q26                       0.592
## q19                       0.394
## 
##                  ML1   ML2   ML3   ML4
## SS loadings    3.151 1.891 1.524 1.361
## Proportion Var 0.197 0.118 0.095 0.085
## Cumulative Var 0.197 0.315 0.410 0.495
mlr_factcorr <- mlr$Phi %>%   # Factor correlations are stored in Phi
  as.matrix() %>%      
  print(digits = 3)
##         ML1     ML2     ML3     ML4
## ML1  1.0000 -0.3173  0.0599  0.4808
## ML2 -0.3173  1.0000 -0.1787 -0.0967
## ML3  0.0599 -0.1787  1.0000  0.0152
## ML4  0.4808 -0.0967  0.0152  1.0000

CFA first round no .4s ML unstandardised

cfa_model <- "
   PositiveImpulsivity =~ q15 + q20 + q18 + q3 + q27 + q2
   SensationSeeking =~ q30 + q1 + q13
   Forethought =~ q12 + q28 + q22 + q6
   NegativeImpulsivity =~ q24 + q26 + q19"

fit_cor <- cfa(model = cfa_model, 
               data = data, 
               estimator = "ML",
               likelihood = "wishart", 
               orthogonal = FALSE)

semPaths(object = fit_cor,
         whatLabels = "par",
         nCharNodes = 0,
         exoVar = TRUE,
         optimizeLatRes = TRUE,
         layout = "circle",
         rotation = 1, 
         edge.color = "black",
         color = "pink", 
         sizeLat = 7,
         sizeLat2 = 4,
         sizeMan = 4, 
         sizeMan2 = 2.5,
         edge.label.cex = 0.5,
         edge.label.position = 0.4
         )

CFA first round no .4s ML standardised

semPaths(object = fit_cor,
         whatLabels = "std",
         nCharNodes = 0,
         exoVar = FALSE,
         optimizeLatRes = TRUE,
         layout = "circle",
         rotation = 1, 
         edge.color = "black",
         color = "pink", 
         sizeLat = 7,
         sizeLat2 = 4,
         sizeMan = 4, 
         sizeMan2 = 2.5,
         edge.label.cex = 0.5,
         edge.label.position = 0.4
         )

summary(fit_cor, standardized = TRUE, ci= TRUE, header= FALSE)
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                          Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   PositiveImpulsivity =~                                                      
##     q15                     1.000                               1.000    1.000
##     q20                     1.037    0.082   12.663    0.000    0.877    1.198
##     q18                     1.096    0.078   14.054    0.000    0.943    1.249
##     q3                      1.164    0.084   13.818    0.000    0.998    1.329
##     q27                     0.945    0.073   12.858    0.000    0.801    1.089
##     q2                      1.045    0.080   12.999    0.000    0.887    1.202
##   SensationSeeking =~                                                         
##     q30                     1.000                               1.000    1.000
##     q1                      0.674    0.074    9.135    0.000    0.529    0.818
##     q13                     0.753    0.082    9.154    0.000    0.592    0.914
##   Forethought =~                                                              
##     q12                     1.000                               1.000    1.000
##     q28                     0.969    0.087   11.187    0.000    0.799    1.139
##     q22                     0.751    0.076    9.851    0.000    0.601    0.900
##     q6                      0.874    0.077   11.320    0.000    0.722    1.025
##   NegativeImpulsivity =~                                                      
##     q24                     1.000                               1.000    1.000
##     q26                     0.867    0.082   10.544    0.000    0.706    1.028
##     q19                     0.762    0.075   10.183    0.000    0.615    0.909
##    Std.lv  Std.all
##                   
##     0.657    0.733
##     0.681    0.684
##     0.720    0.760
##     0.764    0.747
##     0.620    0.695
##     0.686    0.702
##                   
##     1.028    0.754
##     0.692    0.656
##     0.774    0.663
##                   
##     0.797    0.807
##     0.772    0.657
##     0.598    0.568
##     0.696    0.668
##                   
##     0.900    0.750
##     0.780    0.684
##     0.686    0.645
## 
## Covariances:
##                          Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   PositiveImpulsivity ~~                                                      
##     SensationSekng          0.047    0.043    1.079    0.280   -0.038    0.131
##     Forethought            -0.176    0.035   -5.021    0.000   -0.244   -0.107
##     NegatvImplsvty          0.371    0.049    7.626    0.000    0.275    0.466
##   SensationSeeking ~~                                                         
##     Forethought            -0.177    0.056   -3.152    0.002   -0.288   -0.067
##     NegatvImplsvty          0.027    0.064    0.420    0.675   -0.098    0.152
##   Forethought ~~                                                              
##     NegatvImplsvty         -0.147    0.049   -3.006    0.003   -0.243   -0.051
##    Std.lv  Std.all
##                   
##     0.069    0.069
##    -0.335   -0.335
##     0.627    0.627
##                   
##    -0.217   -0.217
##     0.029    0.029
##                   
##    -0.205   -0.205
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .q15               0.372    0.032   11.556    0.000    0.309    0.435
##    .q20               0.527    0.044   12.115    0.000    0.442    0.613
##    .q18               0.379    0.034   11.137    0.000    0.312    0.446
##    .q3                0.463    0.041   11.349    0.000    0.383    0.543
##    .q27               0.413    0.034   12.010    0.000    0.345    0.480
##    .q2                0.484    0.041   11.928    0.000    0.404    0.563
##    .q30               0.803    0.116    6.924    0.000    0.576    1.030
##    .q1                0.635    0.065    9.785    0.000    0.508    0.763
##    .q13               0.762    0.079    9.586    0.000    0.606    0.918
##    .q12               0.339    0.048    7.117    0.000    0.246    0.432
##    .q28               0.784    0.071   11.038    0.000    0.645    0.923
##    .q22               0.751    0.062   12.149    0.000    0.630    0.872
##    .q6                0.603    0.056   10.859    0.000    0.494    0.712
##    .q24               0.631    0.076    8.292    0.000    0.482    0.780
##    .q26               0.692    0.069   10.004    0.000    0.557    0.828
##    .q19               0.661    0.061   10.784    0.000    0.541    0.781
##     PositvImplsvty    0.431    0.054    7.930    0.000    0.325    0.538
##     SensationSekng    1.056    0.157    6.716    0.000    0.748    1.364
##     Forethought       0.635    0.078    8.189    0.000    0.483    0.787
##     NegatvImplsvty    0.811    0.112    7.259    0.000    0.592    1.029
##    Std.lv  Std.all
##     0.372    0.463
##     0.527    0.532
##     0.379    0.422
##     0.463    0.442
##     0.413    0.518
##     0.484    0.507
##     0.803    0.432
##     0.635    0.570
##     0.762    0.560
##     0.339    0.348
##     0.784    0.568
##     0.751    0.677
##     0.603    0.554
##     0.631    0.438
##     0.692    0.532
##     0.661    0.584
##     1.000    1.000
##     1.000    1.000
##     1.000    1.000
##     1.000    1.000
lavInspect(fit_cor, "rsquare") %>% 
  round(3)
##   q15   q20   q18    q3   q27    q2   q30    q1   q13   q12   q28   q22    q6 
## 0.537 0.468 0.578 0.558 0.482 0.493 0.568 0.430 0.440 0.652 0.432 0.323 0.446 
##   q24   q26   q19 
## 0.562 0.468 0.416

CFA first roun no .4s model identification

show(fit_cor)
## lavaan 0.6-19 ended normally after 33 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        38
## 
##   Number of observations                           385
## 
## Model Test User Model:
##                                                       
##   Test statistic                               185.830
##   Degrees of freedom                                98
##   P-value (Chi-square)                           0.000
fitmeasures(fit_cor, c("chisq", "df", "pvalue", "cfi", "srmr", "rmsea"))
##   chisq      df  pvalue     cfi    srmr   rmsea 
## 185.830  98.000   0.000   0.956   0.055   0.048

CFA second round no .4s

cfa_model_respe <- "
   PositiveImpulsivity =~ q15 + q20 + q18 + q3 + q27 + q2 + q19
   SensationSeeking =~ q30 + q1 + q13
   Forethought =~ q12 + q28 + q22 + q6 + q19 + q24
   NegativeImpulsivity =~ q24 + q26 + q19"

fit_cor_respe <- cfa(model = cfa_model_respe, 
               data = data, 
               estimator = "ML",
               likelihood = "wishart", 
               orthogonal = FALSE)

semPaths(object = fit_cor_respe,
         whatLabels = "std",
         nCharNodes = 0,
         exoVar = FALSE,
         optimizeLatRes = TRUE,
         layout = "circle",
         rotation = 1, 
         edge.color = "black",
         color = "pink", 
         sizeLat = 7,
         sizeLat2 = 4,
         sizeMan = 4, 
         sizeMan2 = 2.5,
         edge.label.cex = 0.5,
         edge.label.position = 0.4
         )

summary(fit_cor_respe, standardized = TRUE, ci= TRUE, header= FALSE)
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                          Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   PositiveImpulsivity =~                                                      
##     q15                     1.000                               1.000    1.000
##     q20                     1.032    0.081   12.705    0.000    0.873    1.191
##     q18                     1.090    0.077   14.103    0.000    0.938    1.241
##     q3                      1.158    0.083   13.875    0.000    0.994    1.321
##     q27                     0.943    0.073   12.952    0.000    0.801    1.086
##     q2                      1.037    0.080   13.022    0.000    0.881    1.193
##     q19                     0.418    0.102    4.091    0.000    0.218    0.619
##   SensationSeeking =~                                                         
##     q30                     1.000                               1.000    1.000
##     q1                      0.673    0.074    9.129    0.000    0.528    0.817
##     q13                     0.752    0.082    9.148    0.000    0.591    0.913
##   Forethought =~                                                              
##     q12                     1.000                               1.000    1.000
##     q28                     0.973    0.086   11.362    0.000    0.805    1.140
##     q22                     0.744    0.075    9.860    0.000    0.596    0.891
##     q6                      0.866    0.076   11.395    0.000    0.717    1.016
##     q19                    -0.108    0.074   -1.456    0.145   -0.254    0.037
##     q24                     0.259    0.103    2.520    0.012    0.058    0.461
##   NegativeImpulsivity =~                                                      
##     q24                     1.000                               1.000    1.000
##     q26                     0.740    0.080    9.213    0.000    0.583    0.898
##     q19                     0.432    0.074    5.874    0.000    0.288    0.576
##    Std.lv  Std.all
##                   
##     0.659    0.736
##     0.680    0.683
##     0.718    0.759
##     0.763    0.746
##     0.622    0.697
##     0.684    0.700
##     0.276    0.259
##                   
##     1.028    0.754
##     0.692    0.655
##     0.774    0.663
##                   
##     0.799    0.810
##     0.777    0.661
##     0.594    0.564
##     0.692    0.664
##    -0.086   -0.081
##     0.207    0.173
##                   
##     1.046    0.871
##     0.774    0.679
##     0.452    0.425
## 
## Covariances:
##                          Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   PositiveImpulsivity ~~                                                      
##     SensationSekng          0.049    0.043    1.137    0.255   -0.036    0.134
##     Forethought            -0.178    0.035   -5.053    0.000   -0.247   -0.109
##     NegatvImplsvty          0.381    0.054    7.019    0.000    0.275    0.487
##   SensationSeeking ~~                                                         
##     Forethought            -0.176    0.056   -3.119    0.002   -0.286   -0.065
##     NegatvImplsvty          0.043    0.073    0.584    0.559   -0.101    0.186
##   Forethought ~~                                                              
##     NegatvImplsvty         -0.206    0.076   -2.705    0.007   -0.356   -0.057
##    Std.lv  Std.all
##                   
##     0.073    0.073
##    -0.337   -0.337
##     0.552    0.552
##                   
##    -0.214   -0.214
##     0.040    0.040
##                   
##    -0.247   -0.247
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .q15               0.369    0.032   11.529    0.000    0.306    0.431
##    .q20               0.528    0.044   12.133    0.000    0.443    0.614
##    .q18               0.381    0.034   11.180    0.000    0.314    0.448
##    .q3                0.464    0.041   11.377    0.000    0.384    0.544
##    .q27               0.410    0.034   12.002    0.000    0.343    0.478
##    .q2                0.486    0.041   11.962    0.000    0.407    0.566
##    .q19               0.671    0.055   12.251    0.000    0.564    0.779
##    .q30               0.801    0.116    6.902    0.000    0.574    1.029
##    .q1                0.636    0.065    9.792    0.000    0.509    0.763
##    .q13               0.762    0.079    9.589    0.000    0.606    0.918
##    .q12               0.336    0.047    7.171    0.000    0.244    0.427
##    .q28               0.776    0.070   11.035    0.000    0.638    0.914
##    .q22               0.756    0.062   12.223    0.000    0.635    0.878
##    .q6                0.608    0.055   10.993    0.000    0.500    0.717
##    .q24               0.411    0.101    4.081    0.000    0.214    0.609
##    .q26               0.702    0.072    9.691    0.000    0.560    0.844
##     PositvImplsvty    0.435    0.054    7.980    0.000    0.328    0.542
##     SensationSekng    1.058    0.157    6.719    0.000    0.749    1.366
##     Forethought       0.638    0.077    8.269    0.000    0.487    0.789
##     NegatvImplsvty    1.095    0.157    6.985    0.000    0.787    1.402
##    Std.lv  Std.all
##     0.369    0.459
##     0.528    0.533
##     0.381    0.425
##     0.464    0.443
##     0.410    0.515
##     0.486    0.510
##     0.671    0.593
##     0.801    0.431
##     0.636    0.570
##     0.762    0.560
##     0.336    0.345
##     0.776    0.563
##     0.756    0.682
##     0.608    0.559
##     0.411    0.285
##     0.702    0.539
##     1.000    1.000
##     1.000    1.000
##     1.000    1.000
##     1.000    1.000
lavInspect(fit_cor, "rsquare") %>% 
  round(3)
##   q15   q20   q18    q3   q27    q2   q30    q1   q13   q12   q28   q22    q6 
## 0.537 0.468 0.578 0.558 0.482 0.493 0.568 0.430 0.440 0.652 0.432 0.323 0.446 
##   q24   q26   q19 
## 0.562 0.468 0.416
show(fit_cor_respe)
## lavaan 0.6-19 ended normally after 36 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        41
## 
##   Number of observations                           385
## 
## Model Test User Model:
##                                                       
##   Test statistic                               146.963
##   Degrees of freedom                                95
##   P-value (Chi-square)                           0.001
fitmeasures(fit_cor_respe, c("chisq", "df", "pvalue", "cfi", "srmr", "rmsea"))
##   chisq      df  pvalue     cfi    srmr   rmsea 
## 146.963  95.000   0.001   0.974   0.046   0.038

CFA local test stats

resid(fit_cor, type = "normalized")
## $type
## [1] "normalized"
## 
## $cov
##        q15    q20    q18     q3    q27     q2    q30     q1    q13    q12
## q15  0.000                                                               
## q20  0.194  0.000                                                        
## q18 -0.068 -0.400  0.000                                                 
## q3   0.326  0.265  0.288  0.000                                          
## q27  0.392 -0.077  0.074 -0.945  0.000                                   
## q2  -0.177  0.205 -0.060 -0.430  0.399  0.000                            
## q30 -1.186 -0.754 -1.247 -0.233  0.805 -0.479  0.000                     
## q1   1.152 -1.125  1.485  2.089  2.619  1.294 -0.109  0.000              
## q13 -0.873 -1.408 -0.606 -0.277  0.302  0.111  0.031  0.115  0.000       
## q12  1.090 -0.297 -0.324 -1.405 -0.212 -0.567  0.731  0.825  1.791  0.000
## q28  1.000 -0.006  0.762 -0.700  0.394  1.146  0.333  0.433  2.106  0.362
## q22  2.657 -0.101  0.386  0.141  0.503  1.065 -1.498 -1.733 -0.512 -0.265
## q6   0.923 -1.172  0.390 -0.928 -1.606 -0.106 -2.293 -1.815 -1.592 -0.102
## q24 -1.445 -1.343 -0.545 -0.922 -0.571 -0.267 -1.629  1.891  0.359  1.017
## q26 -1.367 -0.420  0.073  0.063 -0.339  0.503 -2.389  0.450 -0.290 -1.165
## q19  1.649  1.046  1.450  1.630  2.154  1.337  1.113  1.963  0.698 -2.807
##        q28    q22     q6    q24    q26    q19
## q15                                          
## q20                                          
## q18                                          
## q3                                           
## q27                                          
## q2                                           
## q30                                          
## q1                                           
## q13                                          
## q12                                          
## q28  0.000                                   
## q22  0.211  0.000                            
## q6  -0.562  0.371  0.000                     
## q24  2.375  2.225  1.343  0.000              
## q26  0.814  0.593 -0.774  0.846  0.000       
## q19 -2.214  0.135 -1.238 -0.150 -1.202  0.000
resid(fit_cor_respe, type = "normalized")
## $type
## [1] "normalized"
## 
## $cov
##        q15    q20    q18     q3    q27     q2    q19    q30     q1    q13
## q15  0.000                                                               
## q20  0.166  0.000                                                        
## q18 -0.090 -0.373  0.000                                                 
## q3   0.296  0.283  0.316  0.000                                          
## q27  0.331 -0.093  0.066 -0.962  0.000                                   
## q2  -0.189  0.237 -0.017 -0.395  0.399  0.000                            
## q19  0.053 -0.436 -0.162  0.043  0.657 -0.161  0.000                     
## q30 -1.230 -0.791 -1.287 -0.273  0.765 -0.516  0.604  0.000              
## q1   1.115 -1.156  1.451  2.055  2.586  1.263  1.524 -0.110  0.000       
## q13 -0.911 -1.439 -0.640 -0.312  0.268  0.080  0.251  0.028  0.122  0.000
## q12  1.136 -0.273 -0.301 -1.379 -0.174 -0.550 -0.630  0.704  0.799  1.765
## q28  1.049  0.025  0.794 -0.666  0.437  1.172 -0.409  0.319  0.418  2.092
## q22  2.663 -0.109  0.375  0.133  0.505  1.052  1.682 -1.533 -1.766 -0.545
## q6   0.935 -1.176  0.382 -0.933 -1.599 -0.116  0.569 -2.332 -1.851 -1.628
## q24 -0.814 -0.723  0.135 -0.254  0.030  0.369  0.175 -1.276  2.197  0.671
## q26 -0.632  0.287  0.850  0.824  0.358  1.226 -0.429 -2.496  0.358 -0.384
##        q12    q28    q22     q6    q24    q26
## q15                                          
## q20                                          
## q18                                          
## q3                                           
## q27                                          
## q2                                           
## q19                                          
## q30                                          
## q1                                           
## q13                                          
## q12  0.000                                   
## q28  0.279  0.000                            
## q22 -0.228  0.216  0.000                     
## q6  -0.075 -0.569  0.458  0.000              
## q24 -0.743  0.941  0.979 -0.119  0.000       
## q26 -0.736  1.177  0.881 -0.434 -0.003  0.000

CFA MI

modindices(fit_cor, 
           sort = TRUE,         # Sorts modification indices in descending order of MI
           minimum.value = 5)  # Requests modification indices above a certain number (e.g., 10) though the choice of cutoff is fairly arbitrary

CFA correlation matrix

lower <- cor(data) %>% 
  as.matrix() %>% 
  round(2)

lower[upper.tri(lower)] <- ""
lower <- as.data.frame(lower)

lower

CFA multiple r squared

lavInspect(fit_cor, "rsquare") %>% 
  round(3)
##   q15   q20   q18    q3   q27    q2   q30    q1   q13   q12   q28   q22    q6 
## 0.537 0.468 0.578 0.558 0.482 0.493 0.568 0.430 0.440 0.652 0.432 0.323 0.446 
##   q24   q26   q19 
## 0.562 0.468 0.416