You are here

Help: TSSEM Mediation model

6 posts / 0 new
Last post
Kwabenaaaddo's picture
Offline
Joined: 02/01/2021 - 08:16
Help: TSSEM Mediation model
AttachmentSize
Binary Data R codes2.9 KB
File data31.9 KB
Image icon Screenshot 2024-04-12 at 01.04.31.png360.02 KB

Dear community,

I trust you are doing well. Thank you very much for your immense work in structural equation modelling. I'm contacting you because I'm currently working on a research project that involves implementing a two-step structural equation model.

I got an error when I implemented the command to run the first-stage model (I've attached the document). From here, I do not particularly understand how to proceed. I have attached the codes and the data to aid you. I would be grateful if you could help me identify the error and, if convenient, with the right codes.

Once again, thank you very much, and I look forward to your response.

Kindest Regards,

Mike Cheung's picture
Offline
Joined: 10/08/2009 - 22:37
There are errors in the data,

There are errors in the data, such as correlation coefficients with minimum and maximum values of -550 and 1.188, respectively (see the end of the outputs), which are clearly invalid.

my.data <- read.csv("./data_7.csv")
 
#Load MetaSEM package
library(metaSEM)
 
# locate studies with information on at least 1 correlation, and no missing sample size
keepstudy <- rowSums(is.na(my.data[,2:37]))!=36 & is.na(my.data$NUMBER.OF.BANKS)==FALSE
# keep only the studies with information
data <- my.data[keepstudy,]
 
# check data
head(data)
 
##   Study_id X1_X2  X1_X3 X1_X4 X1_X5  X1_X6 X1_X7 X1_X8      X1  X2_X3 X2_X4
## 1        2 0.075 0.1625    NA  0.05 0.1375    NA    NA  0.0375 0.4125    NA
## 2        2 0.075 0.1625    NA  0.05 0.1375    NA    NA  0.0375 0.4125    NA
## 3        2 0.075 0.1625    NA  0.05 0.1375    NA    NA  0.0250 0.4125    NA
## 4        2 0.075 0.1625    NA  0.05 0.1375    NA    NA  0.0375 0.4125    NA
## 5        2 0.075 0.1625    NA  0.05 0.1375    NA    NA -0.1000 0.4125    NA
## 6        2 0.075 0.1625    NA  0.05 0.1375    NA    NA -0.0125 0.4125    NA
##   X2_X5 X2_X6 X2_X7 X2_X8      X2 X3_X4  X3_X5 X3_X6 X3_X7 X3_X8      X3 X4_X5
## 1  0.05 0.175    NA    NA -0.2250    NA 0.0125 0.225    NA    NA -0.1125    NA
## 2  0.05 0.175    NA    NA -0.2500    NA 0.0125 0.225    NA    NA -0.1750    NA
## 3  0.05 0.175    NA    NA -0.2000    NA 0.0125 0.225    NA    NA -0.1250    NA
## 4  0.05 0.175    NA    NA -0.2625    NA 0.0125 0.225    NA    NA -0.1625    NA
## 5  0.05 0.175    NA    NA -0.2625    NA 0.0125 0.225    NA    NA -0.1875    NA
## 6  0.05 0.175    NA    NA -0.1875    NA 0.0125 0.225    NA    NA -0.0500    NA
##   X4_X6 X4_X7 X4_X8 X4 X5_X6 X5_X7 X5_X8     X5 X6_X7 X6_X8      X6 X7_X8 X7 X8
## 1    NA    NA    NA NA -0.05    NA    NA 0.0750    NA    NA -0.0750    NA NA NA
## 2    NA    NA    NA NA    NA    NA    NA 0.4250    NA    NA -0.0125    NA NA NA
## 3    NA    NA    NA NA    NA    NA    NA 0.2375    NA    NA  0.0000    NA NA NA
## 4    NA    NA    NA NA    NA    NA    NA 0.3250    NA    NA -0.0375    NA NA NA
## 5    NA    NA    NA NA    NA    NA    NA 0.2500    NA    NA -0.1625    NA NA NA
## 6    NA    NA    NA NA    NA    NA    NA 0.0375    NA    NA -0.0250    NA NA NA
##   BANK.YEAR.OX1 NUMBER.OF.BANKS
## 1          2426             212
## 2          2426             212
## 3          2426             212
## 4          2426             212
## 5          2426             212
## 6          2426             212
 
length(data)
 
## [1] 39
 
## summary(data)
 
# varnames and labels
nvar <- 9
varnames <- c("X1","X2","X3","X4","X5","X6","X7","X8","X9")
labels <- list(varnames,varnames)
# create list with correlation matrices
cordat <- list()
for (i in 1:nrow(data)){    
  cordat[[i]] <- vec2symMat(as.matrix(data[i,2:37]),diag = FALSE)
  dimnames(cordat[[i]]) <- labels
}
# put NA on diagonal of correlation matrix if variable is missing
for (i in 1:length(cordat)){
  for (j in 1:nrow(cordat[[i]])){   
    if (sum(is.na(cordat[[i]][j,]))==nvar-1) 
    {cordat[[i]][j,j] <- NA}
  }}
 
# show number of studies per correlation coefficient
pattern.na(cordat, show.na = FALSE)
 
##     X1  X2 X3 X4  X5  X6 X7 X8  X9
## X1 219 173 66 69 147 179 42 78 189
## X2 173 198 51 64 125 150 36 60 168
## X3  66  51 69 25  50  61 17 34  62
## X4  69  64 25 86  55  72 18 28  66
## X5 147 125 50 55 196 154 29 60 163
## X6 179 150 61 72 154 236 40 78 204
## X7  42  36 17 18  29  40 48  9  44
## X8  78  60 34 28  60  78  9 93  81
## X9 189 168 62 66 163 204 44 81 249
 
# show total N per correlation coefficient
pattern.n(cordat, data$NUMBER.OF.BANKS)
 
##       X1    X2    X3    X4    X5    X6   X7    X8    X9
## X1 20434 13161 11296  6655 15604 18361 2349 10004 16931
## X2 13161 15875  5859  7623 11027 12986 2196  5282 12268
## X3 11296  5859 11543  3248  9824 10696 1013  6478 10129
## X4  6655  7623  3248 29544 12872 27613 1374 22770 26661
## X5 15604 11027  9824 12872 44614 41298 1753 28733 40607
## X6 18361 12986 10696 27613 41298 47652 2338 30099 44030
## X7  2349  2196  1013  1374  1753  2338 2539   667  2160
## X8 10004  5282  6478 22770 28733 30099  667 30881 29667
## X9 16931 12268 10129 26661 40607 44030 2160 29667 45661
 
cordat <- lapply(cordat, function(x) {diag(x) <- 1; x})
 
summary(unlist(cordat))
 
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's 
## -550.000   -0.025    0.178    0.217    1.000    1.188    14626
Kwabenaaaddo's picture
Offline
Joined: 02/01/2021 - 08:16
Dear Mike,

Dear Mike,

Thank you for the prompt response. Your answer helped helped. I have one more concern: Is it problematic if the TSSEM estimation returns a CFI of 0.265?

Thank you once again.

Regards

Regards

Mike Cheung's picture
Offline
Joined: 10/08/2009 - 22:37
It is very strange that the

It is very strange that the CFI is so bad, especially for a mediation model. There is probably something wrong in your model or data.

Kwabenaaaddo's picture
Offline
Joined: 02/01/2021 - 08:16
Hi Mike,

Hi Mike,

Thank you for your response. Can you please give me any pointers as to where I can look to rectify this?

Mike Cheung's picture
Offline
Joined: 10/08/2009 - 22:37
It is hard to tell. One

It is hard to tell. One common issue is that you forget to allow the predictors correlated. This will make the model fit terribly bad.