1 Preparing Data

1.1 Load Libraries

## Necessary Libraries loaded.

1.2 Load Data for Organisation with 26 Ratees and 287 Raters

## Stacked data with 78 Raters including IWB loaded.

1.3 Unstack and Clean Data

## Data unstacked and prepared for Analysis. Blank cells have been filled with Column Mean.

1.4 Eliminate Items

# Making New Data Set 
ReduceBy <- c("SN06", "SN19", "SN29")
ItemsToCut <- paste(ReduceBy, collapse = ", ")
cat("Dataset reduced by items", ItemsToCut, "due to low factor loading or cross loading. \nAll behaviours stay represented.")
## Dataset reduced by items SN06, SN19, SN29 due to low factor loading or cross loading. 
## All behaviours stay represented.
# Keep full data set
dfValFull   <- dfVal
  
# Reduce data sets
dfUnstack   <- select(dfUnstack,   -c(all_of(ReduceBy)))
dfVal       <- select(dfVal,       -c(all_of(ReduceBy)))
dfValNoIWB  <- select(dfValNoIWB,  -c(all_of(ReduceBy)))

# Delete support variables
rm(ItemsToCut, ReduceBy)

# Write
setwd("~/AB PRIVATE/01 Amy/AB Amy PhD/Part 3/Data/Study3")
write.csv(dfUnstack, file = paste(today, "UnStackedData3reduced.csv"))

1.5 Make Factor and Behaviour Variables

## Behaviour and Factor Data generated out of Item Means.

2 Studying Data

2.1 Displaying Descriptive Stats

Kurtosis and Skewness are used as indication of presence of normality in the data. If the data are normal Kurtosis and Skewness are within -2 and +2. The closer the 0 the better.

# Loading necessary packages
if(! "vtable" %in% installed.packages()) { install.packages("vtable", dependencies = TRUE) }
library(vtable)
if(! "moments" %in% installed.packages()) { install.packages("moments", dependencies = TRUE) }
library(moments)

ST <- as.data.frame(sumtable(dfVal[c(01:31)], out = 'return', title='Summary Statistics by Item', digits = 3, fixed.digits = TRUE,
   summ = list(
     c('notNA(x)','mean(x)','sd(x)','min(x)', 'pctile(x)[25]', 'median(x)', 'pctile(x)[75]', 'max(x)', 'kurtosis(x)', 'skewness(x)')
   ),
   summ.names = list(
     c('N','Mean','SD','Min', '25%', 'Median', '75%', 'Max', 'Kurtosis', 'Skewness')
   )
))

formattable(ST, caption = "Summary Statistics by Item - ILS", align = c("l", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c"), list(
  Mean = color_tile("pink", "green"),
  Cosigned = formatter("span",
       style = x ~ style(
       "border-radius" = "4px",
       "padding-right" = "4px",
       "background-color" = sapply(x,bg.picker)),
       x ~ sprintf("%.2f (rank: %02d)", x, rank(-x)))
))
Summary Statistics by Item - ILS
Variable N Mean SD Min 25% Median 75% Max Kurtosis Skewness
SN01 76 6.054 1.057 2 6.000 6 7.000 7 5.902 -1.610
SN02 76 5.724 1.173 2 5.000 6 7.000 7 4.069 -1.047
SN03 76 5.849 1.041 2 5.000 6 7.000 7 4.214 -1.045
SN04 76 5.893 1.173 2 5.670 6 7.000 7 5.701 -1.539
SN05 76 5.986 1.064 2 6.000 6 7.000 7 6.490 -1.641
SN07 76 5.901 1.121 2 5.901 6 7.000 7 4.329 -1.228
SN08 76 5.806 1.041 2 5.000 6 6.250 7 4.846 -1.167
SN09 76 5.877 1.006 2 5.000 6 7.000 7 6.841 -1.487
SN10 76 5.740 1.096 2 5.000 6 6.000 7 4.312 -1.116
SN11 76 5.736 1.020 2 5.000 6 6.000 7 4.935 -1.189
SN12 76 6.013 1.039 2 6.000 6 7.000 7 5.320 -1.390
SN13 76 6.040 1.012 2 6.000 6 7.000 7 6.487 -1.632
SN14 76 6.408 0.751 4 6.000 7 7.000 7 4.092 -1.201
SN15 76 6.013 0.973 2 6.000 6 7.000 7 5.482 -1.251
SN16 76 6.184 0.934 2 6.000 6 7.000 7 6.896 -1.559
SN17 76 6.133 1.062 2 6.000 6 7.000 7 5.379 -1.478
SN18 76 5.867 1.215 2 5.000 6 7.000 7 4.380 -1.270
SN20 76 5.961 1.101 2 6.000 6 7.000 7 4.726 -1.310
SN21 76 5.946 0.992 2 6.000 6 7.000 7 5.888 -1.458
SN22 76 5.886 1.027 2 5.886 6 6.250 7 5.632 -1.472
SN23 76 6.184 0.976 2 6.000 6 7.000 7 6.383 -1.588
SN24 76 5.889 1.090 2 5.889 6 7.000 7 4.643 -1.266
SN25 76 6.027 1.107 1 6.000 6 7.000 7 7.578 -1.774
SN26 76 6.108 1.053 2 6.000 6 7.000 7 6.007 -1.599
SN27 76 5.920 1.105 2 6.000 6 7.000 7 5.462 -1.573
SN28 76 5.959 1.064 2 5.000 6 7.000 7 4.513 -1.122
SN30 76 6.243 0.921 2 6.000 6 7.000 7 7.994 -1.847
SN31 76 6.147 1.029 2 6.000 6 7.000 7 6.129 -1.629
SN32 76 5.931 1.181 2 5.931 6 7.000 7 5.105 -1.475
SN33 76 6.054 1.106 2 6.000 6 7.000 7 5.111 -1.476
SN34 76 6.027 1.019 2 6.000 6 7.000 7 5.624 -1.422
ST <- as.data.frame(sumtable(dfVal[c(32:40)], out = 'return', title='Summary Statistics by Item', digits = 3, fixed.digits = TRUE,
   summ = list(
     c('notNA(x)','mean(x)','sd(x)','min(x)', 'pctile(x)[25]', 'median(x)', 'pctile(x)[75]', 'max(x)', 'kurtosis(x)', 'skewness(x)')
   ),
   summ.names = list(
     c('N','Mean','SD','Min', '25%', 'Median', '75%', 'Max', 'Kurtosis', 'Skewness')
   )
))

formattable(ST, caption = "Summary Statistics by Item - IWB", align = c("l", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c"), list(
  Mean = color_tile("pink", "green"),
  Cosigned = formatter("span",
       style = x ~ style(
       "border-radius" = "4px",
       "padding-right" = "4px",
       "background-color" = sapply(x,bg.picker)),
       x ~ sprintf("%.2f (rank: %02d)", x, rank(-x)))
))
Summary Statistics by Item - IWB
Variable N Mean SD Min 25% Median 75% Max Kurtosis Skewness
IWB01 76 5.421 1.086 2 5 6 6.000 7 4.224 -0.958
IWB02 76 5.421 1.099 2 5 5 6.000 7 3.925 -0.709
IWB03 76 5.513 1.113 3 5 6 6.000 7 2.314 -0.296
IWB04 76 4.592 0.955 2 4 5 5.000 6 2.565 -0.312
IWB05 76 4.855 1.029 2 4 5 6.000 7 3.309 -0.521
IWB06 76 4.303 1.132 1 4 4 5.000 6 2.967 -0.447
IWB07 76 4.816 1.092 2 4 5 6.000 7 2.645 -0.496
IWB08 76 4.763 1.094 1 4 5 5.250 7 4.189 -0.689
IWB09 76 4.697 1.108 1 4 5 5.000 7 3.852 -0.803
ST <- as.data.frame(sumtable(dfBeh[c(01:11)], out = 'return', title='Summary Statistics by Behaviour', digits = 3, fixed.digits = TRUE,
   summ = list(
     c('notNA(x)','mean(x)','sd(x)','min(x)', 'pctile(x)[25]', 'median(x)', 'pctile(x)[75]', 'max(x)', 'kurtosis(x)', 'skewness(x)')
   ),
   summ.names = list(
     c('N','Mean','SD','Min', '25%', 'Median', '75%', 'Max', 'Kurtosis', 'Skewness')
   )
))

formattable(ST, caption = "Summary Statistics by Behaviour - ILS", align = c("l", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c"), list(
  Mean = color_tile("pink", "green"),
  Cosigned = formatter("span",
       style = x ~ style(
       "border-radius" = "4px",
       "padding-right" = "4px",
       "background-color" = sapply(x,bg.picker)),
       x ~ sprintf("%.2f (rank: %02d)", x, rank(-x)))
))
Summary Statistics by Behaviour - ILS
Variable N Mean SD Min 25% Median 75% Max Kurtosis Skewness
B01 76 5.889 1.057 2.000 5.500 6.000 6.500 7 5.149 -1.417
B02 76 5.910 1.001 2.000 5.658 6.000 6.667 7 5.737 -1.427
B03 76 5.861 0.973 2.000 5.594 6.000 6.417 7 6.096 -1.458
B04 76 5.830 0.973 2.000 5.583 6.000 6.333 7 5.866 -1.475
B05 76 6.202 0.768 3.667 6.000 6.333 7.000 7 4.290 -1.130
B06 76 6.013 1.007 2.000 5.667 6.000 7.000 7 5.549 -1.436
B07 76 5.994 0.929 2.000 5.750 6.125 6.562 7 6.790 -1.698
B08 76 6.008 0.983 1.667 5.667 6.333 6.667 7 7.183 -1.742
B09 76 5.940 1.036 2.000 5.500 6.000 7.000 7 5.216 -1.360
B10 76 6.195 0.937 2.000 6.000 6.122 7.000 7 7.772 -1.886
B11 76 6.004 1.007 2.000 5.667 6.000 7.000 7 5.905 -1.537
ST <- as.data.frame(sumtable(dfFac, out = 'return', title='Summary Statistics by Factor', digits = 3, fixed.digits = TRUE,
   summ = list(
     c('notNA(x)','mean(x)','sd(x)','min(x)', 'pctile(x)[25]', 'median(x)', 'pctile(x)[75]', 'max(x)', 'kurtosis(x)', 'skewness(x)')
   ),
   summ.names = list(
     c('N','Mean','SD','Min', '25%', 'Median', '75%', 'Max', 'Kurtosis', 'Skewness')
   )
))

formattable(ST, caption = "Summary Statistics by Factor - ILS and IWB", align = c("l", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c"), list(
  Mean = color_tile("pink", "green"),
  Cosigned = formatter("span",
       style = x ~ style(
       "border-radius" = "4px",
       "padding-right" = "4px",
       "background-color" = sapply(x,bg.picker)),
       x ~ sprintf("%.2f (rank: %02d)", x, rank(-x)))
))
Summary Statistics by Factor - ILS and IWB
Variable N Mean SD Min 25% Median 75% Max Kurtosis Skewness
Head 76 5.871 0.954 2.000 5.611 6.000 6.477 7.000 6.364 -1.541
Heart 76 6.108 0.841 2.833 5.792 6.167 6.833 7.000 5.610 -1.405
Hand 76 6.020 0.935 1.929 5.768 6.078 6.714 7.000 7.280 -1.784
IWB 76 4.931 0.864 1.889 4.556 5.000 5.667 6.222 4.256 -1.048
ST <- as.data.frame(sumtable(dfFac[c(01:03)], out = 'return', title='Summary Statistics by Factor', digits = 3, fixed.digits = TRUE,
   summ = list(
     c('notNA(x)','mean(x)','sd(x)','min(x)', 'pctile(x)[25]', 'median(x)', 'pctile(x)[75]', 'max(x)', 'kurtosis(x)', 'skewness(x)')
   ),
   summ.names = list(
     c('N','Mean','SD','Min', '25%', 'Median', '75%', 'Max', 'Kurtosis', 'Skewness')
   )
))

formattable(ST, caption = "Summary Statistics by Factor - ILS", align = c("l", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c"), list(
  Mean = color_tile("pink", "green"),
  Cosigned = formatter("span",
       style = x ~ style(
       "border-radius" = "4px",
       "padding-right" = "4px",
       "background-color" = sapply(x,bg.picker)),
       x ~ sprintf("%.2f (rank: %02d)", x, rank(-x)))
))
Summary Statistics by Factor - ILS
Variable N Mean SD Min 25% Median 75% Max Kurtosis Skewness
Head 76 5.871 0.954 2.000 5.611 6.000 6.477 7 6.364 -1.541
Heart 76 6.108 0.841 2.833 5.792 6.167 6.833 7 5.610 -1.405
Hand 76 6.020 0.935 1.929 5.768 6.078 6.714 7 7.280 -1.784

2.2 Calculate Cronbach’s Alpha

Cronbach’s Alpha is an indicator for scale reliability. Raw alpha is sensitive to differences in the item variances. Standardized alpha is based upon the correlations rather than the covariances. Standardized alpha is based on the assumption that all of the items have equal variances, which is often false in practice. We use raw alpha to evaluate the scales. A level of 0.7 and above is acceptable, whereas 0.8 should be achieved in research. When making important data driven decisions, 0.9 marks a minimum. If Guttman’s Lambda 6 (G6) is higher than Alpha, factor shows unequal item loadings.

# Loading necessary packages
if(! "psych" %in% installed.packages()) { install.packages("psych", dependencies = TRUE) }
library(psych)

# Cronbach's Alpha
cAlpha  <- psych::alpha(x = dfValFull[c(1,2)])
alphaDT <- data.table(variable = "Envision Change", id = "B01", cAlpha$total)
cAlpha  <- psych::alpha(x = dfValFull[c(3,4,5)])
alphaDT <- rbind(alphaDT, data.table(variable = "Promote Change", id = "B02", cAlpha$total))
cAlpha  <- psych::alpha(x = dfValFull[c(7,8,9)])
alphaDT <- rbind(alphaDT, data.table(variable = "Manage Change", id = "B03", cAlpha$total))
cAlpha  <- psych::alpha(x = dfValFull[c(10,11,12)])
alphaDT <- rbind(alphaDT, data.table(variable = "Drive Innovation", id = "B04", cAlpha$total))
cAlpha  <- psych::alpha(x = dfValFull[c(14,15,16)])
alphaDT <- rbind(alphaDT, data.table(variable = "Build Relationship", id = "B05", cAlpha$total))
cAlpha  <- psych::alpha(x = dfValFull[c(13,17,18)])
alphaDT <- rbind(alphaDT, data.table(variable = "Support Others", id = "B06", cAlpha$total))
cAlpha  <- psych::alpha(x = dfValFull[c(20,21,22,23)])
alphaDT <- rbind(alphaDT, data.table(variable = "Make Decision", id = "B07", cAlpha$total))
cAlpha  <- psych::alpha(x = dfValFull[c(24,25,26)])
alphaDT <- rbind(alphaDT, data.table(variable = "Make Things Happen", id = "B08", cAlpha$total))
cAlpha  <- psych::alpha(x = dfValFull[c(27,28)])
alphaDT <- rbind(alphaDT, data.table(variable = "Solve Problems Creatively", id = "B09", cAlpha$total))
cAlpha  <- psych::alpha(x = dfValFull[c(30,31)])
alphaDT <- rbind(alphaDT, data.table(variable = "Take Responsibility", id = "B10", cAlpha$total))
cAlpha  <- psych::alpha(x = dfValFull[c(32,33,34)])
alphaDT <- rbind(alphaDT, data.table(variable = "Demonstrate Team Leadership", id = "B11", cAlpha$total))
cAlpha  <- psych::alpha(x = dfValFull[c(01:05,07:12)])
alphaDT <- rbind(alphaDT, data.table(variable = "Head", id = "Hed", cAlpha$total))
cAlpha  <- psych::alpha(x = dfValFull[c(13:18)])
alphaDT <- rbind(alphaDT, data.table(variable = "Heart", id = "Hrt", cAlpha$total))
cAlpha  <- psych::alpha(x = dfValFull[c(20:28,30:34)])
alphaDT <- rbind(alphaDT, data.table(variable = "Hand", id = "Hnd", cAlpha$total))
cAlpha  <- psych::alpha(x = dfVal)
alphaDT <- rbind(alphaDT, data.table(variable = "ILS", id = "ILS", cAlpha$total))
cAlpha  <- psych::alpha(x = dfValFull[c(35:43)])
alphaDT <- rbind(alphaDT, data.table(variable = "Innovative Work Behaviour", id = "IWB", cAlpha$total))

alphaDT$LCL       <- alphaDT$raw_alpha - 2 * alphaDT$ase
alphaDT$UCL       <- alphaDT$raw_alpha + 2 * alphaDT$ase
# alphaDT$StdAlpha   <- alphaDT$std.alpha

# Remove columns
alphaDT <- alphaDT[,-c("S/N", "std.alpha", "average_r", "median_r", "ase")]

# Rename columns
setnames(alphaDT, "variable", "Variable")
setnames(alphaDT, "id", "ID")
setnames(alphaDT, "raw_alpha", "Raw Alpha")
setnames(alphaDT, "G6(smc)", "G6")
setnames(alphaDT, "mean", "Mean")
setnames(alphaDT, "sd", "SD")
# setnames(alphaDT, "StdAlpha", "Std Alpha")

options("digits" = 3) 

# Show Cronbach's alpha table
improvement_formatter <- formatter("span", font.weight = "bold")
alphaDT <- alphaDT  %>% mutate(across(`Raw Alpha`:UCL, ~ formattable::comma(., digits = 3)))
formattable(alphaDT, 
  align = c("l","c","c","c","c","c","c","c"),
  list(
    `Indicator Name` = formatter("span", style = ~ style(color = "grey",font.weight = "bold")), 
    `Raw Alpha`      = formattable::color_tile("pink","lightgreen"),
    `Improvement`    = improvement_formatter)
)
Variable ID Raw Alpha G6 Mean SD LCL UCL
Envision Change B01 0.885 0.798 5.889 1.057 0.833 0.937
Promote Change B02 0.902 0.864 5.910 1.001 0.863 0.941
Manage Change B03 0.909 0.872 5.861 0.973 0.874 0.945
Drive Innovation B04 0.916 0.882 5.830 0.973 0.882 0.949
Build Relationship B05 0.826 0.779 6.202 0.768 0.761 0.892
Support Others B06 0.903 0.875 6.013 1.007 0.865 0.942
Make Decision B07 0.928 0.914 5.994 0.929 0.901 0.955
Make Things Happen B08 0.892 0.846 6.008 0.983 0.849 0.935
Solve Problems Creatively B09 0.904 0.825 5.940 1.036 0.860 0.948
Take Responsibility B10 0.915 0.848 6.195 0.937 0.877 0.953
Demonstrate Team Leadership B11 0.899 0.872 6.004 1.007 0.858 0.940
Head Hed 0.972 0.975 5.871 0.954 0.963 0.982
Heart Hrt 0.916 0.916 6.108 0.841 0.889 0.944
Hand Hnd 0.979 0.984 6.020 0.935 0.971 0.986
ILS ILS 0.989 0.996 5.747 0.883 0.985 0.992
Innovative Work Behaviour IWB 0.930 0.930 4.931 0.864 0.906 0.954
# Write Cronbach's Alpha
setwd("~/AB PRIVATE/01 Amy/AB Amy PhD/Part 3/Data/Study3")
write.csv(alphaDT, file = paste(today, "CronbachAlpha.csv"))

3 Showing Graphs of Data

3.1 Plot Histograms of all Variables

# Setting working Directory
setwd("~/AB PRIVATE/01 Amy/AB Amy PhD/Part 3/Data/Study3")

# Prepare PDF
if (makePDF) {
  pdf(paste(today, "Hist.pdf"), width = 25, height = 16)
}
par(mar=c(7, 1, 7, 1))
par(oma=c(1, 1, 1, 1))
par(mfrow=c(2, 2), mai=c(2, 1, 2, 1))

hist(dfFac$Head, prob = T, xlim = c(1, 7), col = "lightblue", xlab= "", ylab="", cex.lab = 2.5, cex.axis = 2.5, cex.main = 3.0, main = "Histogram of Head", breaks = 10)

hist(dfFac$Heart, prob = T, xlim = c(1, 7), col = "#ffcc00", xlab= "", ylab="", cex.lab = 2.5, cex.axis = 2.5, cex.main = 3.0, main = "Histogram of Heart", breaks = 10)

hist(dfFac$Hand, prob = T, xlim = c(1, 7), col = "lightgreen", xlab= "", ylab="", cex.lab = 2.5, cex.axis = 2.5, cex.main = 3.0, main = "Histogram of Hand", breaks = 10)

hist(dfFac$IWB, prob = T, xlim = c(1, 7), col = "pink", xlab= "", ylab="", cex.lab = 2.5, cex.axis = 2.5, cex.main = 3.0, main = "Histogram of IWB", breaks = 10)

if (makePDF) {
  dev.off()
}

3.2 Show Error Plot of Items per Factor

Error plots give an idea of potential misfitting items (questions/statements) per factor (variable.)

# Setting working Directory
setwd("~/AB PRIVATE/01 Amy/AB Amy PhD/Part 3/Data/Study3")

# Prepare PDF
if (makePDF) {
  pdf(paste(today, "Error.pdf"), width = 25, height = 25)
}
par(mar=c(2, 1, 2, 1))
par(oma=c(1, 1, 1, 1))
par(mfrow=c(2, 2))
layout.matrix <- matrix(c(0, 2, 3, 1), nrow = 2, ncol = 2)

# Create mean scores and confidence intervals
error.dots(dfHead, eyes = TRUE, sort = FALSE, main = "Head - Mean Confidence Interval", xlim = c(1, 7), lcolor = "blue", cex = 1.5, cex.main = 1, pch = 19, color = "blue")

error.dots(dfHeart, eyes = TRUE, sort = FALSE, main = "Heart - Mean Confidence Interval", xlim = c(1, 7), lcolor = "darkgreen", cex = 1.5, cex.main = 1, pch = 19, color = "#CC6633")

error.dots(dfHand, eyes = TRUE, sort = FALSE, main = "Hand - Mean Confidence Interval", xlim = c(1, 7), lcolor = "magenta", cex = 1.5, cex.main = 1, pch = 19, color = "darkgreen")

error.dots(dfIWB, eyes = TRUE, sort = FALSE, main = "IWB - Mean Confidence Interval", xlim = c(1, 7), lcolor = "red", cex = 1.5, cex.main = 1, pch = 19, color = "red")

if (makePDF) {
  dev.off()
}

3.3 Show Item List

# Make Item Data Table
improvement_formatter <- formatter("span", font.weight = "bold")
formattable(dfItems[1:31,], caption = "List of Items at ILS",
  align = c("c","l","l", "c"),
  list(
    `Indicator Name` = formatter("span", style = ~ style(color = "grey",font.weight = "bold")), 
    `Mean` = formattable::color_tile("pink","lightgreen"),
    `Improvement` = improvement_formatter)
)
List of Items at ILS
Item Behavior Statement
SN01 Protected Protected
formattable(dfItems[32:40,], caption = "List of Items at IWB",
  align = c("c","l","l", "c"),  
  list(
    `Indicator Name` = formatter("span", style = ~ style(color = "grey",font.weight = "bold")), 
    `Mean` = formattable::color_tile("pink","lightgreen"),
    `Improvement` = improvement_formatter)
)
List of Items at IWB
Item Behavior Statement
IWB01 Protected Protected

3.4 Plot Correlation Matrix of Items

dfMatrix <- cor(dfVal)
corrplot.mixed(dfMatrix, lower = 'number', upper = 'pie', number.cex = 0.7, cl.cex = 1.0, tl.cex = 0.5)

# Write Correlation Matrix
setwd("~/AB PRIVATE/01 Amy/AB Amy PhD/Part 3/Data/Study3")
write.csv(dfMatrix, file = paste(today, "SNCorrelation.csv"))

dev.off()
## null device 
##           1

3.5 Plot Correlation Matrix of Behaviours

# Preparing Correlation Plot
Mat <- cor(dfBeh)
Res <- cor.mtest(dfBeh, conf.level = .95)
corrplot.mixed(Mat, lower.col = "black", number.cex = 1.0, upper = "pie", tl.col = "blue", tl.cex = 1.5, p.mat = Res$p, insig = "p-value", cl.ratio = 0.2, cl.align = "r", cl.lim = c(0, 1), cl.cex = 1.0, number.digits = 3)

corr.test(dfBeh, y = NULL, use = "pairwise", method="pearson", adjust="holm",  alpha=.05, ci=TRUE, minlength=5, normal=TRUE)
## Call:corr.test(x = dfBeh, y = NULL, use = "pairwise", method = "pearson", 
##     adjust = "holm", alpha = 0.05, ci = TRUE, minlength = 5, 
##     normal = TRUE)
## Correlation matrix 
##      B01  B02  B03  B04  B05  B06  B07  B08  B09  B10  B11  IWB
## B01 1.00 0.89 0.91 0.83 0.65 0.83 0.85 0.84 0.84 0.80 0.86 0.85
## B02 0.89 1.00 0.92 0.88 0.69 0.85 0.87 0.88 0.86 0.85 0.88 0.89
## B03 0.91 0.92 1.00 0.90 0.74 0.84 0.88 0.85 0.88 0.85 0.91 0.90
## B04 0.83 0.88 0.90 1.00 0.78 0.85 0.92 0.88 0.87 0.84 0.87 0.90
## B05 0.65 0.69 0.74 0.78 1.00 0.79 0.77 0.76 0.78 0.77 0.78 0.76
## B06 0.83 0.85 0.84 0.85 0.79 1.00 0.89 0.86 0.87 0.88 0.91 0.87
## B07 0.85 0.87 0.88 0.92 0.77 0.89 1.00 0.91 0.88 0.92 0.92 0.89
## B08 0.84 0.88 0.85 0.88 0.76 0.86 0.91 1.00 0.86 0.90 0.89 0.88
## B09 0.84 0.86 0.88 0.87 0.78 0.87 0.88 0.86 1.00 0.87 0.91 0.89
## B10 0.80 0.85 0.85 0.84 0.77 0.88 0.92 0.90 0.87 1.00 0.90 0.86
## B11 0.86 0.88 0.91 0.87 0.78 0.91 0.92 0.89 0.91 0.90 1.00 0.89
## IWB 0.85 0.89 0.90 0.90 0.76 0.87 0.89 0.88 0.89 0.86 0.89 1.00
## Sample Size 
## [1] 76
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##     B01 B02 B03 B04 B05 B06 B07 B08 B09 B10 B11 IWB
## B01   0   0   0   0   0   0   0   0   0   0   0   0
## B02   0   0   0   0   0   0   0   0   0   0   0   0
## B03   0   0   0   0   0   0   0   0   0   0   0   0
## B04   0   0   0   0   0   0   0   0   0   0   0   0
## B05   0   0   0   0   0   0   0   0   0   0   0   0
## B06   0   0   0   0   0   0   0   0   0   0   0   0
## B07   0   0   0   0   0   0   0   0   0   0   0   0
## B08   0   0   0   0   0   0   0   0   0   0   0   0
## B09   0   0   0   0   0   0   0   0   0   0   0   0
## B10   0   0   0   0   0   0   0   0   0   0   0   0
## B11   0   0   0   0   0   0   0   0   0   0   0   0
## IWB   0   0   0   0   0   0   0   0   0   0   0   0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option
# Write Correlation Matrix
setwd("~/AB PRIVATE/01 Amy/AB Amy PhD/Part 3/Data/Study3")
write.csv(Mat, file = paste(today, "BehCorrelation.csv"))

3.6 Plot Correlation Matrix of Behaviours with p-value

3.7 Plot Correlation Matrix of Factors

# Preparing Correlation Plot
Mat <- cor(dfFac)
Res <- cor.mtest(dfFac, conf.level = .95)
corrplot.mixed(Mat, lower.col = "black", number.cex = 1.0, upper = "pie", tl.col = "blue", tl.cex = 1.5, p.mat = Res$p, insig = "p-value", cl.ratio = 0.2, cl.align = "r", cl.lim = c(0, 1), cl.cex = 1.0, number.digits = 3)

corr.test(dfFac, y = NULL, use = "pairwise", method="pearson", adjust="holm",  alpha=.05, ci=TRUE, minlength=5, normal=TRUE)
## Call:corr.test(x = dfFac, y = NULL, use = "pairwise", method = "pearson", 
##     adjust = "holm", alpha = 0.05, ci = TRUE, minlength = 5, 
##     normal = TRUE)
## Correlation matrix 
##       Head Heart Hand  IWB
## Head  1.00  0.87 0.95 0.93
## Heart 0.87  1.00 0.92 0.87
## Hand  0.95  0.92 1.00 0.92
## IWB   0.93  0.87 0.92 1.00
## Sample Size 
## [1] 76
## Probability values (Entries above the diagonal are adjusted for multiple tests.) 
##       Head Heart Hand IWB
## Head     0     0    0   0
## Heart    0     0    0   0
## Hand     0     0    0   0
## IWB      0     0    0   0
## 
##  To see confidence intervals of the correlations, print with the short=FALSE option
# Write Correlation Matrix
setwd("~/AB PRIVATE/01 Amy/AB Amy PhD/Part 3/Data/Study3")
write.csv(Mat, file = paste(today, "FacCorrelation.csv")) 

3.8 Plot Correlation Matrix of Factor Items

# Setting working Directory
setwd("~/AB PRIVATE/01 Amy/AB Amy PhD/Part 3/Data/Study3")

# Prepare PDF
if (makePDF) {
  pdf(paste(today, "CorrFactor.pdf"), width = 25, height = 16)
}
par(mar=c(7, 1, 7, 1))
par(oma=c(1, 1, 1, 1))

Mat <- cor(dfHead)
Res <- cor.mtest(dfHead, conf.level = .95)
corrplot.mixed(Mat, lower.col = "black", number.cex = 2.0, upper = "pie", tl.col = "blue", tl.cex = 2.0, p.mat = Res$p, insig = "p-value", cl.ratio = 0.2, cl.align = "r", cl.lim = c(0, 1), cl.cex = 2.0, cex.main = 3, main = "Correlation of Head Items", mar = c(2,0,2,0), number.digits = 3 )

Mat <- cor(dfHeart)
Res <- cor.mtest(dfHeart, conf.level = .95)
corrplot.mixed(Mat, lower.col = "black", number.cex = 2.0, upper = "pie", tl.col = "blue", tl.cex = 2.0, p.mat = Res$p, insig = "p-value", cl.ratio = 0.2, cl.align = "r", cl.lim = c(0, 1), cl.cex = 2.0, cex.main = 3, main = "Correlation of Heart Items", mar = c(2,0,2,0), number.digits = 3 )

Mat <- cor(dfHand)
Res <- cor.mtest(dfHand, conf.level = .95)
corrplot.mixed(Mat, lower.col = "black", number.cex = 2.0, upper = "pie", tl.col = "blue", tl.cex = 2.0, p.mat = Res$p, insig = "p-value", cl.ratio = 0.2, cl.align = "r", cl.lim = c(0, 1), cl.cex = 2.0, cex.main = 3, main = "Correlation of Hand Items", mar = c(2,0,2,0), number.digits = 3 )

Mat <- cor(dfIWB)
Res <- cor.mtest(dfIWB, conf.level = .95)
corrplot.mixed(Mat, lower.col = "black", number.cex = 2.0, upper = "pie", tl.col = "blue", tl.cex = 2.0, p.mat = Res$p, insig = "p-value", cl.ratio = 0.2, cl.align = "r", cl.lim = c(0, 1), cl.cex = 2.0, cex.main = 3, main = "Correlation of IWB Items", mar = c(2,0,2,0), number.digits = 3)

if (makePDF) {
  dev.off()
}

4 Testing Whether ILS Scale of Study 2 is Confirmed in Study 3 - 287 Raters

4.1 Calculate KMO

Measured by the Kaiser-Meyer-Olkin (KMO) statistics, sampling adequacy predicts if data are likely to factor well, based on correlation and partial correlation. If it´s value is lower then 0.6 then you should inspect those variables to decide which one should not take part of the factor analysis. To do so drop the indicator variables with the lowest individual KMO statistic values, until KMO overall rises above 0.60.

matrix <- cor(dfValNoIWB)

# Printing output
cat("Factorability of all data: ", round(KMO(matrix)$MSA, 4), "\n\nDetails: ")
## Factorability of all data:  0.978 
## 
## Details:
KMO(r = cor(dfValNoIWB))
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = cor(dfValNoIWB))
## Overall MSA =  0.98
## MSA for each item = 
## SN01 SN02 SN03 SN04 SN05 SN07 SN08 SN09 SN10 SN11 SN12 SN13 SN14 SN15 SN16 SN17 
## 0.99 0.97 0.98 0.97 0.98 0.98 0.98 0.98 0.97 0.98 0.98 0.97 0.96 0.96 0.97 0.98 
## SN18 SN20 SN21 SN22 SN23 SN24 SN25 SN26 SN27 SN28 SN30 SN31 SN32 SN33 SN34 
## 0.97 0.98 0.98 0.99 0.99 0.99 0.98 0.98 0.98 0.99 0.98 0.97 0.98 0.98 0.98
cat("\n\nBartlet Test for homogenity of variance:\n")
## 
## 
## Bartlet Test for homogenity of variance:
cat("Chi Square: ", cortest.bartlett(matrix)$chisq, "\n")
## Chi Square:  2758
cat("P value: ", cortest.bartlett(matrix)$p.value, "\n")
## P value:  3.93e-321
cat("Degree of freedom: ", cortest.bartlett(matrix)$df, "\n\n")
## Degree of freedom:  465
cat("Determinant of matrix: ", det(cor(dfValNoIWB)), "\n")
## Determinant of matrix:  0.0000000000000231
rm(matrix, Res, layout.matrix)
# cat("KMO: ", format(KMO, nsmall = 4), ".\n")
# cat("Sphericity: ", format(Sphericity, nsmall = 4), ".\n")

4.2 Principal component analysis - 287 Raters

The number of components is also the number of variables.

Proportion of variance: If it equals to 0.85 then it explains 85% of the variance. Cumulative Proportion: Cumulates the proportion of the previous components adding up until 1. Choose the number of components (factors) with eigenvalues equal or higher then 1 using the Principal Component function.

# Loading necessary packages
if(! "lavaan" %in% installed.packages()) {install.packages("lavaan", dependencies = TRUE) }
library(lavaan)

pca = princomp(dfValNoIWB, scores = TRUE, cor = TRUE)
summary(pca)
## Importance of components:
##                        Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8
## Standard deviation      4.442 1.2012 0.9426 0.7943 0.7768 0.7332 0.7078 0.6993
## Proportion of Variance  0.636 0.0465 0.0287 0.0204 0.0195 0.0173 0.0162 0.0158
## Cumulative Proportion   0.636 0.6829 0.7116 0.7319 0.7514 0.7687 0.7849 0.8007
##                        Comp.9 Comp.10 Comp.11 Comp.12 Comp.13 Comp.14 Comp.15
## Standard deviation     0.6708  0.6572  0.6319  0.6247  0.6015  0.5887  0.5739
## Proportion of Variance 0.0145  0.0139  0.0129  0.0126  0.0117  0.0112  0.0106
## Cumulative Proportion  0.8152  0.8291  0.8420  0.8546  0.8663  0.8774  0.8881
##                        Comp.16 Comp.17 Comp.18 Comp.19 Comp.20 Comp.21 Comp.22
## Standard deviation     0.54814 0.53249 0.52980 0.51737 0.50781 0.49570 0.48245
## Proportion of Variance 0.00969 0.00915 0.00905 0.00863 0.00832 0.00793 0.00751
## Cumulative Proportion  0.89777 0.90691 0.91597 0.92460 0.93292 0.94085 0.94835
##                        Comp.23 Comp.24 Comp.25 Comp.26 Comp.27 Comp.28 Comp.29
## Standard deviation     0.47078 0.46294 0.45135 0.44405 0.41584 0.41376 0.38365
## Proportion of Variance 0.00715 0.00691 0.00657 0.00636 0.00558 0.00552 0.00475
## Cumulative Proportion  0.95550 0.96242 0.96899 0.97535 0.98093 0.98645 0.99120
##                        Comp.30 Comp.31
## Standard deviation     0.37795 0.36056
## Proportion of Variance 0.00461 0.00419
## Cumulative Proportion  0.99581 1.00000
# pca$loadings

4.3 Confirmatory factor analysis - 287 Raters

# Loading necessary packages
if(! "lavaan" %in% installed.packages()) {install.packages("lavaan", dependencies = TRUE) }
library(lavaan)

# Build model
Model01 <- '

# latent variables
 Head  =~ SN01 + SN02 + SN03 + SN04 + SN05 + SN07 + SN08 + SN09 + SN10 + SN11 + SN12
 Heart =~ SN13 + SN14 + SN15 + SN16 + SN17 + SN18 
 Hand  =~ SN20 + SN21 + SN22 + SN23 + SN24 + SN25 + SN26 + SN27 + SN28 + SN30 + SN31 + SN32 + SN33 + SN34
'

# Run CFA
CFA01 <- cfa(Model01, data = dfValNoIWB)
summary(CFA01, fit.measures = TRUE, standardized = TRUE)
## lavaan 0.6-12 ended normally after 66 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        65
## 
##   Number of observations                           287
## 
## Model Test User Model:
##                                                       
##   Test statistic                               985.789
##   Degrees of freedom                               431
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              9011.304
##   Degrees of freedom                               465
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.935
##   Tucker-Lewis Index (TLI)                       0.930
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -8425.474
##   Loglikelihood unrestricted model (H1)      -7932.580
##                                                       
##   Akaike (AIC)                               16980.949
##   Bayesian (BIC)                             17218.815
##   Sample-size adjusted Bayesian (BIC)        17012.693
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.067
##   90 Percent confidence interval - lower         0.061
##   90 Percent confidence interval - upper         0.072
##   P-value RMSEA <= 0.05                          0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.039
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   Head =~                                                               
##     SN01              1.000                               0.729    0.780
##     SN02              1.222    0.076   16.094    0.000    0.891    0.839
##     SN03              1.109    0.072   15.443    0.000    0.808    0.813
##     SN04              1.279    0.080   15.913    0.000    0.932    0.831
##     SN05              1.053    0.069   15.182    0.000    0.767    0.802
##     SN07              1.201    0.074   16.164    0.000    0.876    0.841
##     SN08              1.152    0.071   16.181    0.000    0.840    0.842
##     SN09              1.063    0.070   15.162    0.000    0.775    0.801
##     SN10              1.192    0.073   16.365    0.000    0.869    0.849
##     SN11              1.173    0.073   16.122    0.000    0.855    0.840
##     SN12              0.981    0.068   14.509    0.000    0.715    0.774
##   Heart =~                                                              
##     SN13              1.000                               0.713    0.788
##     SN14              0.967    0.074   13.112    0.000    0.690    0.719
##     SN15              1.084    0.072   15.035    0.000    0.773    0.801
##     SN16              1.203    0.075   16.040    0.000    0.858    0.841
##     SN17              1.163    0.070   16.590    0.000    0.829    0.863
##     SN18              1.098    0.077   14.319    0.000    0.783    0.771
##   Hand =~                                                               
##     SN20              1.000                               0.820    0.815
##     SN21              0.926    0.054   17.143    0.000    0.760    0.832
##     SN22              1.007    0.057   17.725    0.000    0.826    0.851
##     SN23              0.851    0.055   15.611    0.000    0.698    0.781
##     SN24              0.999    0.059   16.823    0.000    0.820    0.822
##     SN25              1.011    0.061   16.662    0.000    0.829    0.817
##     SN26              0.955    0.059   16.201    0.000    0.783    0.801
##     SN27              0.967    0.057   17.075    0.000    0.793    0.830
##     SN28              1.090    0.060   18.179    0.000    0.894    0.865
##     SN30              0.805    0.050   16.080    0.000    0.661    0.797
##     SN31              0.857    0.055   15.555    0.000    0.703    0.779
##     SN32              1.010    0.059   17.055    0.000    0.828    0.830
##     SN33              1.006    0.065   15.510    0.000    0.825    0.777
##     SN34              0.986    0.059   16.622    0.000    0.809    0.815
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   Head ~~                                                               
##     Heart             0.430    0.050    8.638    0.000    0.828    0.828
##     Hand              0.566    0.061    9.307    0.000    0.947    0.947
##   Heart ~~                                                              
##     Hand              0.528    0.058    9.142    0.000    0.902    0.902
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .SN01              0.342    0.030   11.346    0.000    0.342    0.392
##    .SN02              0.335    0.030   11.011    0.000    0.335    0.297
##    .SN03              0.336    0.030   11.185    0.000    0.336    0.340
##    .SN04              0.388    0.035   11.064    0.000    0.388    0.309
##    .SN05              0.327    0.029   11.243    0.000    0.327    0.357
##    .SN07              0.317    0.029   10.989    0.000    0.317    0.292
##    .SN08              0.290    0.026   10.983    0.000    0.290    0.291
##    .SN09              0.335    0.030   11.248    0.000    0.335    0.358
##    .SN10              0.292    0.027   10.922    0.000    0.292    0.279
##    .SN11              0.306    0.028   11.002    0.000    0.306    0.295
##    .SN12              0.342    0.030   11.370    0.000    0.342    0.401
##    .SN13              0.310    0.029   10.650    0.000    0.310    0.379
##    .SN14              0.445    0.040   11.117    0.000    0.445    0.483
##    .SN15              0.334    0.032   10.529    0.000    0.334    0.359
##    .SN16              0.304    0.030   10.008    0.000    0.304    0.292
##    .SN17              0.236    0.025    9.605    0.000    0.236    0.256
##    .SN18              0.418    0.039   10.793    0.000    0.418    0.405
##    .SN20              0.340    0.030   11.366    0.000    0.340    0.336
##    .SN21              0.256    0.023   11.279    0.000    0.256    0.307
##    .SN22              0.260    0.023   11.166    0.000    0.260    0.276
##    .SN23              0.311    0.027   11.495    0.000    0.311    0.390
##    .SN24              0.322    0.028   11.333    0.000    0.322    0.324
##    .SN25              0.343    0.030   11.358    0.000    0.343    0.333
##    .SN26              0.342    0.030   11.423    0.000    0.342    0.358
##    .SN27              0.284    0.025   11.291    0.000    0.284    0.311
##    .SN28              0.270    0.024   11.059    0.000    0.270    0.253
##    .SN30              0.250    0.022   11.439    0.000    0.250    0.365
##    .SN31              0.320    0.028   11.501    0.000    0.320    0.393
##    .SN32              0.311    0.028   11.295    0.000    0.311    0.312
##    .SN33              0.446    0.039   11.506    0.000    0.446    0.396
##    .SN34              0.330    0.029   11.364    0.000    0.330    0.335
##     Head              0.531    0.068    7.837    0.000    1.000    1.000
##     Heart             0.508    0.065    7.869    0.000    1.000    1.000
##     Hand              0.673    0.080    8.388    0.000    1.000    1.000
# pca$loadings

4.4 Factor Analysis - 287 Raters

# Factor analysis
fa = factanal(dfValNoIWB, factor = 3, rotation = "Promax", scores = "regression")
fa
## 
## Call:
## factanal(x = dfValNoIWB, factors = 3, scores = "regression",     rotation = "Promax")
## 
## Uniquenesses:
##  SN01  SN02  SN03  SN04  SN05  SN07  SN08  SN09  SN10  SN11  SN12  SN13  SN14 
## 0.374 0.310 0.353 0.275 0.358 0.304 0.263 0.367 0.248 0.263 0.377 0.393 0.315 
##  SN15  SN16  SN17  SN18  SN20  SN21  SN22  SN23  SN24  SN25  SN26  SN27  SN28 
## 0.301 0.250 0.282 0.402 0.336 0.314 0.280 0.318 0.318 0.323 0.351 0.294 0.258 
##  SN30  SN31  SN32  SN33  SN34 
## 0.290 0.304 0.317 0.395 0.329 
## 
## Loadings:
##      Factor1 Factor2 Factor3
## SN01  0.393   0.490         
## SN02  0.768                 
## SN03  0.643   0.226         
## SN04  0.908  -0.118         
## SN05  0.475   0.421         
## SN07  0.686   0.188         
## SN08  0.907                 
## SN09  0.727                 
## SN10  0.865  -0.167   0.201 
## SN11  0.944  -0.111         
## SN12  0.430   0.214   0.221 
## SN13          0.469   0.389 
## SN14                  0.864 
## SN15  0.154           0.656 
## SN16          0.208   0.684 
## SN17          0.643   0.310 
## SN18  0.204   0.450   0.183 
## SN20  0.573   0.287         
## SN21  0.267   0.528         
## SN22  0.523   0.327         
## SN23          0.822         
## SN24  0.309   0.581         
## SN25  0.370   0.571  -0.116 
## SN26  0.241   0.596         
## SN27  0.633   0.184         
## SN28  0.500   0.328         
## SN30          0.866         
## SN31 -0.130   0.876         
## SN32  0.333   0.515         
## SN33  0.201   0.579         
## SN34  0.517   0.379         
## 
##                Factor1 Factor2 Factor3
## SS loadings      7.984   6.066   2.108
## Proportion Var   0.258   0.196   0.068
## Cumulative Var   0.258   0.453   0.521
## 
## Factor Correlations:
##         Factor1 Factor2 Factor3
## Factor1   1.000  -0.832  -0.642
## Factor2  -0.832   1.000   0.724
## Factor3  -0.642   0.724   1.000
## 
## Test of the hypothesis that 3 factors are sufficient.
## The chi square statistic is 662 on 375 degrees of freedom.
## The p-value is 0.00000000000000000344

5 Testing Whether ILS Factors Influence IWB - 76 Raters

5.1 How to Evaluate SEM Output?

Chisq: The model Chi-squared assesses overall fit and the discrepancy between the sample and fitted covariance matrices. Its p-value should be > .05 (i.e., the hypothesis of a perfect fit cannot be rejected). However, it is quite sensitive to sample size. Commonly, Chisq/DF < 3 is used as criteria.

GFI/AGFI: The (Adjusted) Goodness of Fit is the proportion of variance accounted for by the estimated population covariance. Analogous to R2. The GFI and the AGFI should be > .95 and > .90, respectively.

NFI/NNFI/TLI: The (Non) Normed Fit Index. An NFI of 0.95, indicates the model of interest improves the fit by 95% relative to the null model. The NNFI (also called the Tucker Lewis index; TLI) is preferable for smaller samples. They should be > .90 (Byrne, 1994) or > .95 (Schumacker & Lomax, 2004). TLI > .90. TLI: < .85(poor); .85-.90 (mediocre); .90-.95 (acceptable); .95-.99 (close); 1.00 (perfect)

CFI: The Comparative Fit Index is a revised form of NFI. Not very sensitive to sample size (Fan, Thompson, & Wang, 1999). Compares the fit of a target model to the fit of an independent, or null, model. CFI: < .85(poor); .85-.90 (mediocre); .90-.95 (acceptable); .95-.99 (close); 1.00 (perfect)

RMSEA: The Root Mean Square Error of Approximation is a parsimony-adjusted index. Values closer to 0 represent a good fit. It should be < .08 or < .05. The p-value printed with it tests the hypothesis that RMSEA is less than or equal to .05 (a cutoff sometimes used for good fit), and thus should be not significant. RMSEA: > .10 (poor); .08-.10 (mediocre); .05-.08 (acceptable); .01-.05 (close); .00 (perfect)

RMR/SRMR: the (Standardized) Root Mean Square Residual represents the square-root of the difference between the residuals of the sample covariance matrix and the hypothesized model. As the RMR can be sometimes hard to interpret, better to use SRMR. SRMR: > .10 (poor); .08-.10 (mediocre); .05-.08 (acceptable); .01-.05 (close); .00 (perfect)

RFI: the Relative Fit Index, also known as RHO1, is not guaranteed to vary from 0 to 1. However, RFI close to 1 indicates a good fit.

IFI: the Incremental Fit Index (IFI) adjusts the Normed Fit Index (NFI) for sample size and degrees of freedom (Bollen’s, 1989). Over 0.90 is a good fit, but the index can exceed 1.

PNFI: the Parsimony-Adjusted Measures Index. There is no commonly agreed-upon cutoff value for an acceptable model for this index. Should be > 0.50.

To Report: chi-square, RMSEA, CFI, RMSEA and SRMR.

5.2 About Estimators

Commonly used estimation method Maximum Likelihood (ML) has been developed for continuous data following the normal-theory. This method is used to estimate all fit indices like RMSEA, CFI, and TLI. Since our data is generated using a 7-point Likert Scale, i.e. resulting in ordered discrete/categorical data, this method may not be the best to determine model fit (Yan Xia & Yanyun Yang, 2018).Therefore, methods based on Unweighted Least Squares (ULS) and Diagonally Weighted Least Squares (DWLS) based on polychoric correlation matrices have been considered in previous studies.

5.3 Build Model: Head -> Hand -> IWB with Heart as Mediator (MLR) - 76 Raters

# Loading necessary packages
if(! "lavaan" %in% installed.packages()) {install.packages("lavaan", dependencies = TRUE) }
library(lavaan)

Model05 <- '

# latent variables
 IWB   =~ IWB01 + IWB02 + IWB03 + IWB04 + IWB05 + IWB06 + IWB07 + IWB08 + IWB09

 Head  =~ SN01 + SN02 + SN03 + SN04 + SN05 + SN07 + SN08 + SN09 + SN10 + SN11 + SN12 + SN18 
 Heart =~ SN13 + SN14 + SN15 + SN16 + SN17 
 Hand  =~ SN20 + SN21 + SN22 + SN23 + SN24 + SN25 + SN26 + SN27 + SN28 + SN30 + SN31 + SN32 + SN33 + SN34

# direct effect
 IWB   ~ a * Hand
 Hand  ~ d * Head

 EffHnd := a

# mediator
 Hand  ~ b * Heart
 Heart ~ c * Head
 
# covariances
 IWB07  ~~  SN24
 IWB03  ~~  SN16
 SN02     ~~    SN30
 SN04     ~~    SN31
 SN05   ~~  SN30
 SN12   ~~  SN21
 SN13   ~~  SN20
 SN15   ~~  SN24
 SN16     ~~    SN20
 SN21     ~~    SN34
 SN21   ~~  SN22
 SN24     ~~    SN28

# indirect effect

 EffHrt := a * b
 EffHed := a * (d + b * c)

'

# Calculate fit
Fit05 <- sem(Model05, data = dfVal, estimator = "MLR", likelihood = "wishart")

# Print results (fit indices, parameters, hypothesis tests)
summary(Fit05, fit.measures = TRUE, rsquare = TRUE)
## lavaan 0.6-12 ended normally after 76 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        96
## 
##   Number of observations                            76
## 
## Model Test User Model:
##                                               Standard      Robust
##   Test Statistic                              1209.330    1233.195
##   Degrees of freedom                               724         724
##   P-value (Chi-square)                           0.000       0.000
##   Scaling correction factor                                  0.981
##     Yuan-Bentler correction (Mplus variant)                       
## 
## Model Test Baseline Model:
## 
##   Test statistic                              4779.371    4858.433
##   Degrees of freedom                               780         780
##   P-value                                        0.000       0.000
##   Scaling correction factor                                  0.984
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.879       0.875
##   Tucker-Lewis Index (TLI)                       0.869       0.865
##                                                                   
##   Robust Comparative Fit Index (CFI)                         0.876
##   Robust Tucker-Lewis Index (TLI)                            0.866
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -2661.884   -2661.884
##   Scaling correction factor                                  1.411
##       for the MLR correction                                      
##   Loglikelihood unrestricted model (H1)      -2049.157   -2049.157
##   Scaling correction factor                                  1.031
##       for the MLR correction                                      
##                                                                   
##   Akaike (AIC)                                5515.769    5515.769
##   Bayesian (BIC)                              5739.519    5739.519
##   Sample-size adjusted Bayesian (BIC)         5436.920    5436.920
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.095       0.097
##   90 Percent confidence interval - lower         0.085       0.087
##   90 Percent confidence interval - upper         0.104       0.106
##   P-value RMSEA <= 0.05                          0.000       0.000
##                                                                   
##   Robust RMSEA                                               0.096
##   90 Percent confidence interval - lower                     0.087
##   90 Percent confidence interval - upper                     0.105
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.042       0.042
## 
## Parameter Estimates:
## 
##   Standard errors                             Sandwich
##   Information bread                           Observed
##   Observed information based on                Hessian
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   IWB =~                                              
##     IWB01             1.000                           
##     IWB02             0.942    0.103    9.169    0.000
##     IWB03             0.940    0.113    8.293    0.000
##     IWB04             0.699    0.086    8.134    0.000
##     IWB05             0.885    0.080   11.072    0.000
##     IWB06             0.899    0.164    5.474    0.000
##     IWB07             0.842    0.085    9.912    0.000
##     IWB08             0.876    0.155    5.631    0.000
##     IWB09             0.838    0.145    5.766    0.000
##   Head =~                                             
##     SN01              1.000                           
##     SN02              1.178    0.122    9.619    0.000
##     SN03              0.998    0.112    8.892    0.000
##     SN04              1.162    0.129    8.996    0.000
##     SN05              1.031    0.149    6.911    0.000
##     SN07              1.122    0.117    9.547    0.000
##     SN08              1.013    0.106    9.588    0.000
##     SN09              0.987    0.142    6.964    0.000
##     SN10              1.085    0.113    9.582    0.000
##     SN11              0.988    0.106    9.313    0.000
##     SN12              0.971    0.112    8.696    0.000
##     SN18              1.176    0.119    9.883    0.000
##   Heart =~                                            
##     SN13              1.000                           
##     SN14              0.450    0.192    2.350    0.019
##     SN15              0.930    0.086   10.816    0.000
##     SN16              0.908    0.090   10.134    0.000
##     SN17              1.103    0.122    9.077    0.000
##   Hand =~                                             
##     SN20              1.000                           
##     SN21              0.924    0.086   10.678    0.000
##     SN22              0.980    0.076   12.855    0.000
##     SN23              0.876    0.098    8.967    0.000
##     SN24              1.005    0.083   12.091    0.000
##     SN25              1.011    0.109    9.279    0.000
##     SN26              0.937    0.110    8.515    0.000
##     SN27              1.094    0.103   10.658    0.000
##     SN28              0.980    0.091   10.796    0.000
##     SN30              0.881    0.089    9.947    0.000
##     SN31              0.995    0.104    9.604    0.000
##     SN32              1.031    0.077   13.372    0.000
##     SN33              1.081    0.076   14.283    0.000
##     SN34              0.981    0.082   11.957    0.000
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   IWB ~                                               
##     Hand       (a)    0.982    0.112    8.783    0.000
##   Hand ~                                              
##     Head       (d)    0.702    0.089    7.893    0.000
##     Heart      (b)    0.367    0.097    3.776    0.000
##   Heart ~                                             
##     Head       (c)    0.876    0.134    6.545    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##  .IWB07 ~~                                            
##    .SN24              0.168    0.063    2.669    0.008
##  .IWB03 ~~                                            
##    .SN16             -0.127    0.035   -3.674    0.000
##  .SN02 ~~                                             
##    .SN30             -0.088    0.032   -2.756    0.006
##  .SN04 ~~                                             
##    .SN31             -0.097    0.049   -1.979    0.048
##  .SN05 ~~                                             
##    .SN30              0.070    0.033    2.126    0.034
##  .SN12 ~~                                             
##    .SN21              0.093    0.034    2.746    0.006
##  .SN13 ~~                                             
##    .SN20             -0.105    0.040   -2.630    0.009
##  .SN15 ~~                                             
##    .SN24             -0.083    0.033   -2.482    0.013
##  .SN16 ~~                                             
##    .SN20             -0.104    0.039   -2.692    0.007
##  .SN21 ~~                                             
##    .SN34             -0.070    0.031   -2.282    0.022
##    .SN22              0.076    0.033    2.327    0.020
##  .SN24 ~~                                             
##    .SN28             -0.096    0.032   -3.031    0.002
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .IWB01             0.292    0.045    6.495    0.000
##    .IWB02             0.419    0.060    6.975    0.000
##    .IWB03             0.428    0.063    6.794    0.000
##    .IWB04             0.477    0.069    6.883    0.000
##    .IWB05             0.362    0.053    6.819    0.000
##    .IWB06             0.562    0.116    4.858    0.000
##    .IWB07             0.564    0.097    5.844    0.000
##    .IWB08             0.515    0.079    6.491    0.000
##    .IWB09             0.603    0.095    6.345    0.000
##    .SN01              0.314    0.084    3.749    0.000
##    .SN02              0.241    0.066    3.670    0.000
##    .SN03              0.285    0.067    4.276    0.000
##    .SN04              0.283    0.070    4.021    0.000
##    .SN05              0.296    0.070    4.224    0.000
##    .SN07              0.248    0.067    3.695    0.000
##    .SN08              0.259    0.043    6.084    0.000
##    .SN09              0.230    0.061    3.746    0.000
##    .SN10              0.256    0.051    5.060    0.000
##    .SN11              0.256    0.041    6.196    0.000
##    .SN12              0.316    0.076    4.179    0.000
##    .SN18              0.365    0.082    4.483    0.000
##    .SN13              0.259    0.050    5.160    0.000
##    .SN14              0.406    0.089    4.547    0.000
##    .SN15              0.260    0.061    4.289    0.000
##    .SN16              0.243    0.050    4.827    0.000
##    .SN17              0.175    0.047    3.714    0.000
##    .SN20              0.302    0.057    5.249    0.000
##    .SN21              0.216    0.039    5.559    0.000
##    .SN22              0.212    0.039    5.470    0.000
##    .SN23              0.278    0.077    3.626    0.000
##    .SN24              0.300    0.067    4.496    0.000
##    .SN25              0.329    0.060    5.462    0.000
##    .SN26              0.338    0.079    4.298    0.000
##    .SN27              0.169    0.042    3.997    0.000
##    .SN28              0.289    0.062    4.629    0.000
##    .SN30              0.173    0.035    4.980    0.000
##    .SN31              0.183    0.047    3.926    0.000
##    .SN32              0.462    0.188    2.463    0.014
##    .SN33              0.198    0.050    3.989    0.000
##    .SN34              0.194    0.039    5.027    0.000
##    .IWB               0.043    0.028    1.521    0.128
##     Head              0.803    0.275    2.914    0.004
##    .Heart             0.167    0.047    3.546    0.000
##    .Hand              0.014    0.010    1.463    0.143
## 
## R-Square:
##                    Estimate
##     IWB01             0.753
##     IWB02             0.653
##     IWB03             0.647
##     IWB04             0.477
##     IWB05             0.658
##     IWB06             0.561
##     IWB07             0.528
##     IWB08             0.570
##     IWB09             0.509
##     SN01              0.719
##     SN02              0.822
##     SN03              0.737
##     SN04              0.793
##     SN05              0.742
##     SN07              0.803
##     SN08              0.761
##     SN09              0.773
##     SN10              0.787
##     SN11              0.753
##     SN12              0.705
##     SN18              0.752
##     SN13              0.752
##     SN14              0.281
##     SN15              0.722
##     SN16              0.727
##     SN17              0.845
##     SN20              0.744
##     SN21              0.776
##     SN22              0.799
##     SN23              0.708
##     SN24              0.747
##     SN25              0.732
##     SN26              0.695
##     SN27              0.862
##     SN28              0.745
##     SN30              0.798
##     SN31              0.826
##     SN32              0.669
##     SN33              0.838
##     SN34              0.813
##     IWB               0.952
##     Heart             0.787
##     Hand              0.984
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     EffHnd            0.982    0.112    8.783    0.000
##     EffHrt            0.360    0.077    4.693    0.000
##     EffHed            1.005    0.126    7.989    0.000
modificationIndices(Fit05, minimum.value = 5)
##       lhs op   rhs    mi    epc sepc.lv sepc.all sepc.nox
## 114   IWB =~  SN12 11.88  1.044   0.985    0.951    0.951
## 135  Head =~ IWB01  6.88  0.951   0.852    0.784    0.784
## 143  Head =~ IWB09  5.40  1.106   0.991    0.895    0.895
## 158  Head =~  SN30  6.27 -0.768  -0.688   -0.744   -0.744
## 168 Heart =~ IWB06  6.53 -0.846  -0.748   -0.661   -0.661
## 171 Heart =~ IWB09  5.47 -0.797  -0.705   -0.637   -0.637
## 182 Heart =~  SN12 20.59  0.800   0.708    0.684    0.684
## 193 Heart =~  SN30  6.88  0.467   0.414    0.448    0.448
## 217  Hand =~  SN12 16.00  1.698   1.591    1.536    1.536
## 222  Hand =~  SN16  5.12 -0.560  -0.524   -0.556   -0.556
## 270 IWB02 ~~  SN01  6.17 -0.109  -0.109   -0.300   -0.300
## 282 IWB02 ~~  SN13  6.12  0.099   0.099    0.300    0.300
## 331 IWB03 ~~  SN28  7.60  0.103   0.103    0.294    0.294
## 366 IWB04 ~~  SN27  7.80  0.095   0.095    0.335    0.335
## 410 IWB06 ~~ IWB09  5.96  0.170   0.170    0.292    0.292
## 424 IWB06 ~~  SN14  6.46  0.143   0.143    0.300    0.300
## 437 IWB06 ~~  SN30  6.51 -0.082  -0.082   -0.263   -0.263
## 450 IWB07 ~~  SN08  5.29 -0.095  -0.095   -0.247   -0.247
## 456 IWB07 ~~  SN13  6.12 -0.103  -0.103   -0.269   -0.269
## 466 IWB07 ~~  SN26  6.53  0.118   0.118    0.271    0.271
## 511 IWB09 ~~  SN07  5.22  0.107   0.107    0.276    0.276
## 512 IWB09 ~~  SN08  7.40  0.129   0.129    0.326    0.326
## 554  SN01 ~~  SN21  7.69  0.069   0.069    0.264    0.264
## 560  SN01 ~~  SN27  6.31  0.070   0.070    0.304    0.304
## 619  SN03 ~~  SN31  6.24  0.064   0.064    0.280    0.280
## 627  SN04 ~~  SN10  5.23 -0.071  -0.071   -0.263   -0.263
## 632  SN04 ~~  SN14  5.79 -0.090  -0.090   -0.266   -0.266
## 639  SN04 ~~  SN23  5.21 -0.071  -0.071   -0.254   -0.254
## 643  SN04 ~~  SN27  5.45  0.058   0.058    0.266    0.266
## 660  SN05 ~~  SN17  5.83 -0.067  -0.067   -0.296   -0.296
## 665  SN05 ~~  SN24  6.88  0.072   0.072    0.242    0.242
## 696  SN07 ~~  SN32  5.40  0.094   0.094    0.279    0.279
## 734  SN09 ~~  SN22  6.59 -0.061  -0.061   -0.278   -0.278
## 735  SN09 ~~  SN23  7.81  0.085   0.085    0.334    0.334
## 791  SN12 ~~  SN14 10.11  0.123   0.123    0.342    0.342
## 792  SN12 ~~  SN15  5.26  0.071   0.071    0.246    0.246
## 793  SN12 ~~  SN16  5.36  0.065   0.065    0.235    0.235
## 824  SN18 ~~  SN32  5.47  0.114   0.114    0.278    0.278
## 841  SN13 ~~  SN32  9.38  0.126   0.126    0.365    0.365
## 898  SN17 ~~  SN28  8.07 -0.080  -0.080   -0.354   -0.354
## 913  SN20 ~~  SN31 10.01 -0.075  -0.075   -0.318   -0.318
## 914  SN20 ~~  SN32  5.80  0.095   0.095    0.256    0.256
## 960  SN25 ~~  SN31  7.92  0.076   0.076    0.311    0.311

5.4 Plot Model (MLR) - 76 Raters

# Loading necessary packages
if(! "semPlot" %in% installed.packages()) {install.packages("semPlot", dependencies = TRUE) }
library(semPlot)

# Setting working Directory
setwd("~/AB PRIVATE/01 Amy/AB Amy PhD/Part 3/Data/Study3")

# Prepare PDF for Model 05
if (makePDF) {
  pdf(paste(today, "Model05.pdf"), width = 25, height = 25)
}
par(mar=c(7, 1, 7, 1))
par(oma=c(1, 1, 1, 1))

# Prepare fitmeasures
ParDF  <- as.data.frame(do.call(cbind, Fit05@ParTable))
EffHed <- round(as.numeric(ParDF[ParDF$label == "EffHed", 14]), 4)
EffHrt <- round(as.numeric(ParDF[ParDF$label == "EffHrt", 14]), 4)
EffHnd <- round(as.numeric(ParDF[ParDF$label == "EffHnd", 14]), 4)
n      <- Fit05@SampleStats@ntotal

fitMeas <- toString(c("ChiSq: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "chisq"))), 4),
            " - ChiSq-p: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "pvalue"))), 4),
            " - DF: ", gsub("[^0-9.]", "", fitMeasures(Fit05, "df")),
            " - ChiSq/DF: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "chisq")))/ as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "df"))), 4),
            " - CFI: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "cfi"))), 4),
            " - TLI: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "tli"))), 4),
            " - RMSEA: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "rmsea"))), 4),
            " - SRMR: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "srmr"))), 4),
            " - n: ", n,
            " - EffHed: ", EffHed,
            " - EffHrt: ", EffHrt,
            " - EffHnd: ", EffHnd
            ), 
            width = 255)
fitMeas <- gsub(",", "", fitMeas)

# Plot model
semPaths(Fit05, what = "eq", whatLabels = "stand", intercepts = FALSE, residuals = FALSE, 
         edge.label.cex = 0.7, edge.color = "blue", layout = "circle2", rotation = 3, curve = 1, 
         curvePivot = TRUE, mar = c(3,1,5,1), sizeLat = 7, sizeMan = 4, color = colorlist 
         )
title(main = "Model 5: Showing Head -> Hand -> IWB with Heart as Mediator\nEstimator: MLR - 76 Raters",
      cex.main = 2.5, col.main = "darkblue", font.main = 3, sub = fitMeas, cex.sub = 1.4)

if (makePDF) {
  dev.off()
}

5.5 Build Model: Head -> Hand -> IWB with Heart as Mediator (WLSMV) - 76 Raters

# Loading necessary packages
if(! "lavaan" %in% installed.packages()) {install.packages("lavaan", dependencies = TRUE) }
library(lavaan)

Model05 <- '

# latent variables
 IWB =~ IWB01 + IWB02 + IWB03 + IWB04 + IWB05 + IWB06 + IWB07 + IWB08 + IWB09

 Head  =~ SN01 + SN02 + SN03 + SN04 + SN05 + SN07 + SN08 + SN09 + SN10 + SN11 + SN12 + SN18 
 Heart =~ SN13 + SN14 + SN15 + SN16 + SN17 
 Hand  =~ SN20 + SN21 + SN22 + SN23 + SN24 + SN25 + SN26 + SN27 + SN28 + SN30 + SN31 + SN32 + SN33 + SN34

# direct effect
 IWB   ~ a * Hand
 Hand  ~ d * Head

 EffHnd := a

# mediator
 Hand  ~ b * Heart
 Heart ~ c * Head
 
# covariances
 IWB07  ~~  SN24
 IWB03  ~~  SN16
 SN02     ~~    SN30
 SN04     ~~    SN31
 SN05   ~~  SN30
 SN12   ~~  SN21
 SN13   ~~  SN20
 SN15   ~~  SN24
 SN16     ~~    SN20
 SN21     ~~    SN34
 SN21   ~~  SN22
 SN24     ~~    SN28

# indirect effect

 EffHrt := a * b
 EffHed := a * (d + b * c)

'

# Calculate fit
Fit05 <- sem(Model05, data = dfVal, estimator = "WLSMV")
lavInspect(Fit05, "cov.lv")
##       IWB   Head  Heart Hand 
## IWB   0.909                  
## Head  0.805 0.767            
## Heart 0.767 0.683 0.799      
## Hand  0.881 0.820 0.782 0.898
# Print results (fit indices, parameters, hypothesis tests)
summary(Fit05, fit.measures = TRUE, rsquare = TRUE)
## lavaan 0.6-12 ended normally after 75 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                        96
## 
##   Number of observations                            76
## 
## Model Test User Model:
##                                               Standard      Robust
##   Test Statistic                                38.551     747.705
##   Degrees of freedom                               724         724
##   P-value (Chi-square)                           1.000       0.263
##   Scaling correction factor                                  0.241
##   Shift parameter                                          587.674
##     simple second-order correction                                
## 
## Model Test Baseline Model:
## 
##   Test statistic                              9475.041    1189.609
##   Degrees of freedom                               780         780
##   P-value                                        0.000       0.000
##   Scaling correction factor                                 21.228
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       0.942
##   Tucker-Lewis Index (TLI)                       1.085       0.938
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.021
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.041
##   P-value RMSEA <= 0.05                          1.000       0.995
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                     0.000
##   90 Percent confidence interval - upper                        NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.040       0.040
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   IWB =~                                              
##     IWB01             1.000                           
##     IWB02             0.924    0.098    9.474    0.000
##     IWB03             0.949    0.111    8.524    0.000
##     IWB04             0.686    0.084    8.118    0.000
##     IWB05             0.877    0.078   11.196    0.000
##     IWB06             0.892    0.175    5.088    0.000
##     IWB07             0.838    0.081   10.331    0.000
##     IWB08             0.861    0.161    5.337    0.000
##     IWB09             0.833    0.148    5.644    0.000
##   Head =~                                             
##     SN01              1.000                           
##     SN02              1.199    0.125    9.619    0.000
##     SN03              1.019    0.131    7.752    0.000
##     SN04              1.175    0.142    8.304    0.000
##     SN05              1.039    0.158    6.560    0.000
##     SN07              1.139    0.139    8.207    0.000
##     SN08              1.039    0.115    9.035    0.000
##     SN09              1.004    0.151    6.668    0.000
##     SN10              1.106    0.133    8.341    0.000
##     SN11              1.022    0.127    8.030    0.000
##     SN12              1.047    0.137    7.669    0.000
##     SN18              1.210    0.145    8.326    0.000
##   Heart =~                                            
##     SN13              1.000                           
##     SN14              0.446    0.187    2.388    0.017
##     SN15              0.955    0.090   10.649    0.000
##     SN16              0.869    0.096    9.047    0.000
##     SN17              1.123    0.149    7.534    0.000
##   Hand =~                                             
##     SN20              1.000                           
##     SN21              0.926    0.086   10.761    0.000
##     SN22              0.968    0.079   12.298    0.000
##     SN23              0.848    0.101    8.354    0.000
##     SN24              0.987    0.089   11.144    0.000
##     SN25              0.987    0.111    8.868    0.000
##     SN26              0.930    0.113    8.193    0.000
##     SN27              1.089    0.104   10.437    0.000
##     SN28              0.969    0.099    9.763    0.000
##     SN30              0.849    0.095    8.930    0.000
##     SN31              0.981    0.108    9.072    0.000
##     SN32              1.019    0.082   12.459    0.000
##     SN33              1.058    0.085   12.493    0.000
##     SN34              0.968    0.091   10.605    0.000
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   IWB ~                                               
##     Hand       (a)    0.981    0.115    8.529    0.000
##   Hand ~                                              
##     Head       (d)    0.828    0.105    7.912    0.000
##     Heart      (b)    0.271    0.106    2.548    0.011
##   Heart ~                                             
##     Head       (c)    0.890    0.155    5.758    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##  .IWB07 ~~                                            
##    .SN24              0.169    0.069    2.461    0.014
##  .IWB03 ~~                                            
##    .SN16             -0.129    0.038   -3.404    0.001
##  .SN02 ~~                                             
##    .SN30             -0.090    0.032   -2.784    0.005
##  .SN04 ~~                                             
##    .SN31             -0.111    0.053   -2.095    0.036
##  .SN05 ~~                                             
##    .SN30              0.053    0.038    1.413    0.158
##  .SN12 ~~                                             
##    .SN21              0.059    0.031    1.873    0.061
##  .SN13 ~~                                             
##    .SN20             -0.089    0.047   -1.868    0.062
##  .SN15 ~~                                             
##    .SN24             -0.098    0.038   -2.555    0.011
##  .SN16 ~~                                             
##    .SN20             -0.086    0.057   -1.499    0.134
##  .SN21 ~~                                             
##    .SN34             -0.070    0.034   -2.047    0.041
##    .SN22              0.081    0.034    2.395    0.017
##  .SN24 ~~                                             
##    .SN28             -0.106    0.042   -2.508    0.012
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .IWB01             0.271    0.049    5.495    0.000
##    .IWB02             0.430    0.063    6.804    0.000
##    .IWB03             0.421    0.067    6.280    0.000
##    .IWB04             0.484    0.067    7.200    0.000
##    .IWB05             0.360    0.057    6.342    0.000
##    .IWB06             0.558    0.123    4.522    0.000
##    .IWB07             0.554    0.094    5.874    0.000
##    .IWB08             0.522    0.085    6.125    0.000
##    .IWB09             0.596    0.091    6.524    0.000
##    .SN01              0.350    0.111    3.149    0.002
##    .SN02              0.273    0.088    3.088    0.002
##    .SN03              0.288    0.073    3.950    0.000
##    .SN04              0.316    0.082    3.832    0.000
##    .SN05              0.305    0.072    4.222    0.000
##    .SN07              0.262    0.070    3.736    0.000
##    .SN08              0.256    0.045    5.753    0.000
##    .SN09              0.239    0.058    4.093    0.000
##    .SN10              0.263    0.052    5.064    0.000
##    .SN11              0.239    0.043    5.523    0.000
##    .SN12              0.239    0.071    3.387    0.001
##    .SN18              0.352    0.094    3.757    0.000
##    .SN13              0.226    0.066    3.455    0.001
##    .SN14              0.406    0.087    4.679    0.000
##    .SN15              0.218    0.064    3.424    0.001
##    .SN16              0.269    0.064    4.225    0.000
##    .SN17              0.122    0.067    1.840    0.066
##    .SN20              0.314    0.059    5.348    0.000
##    .SN21              0.214    0.037    5.777    0.000
##    .SN22              0.214    0.038    5.594    0.000
##    .SN23              0.307    0.079    3.875    0.000
##    .SN24              0.313    0.077    4.059    0.000
##    .SN25              0.351    0.068    5.176    0.000
##    .SN26              0.333    0.077    4.319    0.000
##    .SN27              0.154    0.041    3.763    0.000
##    .SN28              0.289    0.062    4.665    0.000
##    .SN30              0.202    0.038    5.244    0.000
##    .SN31              0.195    0.043    4.568    0.000
##    .SN32              0.463    0.187    2.473    0.013
##    .SN33              0.218    0.051    4.269    0.000
##    .SN34              0.198    0.040    4.977    0.000
##    .IWB               0.044    0.042    1.066    0.286
##     Head              0.767    0.276    2.775    0.006
##    .Heart             0.191    0.065    2.956    0.003
##    .Hand              0.007    0.011    0.601    0.548
## 
## R-Square:
##                    Estimate
##     IWB01             0.770
##     IWB02             0.644
##     IWB03             0.661
##     IWB04             0.469
##     IWB05             0.660
##     IWB06             0.564
##     IWB07             0.536
##     IWB08             0.564
##     IWB09             0.514
##     SN01              0.687
##     SN02              0.802
##     SN03              0.734
##     SN04              0.770
##     SN05              0.731
##     SN07              0.792
##     SN08              0.764
##     SN09              0.764
##     SN10              0.781
##     SN11              0.771
##     SN12              0.779
##     SN18              0.762
##     SN13              0.779
##     SN14              0.282
##     SN15              0.770
##     SN16              0.692
##     SN17              0.892
##     SN20              0.741
##     SN21              0.782
##     SN22              0.797
##     SN23              0.678
##     SN24              0.737
##     SN25              0.714
##     SN26              0.700
##     SN27              0.873
##     SN28              0.745
##     SN30              0.762
##     SN31              0.816
##     SN32              0.668
##     SN33              0.822
##     SN34              0.810
##     IWB               0.951
##     Heart             0.761
##     Hand              0.993
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     EffHnd            0.981    0.115    8.529    0.000
##     EffHrt            0.266    0.096    2.783    0.005
##     EffHed            1.049    0.140    7.509    0.000
# modificationIndices(Fit05, minimum.value = 5)

5.6 Plot Model (WLSMV) - 76 Raters

# Loading necessary packages
if(! "semPlot" %in% installed.packages()) {install.packages("semPlot", dependencies = TRUE) }
library(semPlot)

# Setting working Directory
setwd("~/AB PRIVATE/01 Amy/AB Amy PhD/Part 3/Data/Study3")

# Prepare PDF for Model 05
if (makePDF) {
  pdf(paste(today, "Model05.pdf"), width = 25, height = 25)
}
par(mar=c(7, 1, 7, 1))
par(oma=c(1, 1, 1, 1))

# Prepare fitmeasures
ParDF  <- as.data.frame(do.call(cbind, Fit05@ParTable))
EffHed <- round(as.numeric(ParDF[ParDF$label == "EffHed", 14]), 4)
EffHrt <- round(as.numeric(ParDF[ParDF$label == "EffHrt", 14]), 4)
EffHnd <- round(as.numeric(ParDF[ParDF$label == "EffHnd", 14]), 4)
n      <- Fit05@SampleStats@ntotal

fitMeas <- toString(c("ChiSq: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "chisq"))), 4),
            " - ChiSq-p: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "pvalue"))), 4),
            " - DF: ", gsub("[^0-9.]", "", fitMeasures(Fit05, "df")),
            " - ChiSq/DF: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "chisq")))/ as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "df"))), 4),
            " - CFI: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "cfi"))), 4),
            " - TLI: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "tli"))), 4),
            " - RMSEA: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "rmsea"))), 4),
            " - SRMR: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "srmr"))), 4),
            " - n: ", n,
            " - EffHed: ", EffHed,
            " - EffHrt: ", EffHrt,
            " - EffHnd: ", EffHnd
            ), 
            width = 255)
fitMeas <- gsub(",", "", fitMeas)

# Plot model
semPaths(Fit05, what = "eq", whatLabels = "stand", intercepts = FALSE, residuals = TRUE, 
         edge.label.cex = 0.7, edge.color = "blue", layout = "circle2", rotation = 3, curve = 1,          curvePivot = TRUE, mar = c(3,1,5,1), sizeLat = 7, sizeMan = 4, color = colorlist,
         style = "lisrel")
title(main = "Model 5: Showing Head -> Hand -> IWB with Heart as Mediator\nEstimator: WLSMV - 76 Raters",
      cex.main = 2.5, col.main = "darkblue", font.main = 3, sub = fitMeas, cex.sub = 1.4)

if (makePDF) {
  dev.off()
}

5.7 Build Model: Head -> Hand -> IWB with Heart as Mediator (DWLS) - 76 Raters

# Loading necessary packages
if(! "lavaan" %in% installed.packages()) {install.packages("lavaan", dependencies = TRUE) }
library(lavaan)

Model05 <- '

# latent variables
 IWB =~ IWB01 + IWB02 + IWB03 + IWB04 + IWB05 + IWB06 + IWB07 + IWB08 + IWB09

 Head  =~ SN01 + SN02 + SN03 + SN04 + SN05 + SN07 + SN08 + SN09 + SN10 + SN11 + SN12
 Heart =~ SN13 + SN14 + SN15 + SN16 + SN17 + SN18 
 Hand  =~ SN20 + SN21 + SN22 + SN23 + SN24 + SN25 + SN26 + SN27 + SN28 + SN30 + SN31 + SN32 + SN33 + SN34

# direct effect
 IWB   ~ a * Hand
 Hand  ~ d * Head

 EffHnd := a

# mediator
 Hand  ~ b * Heart
 Heart ~ c * Head

# indirect effect

 EffHrt := a * b
 EffHed := a * (d + b * c)

'

# Calculate fit
Fit05 <- sem(Model05, data = dfVal, estimator = "DWLS")

# Print results (fit indices, parameters, hypothesis tests)
summary(Fit05, fit.measures = TRUE, rsquare = TRUE)
## lavaan 0.6-12 ended normally after 74 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                        84
## 
##   Number of observations                            76
## 
## Model Test User Model:
##                                                       
##   Test statistic                                42.202
##   Degrees of freedom                               736
##   P-value (Chi-square)                           1.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              9475.041
##   Degrees of freedom                               780
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.085
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value RMSEA <= 0.05                          1.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.042
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   IWB =~                                              
##     IWB01             1.000                           
##     IWB02             0.924    0.061   15.275    0.000
##     IWB03             0.946    0.055   17.171    0.000
##     IWB04             0.685    0.044   15.677    0.000
##     IWB05             0.877    0.055   15.898    0.000
##     IWB06             0.892    0.053   16.790    0.000
##     IWB07             0.843    0.055   15.364    0.000
##     IWB08             0.861    0.053   16.166    0.000
##     IWB09             0.833    0.053   15.856    0.000
##   Head =~                                             
##     SN01              1.000                           
##     SN02              1.197    0.080   15.007    0.000
##     SN03              1.019    0.068   14.924    0.000
##     SN04              1.171    0.080   14.559    0.000
##     SN05              1.041    0.074   14.016    0.000
##     SN07              1.140    0.076   14.909    0.000
##     SN08              1.040    0.071   14.564    0.000
##     SN09              1.005    0.072   14.018    0.000
##     SN10              1.106    0.075   14.825    0.000
##     SN11              1.022    0.070   14.508    0.000
##     SN12              1.050    0.073   14.353    0.000
##   Heart =~                                            
##     SN13              1.000                           
##     SN14              0.448    0.037   12.008    0.000
##     SN15              0.955    0.070   13.577    0.000
##     SN16              0.861    0.068   12.756    0.000
##     SN17              1.127    0.080   14.037    0.000
##     SN18              1.276    0.089   14.409    0.000
##   Hand =~                                             
##     SN20              1.000                           
##     SN21              0.932    0.061   15.242    0.000
##     SN22              0.974    0.063   15.478    0.000
##     SN23              0.851    0.058   14.729    0.000
##     SN24              0.992    0.065   15.302    0.000
##     SN25              0.991    0.068   14.651    0.000
##     SN26              0.934    0.064   14.694    0.000
##     SN27              1.094    0.070   15.703    0.000
##     SN28              0.970    0.063   15.377    0.000
##     SN30              0.851    0.059   14.541    0.000
##     SN31              0.981    0.064   15.308    0.000
##     SN32              1.024    0.066   15.486    0.000
##     SN33              1.063    0.068   15.586    0.000
##     SN34              0.970    0.064   15.183    0.000
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   IWB ~                                               
##     Hand       (a)    0.986    0.065   15.224    0.000
##   Hand ~                                              
##     Head       (d)    0.736    0.308    2.389    0.017
##     Heart      (b)    0.362    0.321    1.127    0.260
##   Heart ~                                             
##     Head       (c)    0.895    0.080   11.245    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .IWB01             0.271    0.256    1.058    0.290
##    .IWB02             0.430    0.247    1.739    0.082
##    .IWB03             0.427    0.174    2.450    0.014
##    .IWB04             0.484    0.136    3.555    0.000
##    .IWB05             0.360    0.194    1.854    0.064
##    .IWB06             0.558    0.214    2.609    0.009
##    .IWB07             0.546    0.185    2.943    0.003
##    .IWB08             0.522    0.251    2.079    0.038
##    .IWB09             0.596    0.244    2.446    0.014
##    .SN01              0.347    0.293    1.186    0.236
##    .SN02              0.273    0.292    0.935    0.350
##    .SN03              0.285    0.234    1.219    0.223
##    .SN04              0.319    0.355    0.900    0.368
##    .SN05              0.299    0.315    0.948    0.343
##    .SN07              0.257    0.277    0.928    0.354
##    .SN08              0.252    0.255    0.987    0.324
##    .SN09              0.235    0.290    0.810    0.418
##    .SN10              0.259    0.264    0.979    0.327
##    .SN11              0.236    0.248    0.950    0.342
##    .SN12              0.232    0.269    0.860    0.390
##    .SN13              0.285    0.290    0.984    0.325
##    .SN14              0.416    0.115    3.615    0.000
##    .SN15              0.272    0.243    1.118    0.263
##    .SN16              0.323    0.252    1.280    0.201
##    .SN17              0.189    0.291    0.650    0.516
##    .SN18              0.270    0.338    0.800    0.423
##    .SN20              0.321    0.278    1.152    0.249
##    .SN21              0.210    0.259    0.813    0.416
##    .SN22              0.209    0.270    0.775    0.438
##    .SN23              0.306    0.260    1.178    0.239
##    .SN24              0.311    0.271    1.147    0.252
##    .SN25              0.350    0.369    0.948    0.343
##    .SN26              0.332    0.293    1.130    0.258
##    .SN27              0.153    0.309    0.496    0.620
##    .SN28              0.293    0.254    1.155    0.248
##    .SN30              0.203    0.264    0.770    0.441
##    .SN31              0.200    0.285    0.702    0.482
##    .SN32              0.462    0.333    1.385    0.166
##    .SN33              0.217    0.297    0.731    0.465
##    .SN34              0.200    0.267    0.750    0.453
##    .IWB               0.042    0.051    0.831    0.406
##     Head              0.770    0.080    9.618    0.000
##    .Heart             0.124    0.083    1.493    0.135
##    .Hand              0.010    0.039    0.250    0.802
## 
## R-Square:
##                    Estimate
##     IWB01             0.770
##     IWB02             0.643
##     IWB03             0.656
##     IWB04             0.469
##     IWB05             0.660
##     IWB06             0.564
##     IWB07             0.542
##     IWB08             0.564
##     IWB09             0.514
##     SN01              0.689
##     SN02              0.801
##     SN03              0.738
##     SN04              0.768
##     SN05              0.737
##     SN07              0.795
##     SN08              0.767
##     SN09              0.768
##     SN10              0.785
##     SN11              0.774
##     SN12              0.785
##     SN13              0.722
##     SN14              0.263
##     SN15              0.713
##     SN16              0.630
##     SN17              0.832
##     SN18              0.817
##     SN20              0.735
##     SN21              0.786
##     SN22              0.802
##     SN23              0.678
##     SN24              0.738
##     SN25              0.714
##     SN26              0.701
##     SN27              0.874
##     SN28              0.741
##     SN30              0.760
##     SN31              0.811
##     SN32              0.669
##     SN33              0.823
##     SN34              0.807
##     IWB               0.954
##     Heart             0.832
##     Hand              0.989
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     EffHnd            0.986    0.065   15.224    0.000
##     EffHrt            0.357    0.317    1.128    0.259
##     EffHed            1.046    0.082   12.733    0.000
modificationIndices(Fit05, minimum.value = 5)
## [1] lhs      op       rhs      mi       epc      sepc.lv  sepc.all sepc.nox
## <0 rows> (or 0-length row.names)

5.8 Plot Model - (DWLS) 76 Raters

# Loading necessary packages
if(! "semPlot" %in% installed.packages()) {install.packages("semPlot", dependencies = TRUE) }
library(semPlot)

# Setting working Directory
setwd("~/AB PRIVATE/01 Amy/AB Amy PhD/Part 3/Data/Study3")

# Prepare PDF for Model 05
if (makePDF) {
  pdf(paste(today, "Model05.pdf"), width = 25, height = 25)
}
par(mar=c(7, 1, 7, 1))
par(oma=c(1, 1, 1, 1))

# Prepare fitmeasures
ParDF  <- as.data.frame(do.call(cbind, Fit05@ParTable))
EffHed <- round(as.numeric(ParDF[ParDF$label == "EffHed", 14]), 4)
EffHrt <- round(as.numeric(ParDF[ParDF$label == "EffHrt", 14]), 4)
EffHnd <- round(as.numeric(ParDF[ParDF$label == "EffHnd", 14]), 4)
n      <- Fit05@SampleStats@ntotal

fitMeas <- toString(c("ChiSq: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "chisq"))), 4),
            " - ChiSq-p: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "pvalue"))), 4),
            " - DF: ", gsub("[^0-9.]", "", fitMeasures(Fit05, "df")),
            " - ChiSq/DF: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "chisq")))/ as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "df"))), 4),
            " - CFI: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "cfi"))), 4),
            " - TLI: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "tli"))), 4),
            " - RMSEA: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "rmsea"))), 4),
            " - SRMR: ", round(as.numeric(gsub("[^0-9.]", "", fitMeasures(Fit05, "srmr"))), 4),
            " - n: ", n,
            " - EffHed: ", EffHed,
            " - EffHrt: ", EffHrt,
            " - EffHnd: ", EffHnd
            ), 
            width = 255)
fitMeas <- gsub(",", "", fitMeas)

# Plot model
semPaths(Fit05, what = "eq", whatLabels = "stand", intercepts = FALSE, residuals = TRUE, 
         edge.label.cex = 0.7, edge.color = "blue", layout = "circle2", rotation = 3, curve = 1,          curvePivot = TRUE, mar = c(3,1,5,1), sizeLat = 7, sizeMan = 4, color = colorlist,
         style = "lisrel")
title(main = "Model 5: Showing Head -> Hand -> IWB with Heart as Mediator\nEstimator: DWLS - 76 Raters",
      cex.main = 2.5, col.main = "darkblue", font.main = 3, sub = fitMeas, cex.sub = 1.4)

if (makePDF) {
  dev.off()
}