Complex data anaysis in REM doesn't result
Posted on
vildan Bağcı
Joined: 12/04/2019
Attachment | Size |
---|---|
syntax form metasem | 114.44 KB |
Forums
Dear Mike & colleagues,
First of all, I am grateful for asking my question to this forum where gurus of meta-SEM are helping people like me.
I'm trying to make analysis in your metasem package. I have 41 studies and so 41 correlation matrices. and the correlation matrices consist of 20x20.
While i was anaysing the data under the fixed effects model, the results came after a long time. But while i'm trying to analyse under the random effect model, the analysis is running but no results even though I wait a long time. Why i can not take the result, becouse of amount of matrices or items/complex data?
First of all, I am grateful for asking my question to this forum where gurus of meta-SEM are helping people like me.
I'm trying to make analysis in your metasem package. I have 41 studies and so 41 correlation matrices. and the correlation matrices consist of 20x20.
While i was anaysing the data under the fixed effects model, the results came after a long time. But while i'm trying to analyse under the random effect model, the analysis is running but no results even though I wait a long time. Why i can not take the result, becouse of amount of matrices or items/complex data?
May I ask how can handle this problem?
Thanks for your time and patience.
(i added my syntax for you to review )
Hi vildan,
For the fixed-effects model, you are fitting a multiple-group analysis with 41 groups. For the random-effects model, there are 20x19/2 random effects. Both of them are computationally intensive. It may take a long time to run them. It may be better to run these analyses in High-performance computing (HPC) computers.
BTW, I have modified the code a bit for your reference. I hope it works.
## Add the variable labels to the data
var.names <- paste0("x", 1:20)
ucla <- lapply(ucla, function(x) {dimnames(x) <- list(var.names, var.names); x})
## First stage of the analysis
random1 <- tssem1(ucla, n, method="REM")
summary(random1)
## Create the model in lavaan syntax
model <- paste0("f =~ ", paste0("x", 1:20, collapse = "+"))
## Plot it for checking
plot(model)
## Convert it into RAM specification
RAM1 <- lavaan2RAM(model, obs.variables = var.names)
RAM1
## Second stage of the analysis
random2 <- tssem2(random1, RAM=RAM1)
summary(random2)
## Plot the results
plot(random2)
Best,
Mike
Log in or register to post comments
In reply to Hi vildan, by Mike Cheung
Dear all,
I have 32 correlation matrices (6 rows x 6 columns) from 30 studies that all used the same questionnaire.
For one model, I am using 5 of the 6 variables that are modeled to be correlated with each other (i.e., variable 1 and 2, 1 and 3...). My tssem2 code (stage 2 random effects model) for the metaSEM package kept running for 47 days and stopped with a warning that it ran out of memory (my computer has 64gb memory). I executed the code on a few different computers of similar cpu and ram specs and I had the same warning message. To analyze the model, should I
(1) use high performance computing (HPC) services, following Mike's advice above. My random-effects model has 5x4/2 random effects (I am analyzing 5 of the 6 variables). So, is this really computationally intensive enough to use HPC? I thought my model was small and simple to estimate...
(2) write a more computer-friendly code (consuming less memory) after reading books such as "Advanced R"? This sounds like really technical.
(3) any other alternatives?
I have attached my code (that includes the data). In the file, my question is related to this line:
stage2random_model1 <- tssem2(stage1random, RAM=RAM1, diag.constraints=FALSE,
intervals.type="LB")# This model takes a long time to estimate.
Thanks very much,
Yo
Yo In'nami (first name-last name; male)
Professor
Division of English Language Education
Faculty of Science and Engineering
Chuo University
1-13-27 Kasuga, Bunkyo-ku, Tokyo 112-8551, Japan
+81-3-3817-1950
innami@tamacc.chuo-u.ac.jp
https://sites.google.com/site/yoinnami/
Log in or register to post comments
Dear Yo,
This model is not computationally intensive.
The tssem2 function uses some tricks to handle correlation structure properly. However, the limitation is that the model cannot be a correlation structure without any direct paths. I would consider it as a bug.
If you change the models to regression models or other path models, it takes seconds to fit them.
Best,
Mike
Log in or register to post comments
Hi Mike,
Thanks very much for your comment. Now I can better understand how the tssem2 function works. That also explains why I haven't seen examples like mine in your books and websites.
I'd like to obtain a synthesized inter-correlation matrix of six observed variables to examine my research question. The best I can is to report on the tssem1 (not tssem2) results? They are a pooled correlation matrix and I assume I could use that to examine the research question.
I also tried one-stage MASEM before posting my previous question. It kept running... and I had to terminate it forcefully.
## One-stage meta-analytic structural equation modeling
## Convert correlation matrices into a dataframe
my.df <- Cor2DataFrame(cordat5variables, N2)
my.df
head(my.df$data)
# Fit the OSMASEM
fit0 <- osmasem(model.name="No moderator", RAM=RAM1, data=my.df)# This model takes a long time to estimate.
Further, I also tested a one-factor model with my data using the tssem2 function. It was estimated in a second and fit nicely.
Cheers,
Yo
Log in or register to post comments
Hi Yo,
RE: I'd like to obtain a synthesized inter-correlation matrix of six observed variables to examine my research question. The best I can is to report on the tssem1 (not tssem2) results? They are a pooled correlation matrix and I assume I could use that to examine the research question.
Yes.
RE: I also tried one-stage MASEM before posting my previous question. It kept running... and I had to terminate it forcefully.
If your models are the same in the tssem2() and osmasem(), please refer to my reply related to tssem2().
Best,
Mike
Log in or register to post comments
Hi Mike,
Thanks to your comment, I can now better understand how to proceed with my study.
I don't know how to thank you enough for taking time from your busy schedule to respond to my question.
Very best wishes,
Yo
Log in or register to post comments
Variance freed, but still warned to make it free
As my dependent variable is a single-indicator model, I fixed the residual variance of the observed variable at (1– reliability)*(measurement variance). I received this warning: "The variances of the dependent variables in 'Smatrix' should be free." To address this, the variance of the measure was freed. However, I still receive the warning.
I checked the checkRAM function used in the metaSEM, but the limitation of the function below does not apply to my case. I haven't fixed parameters in A.
## Check both A and S: Variances of IVs must be fixed at 1 and DVs must be free
## Limitation: it may still give warnings when there are DVs with fixed parameters in A
https://rdrr.io/cran/metaSEM/src/R/checkRAM.R
(1) Would you please advise as to how to revise my code? I thought fixing the variance was necessary to identify a single-indicator model but is not allowed in the metaSEM?
(2) Regardless of fixing the residual variance of the observed variable, the results are almost the same (with the same degrees of freedom). Does this mean such fixing is not necessary for a single-indicator model in the metaSEM?
I have attached the output and code files.
Thank you very much,
Yo
Yo In'nami (first name-last name; male)
Professor
Division of English Language Education
Faculty of Science and Engineering
Chuo University
1-13-27 Kasuga, Bunkyo-ku, Tokyo 112-8551, Japan
+81-3-3817-1950
innami@tamacc.chuo-u.ac.jp
https://sites.google.com/site/yoinnami/
Log in or register to post comments
Hi Yo,
Since the variances of the dependent variables are functions of other parameters in the analysis of the correlation matrix, these variances are not free parameters. It is advisable not to fix them.
Second, there is only one indicator on the latent variable LCompre. It would help if you replaced the LCompre with its observed variable LC.
Mike
Log in or register to post comments
Hi Mike,
As for the first point, thanks very much. I have understood your point.
As for the second point, I had, in fact, analyzed the data as you have suggested, before posting the questions. The results were almost the identical to those from the current analysis (with a different degree of freedom). The issue was that the six observed variables all loaded on the same, single factor. That was theoretically not something I wanted to examine. Thus, I have thought of constructing a single-indicator model that only consisted of the observed variable LC. This way, I can separately model LC from the remaining five observed variables that constituted another factor.
So, would it be sensible to ignore the warning "The variances of the dependent variables in 'Smatrix' should be free."? Even after freeing the variance of the dependent variable, I have received the warning.
Yo
Log in or register to post comments
Hi Yo,
If you don't fix the measurement error related to the reliability, the two models are equivalent. Since the dfs are different, it indicates that something is wrong here.
Regarding the issue of fixing the measurement error related to reliability, it isn't very easy. There are at least two issues here: (1) correlation matrices are used here. Therefore, the diagonals of the model implied correlation matrices must be one. (2) The sampling error of a correlation has already been fixed for each study. Therefore, it is not clear how the measurement error can be added to the model.
Mike
Log in or register to post comments
Hi Mike,
I have been unable to locate the parameter that should be freed to make the two models (i.e., my model and your model) equivalent. May I ask which parameter to free? In particular, I have freed the measurement error related to the reliability (LC). The model's degrees of freedom are 8.
$S
LC DA MT PK PE PS META LCompre
LC "0*LCWITHLC" "0" "0" "0" "0" "0" "0" "0"
DA "0" "0*DAWITHDA" "0" "0" "0" "0" "0" "0"
MT "0" "0" "0*MTWITHMT" "0" "0" "0" "0" "0"
PK "0" "0" "0" "0*PKWITHPK" "0" "0" "0" "0"
PE "0" "0" "0" "0" "0*PEWITHPE" "0" "0" "0"
PS "0" "0" "0" "0" "0" "0*PSWITHPS" "0" "0"
META "0" "0" "0" "0" "0" "0" "1" "0"
LCompre "0" "0" "0" "0" "0" "0" "0" "1"
## Goodness-of-fit indices:
## Value
## Sample size 4621.0000
## Chi-square of target model 20.7596
## DF of target model 8.0000 (<--this: Yo)
Your suggested model has degrees of freedom of 9. Your model is this: "Second, there is only one indicator on the latent variable LCompre. It would help if you replaced the LCompre with its observed variable LC." I cannot match the df of my model (i.e., 8) to that of your model (i.e., 9). There is an error in my code.
> model3a <- '## Metacognitive strategy factor (META) is measured by DA, MT, PK, PE, and PS
+ META =~ METAonDA*DA + METAonMT*MT + METAonPK*PK + METAonPE*PE + METAonPS*PS
+ ## LC is regressed on META
+ LC ~ LCompreMETA*META'
>
> plot(model3a, col="yellow", layout="spring")
> RAM3a <- lavaan2RAM(model3a, obs.variables=c("LC", "DA", "MT", "PK", "PE", "PS"))
>
> RAM3a
$A
LC DA MT PK PE PS META
LC "0" "0" "0" "0" "0" "0" "0*LCompreMETA"
DA "0" "0" "0" "0" "0" "0" "0*METAonDA"
MT "0" "0" "0" "0" "0" "0" "0*METAonMT"
PK "0" "0" "0" "0" "0" "0" "0*METAonPK"
PE "0" "0" "0" "0" "0" "0" "0*METAonPE"
PS "0" "0" "0" "0" "0" "0" "0*METAonPS"
META "0" "0" "0" "0" "0" "0" "0"
$S
LC DA MT PK PE PS META
LC "0*LCWITHLC" "0" "0" "0" "0" "0" "0"
DA "0" "0*DAWITHDA" "0" "0" "0" "0" "0"
MT "0" "0" "0*MTWITHMT" "0" "0" "0" "0"
PK "0" "0" "0" "0*PKWITHPK" "0" "0" "0"
PE "0" "0" "0" "0" "0*PEWITHPE" "0" "0"
PS "0" "0" "0" "0" "0" "0*PSWITHPS" "0"
META "0" "0" "0" "0" "0" "0" "1"
$F
LC DA MT PK PE PS META
LC 1 0 0 0 0 0 0
DA 0 1 0 0 0 0 0
MT 0 0 1 0 0 0 0
PK 0 0 0 1 0 0 0
PE 0 0 0 0 1 0 0
PS 0 0 0 0 0 1 0
$M
LC DA MT PK PE PS META
1 0 0 0 0 0 0 0
> stage2random_model3a <- tssem2(stage1random2, RAM=RAM3a, diag.constraints=FALSE, intervals.type="LB")
> summary(stage2random_model3a)
Call:
wls(Cov = pooledS, aCov = aCov, n = tssem1.obj$total.n, RAM = RAM,
Amatrix = Amatrix, Smatrix = Smatrix, Fmatrix = Fmatrix,
diag.constraints = diag.constraints, cor.analysis = cor.analysis,
intervals.type = intervals.type, mx.algebras = mx.algebras,
model.name = model.name, suppressWarnings = suppressWarnings,
silent = silent, run = run)
95% confidence intervals: Likelihood-based statistic
Coefficients:
Estimate Std.Error lbound ubound z value Pr(>|z|)
METAonDA 0.591859 NA 0.531698 0.653155 NA NA
LCompreMETA 0.312846 NA 0.252824 0.373454 NA NA
METAonMT 0.151865 NA 0.061752 0.241867 NA NA
METAonPE 0.616426 NA 0.560325 0.676011 NA NA
METAonPK 0.232201 NA 0.169570 0.295090 NA NA
METAonPS 0.755402 NA 0.690348 0.824983 NA NA
Goodness-of-fit indices:
Value
Sample size 4621.0000
Chi-square of target model 20.7596
DF of target model 9.0000 (<--this: Yo)
If I use "std.lv=FALSE", I no longer get the warning "The variances of the dependent variables in 'Smatrix' should be free." However, there is still a difference in the degrees of freedom between my model and your model.
> RAM3 <- lavaan2RAM(model3, obs.variables=c("LC", "DA", "MT", "PK", "PE", "PS"), std.lv=FALSE)
> RAM3
$S
LC DA MT PK PE PS META LCompre
LC "0*LCWITHLC" "0" "0" "0" "0" "0" "0" "0"
DA "0" "0*DAWITHDA" "0" "0" "0" "0" "0" "0"
MT "0" "0" "0*MTWITHMT" "0" "0" "0" "0" "0"
PK "0" "0" "0" "0*PKWITHPK" "0" "0" "0" "0"
PE "0" "0" "0" "0" "0*PEWITHPE" "0" "0" "0"
PS "0" "0" "0" "0" "0" "0*PSWITHPS" "0" "0"
META "0" "0" "0" "0" "0" "0" "1" "0"
LCompre "0" "0" "0" "0" "0" "0" "0" "0*LCompreWITHLCompre"
Goodness-of-fit indices:
Value
Sample size 4621.0000
Chi-square of target model 20.7596
DF of target model 8.0000 (<--this: Yo)
In the meantime, to explore another model, I have correlated the META factor with LC. The results say " The variances of the independent variables in 'Smatrix' must be fixed at 1." May I ask which parameter to fix? I have unsuccessfully attempted to do so...
$S
LC DA MT PK PE PS META
LC "0*LCWITHLC" "0" "0" "0" "0" "0" "0*LCompreMETA"
DA "0" "0*DAWITHDA" "0" "0" "0" "0" "0"
MT "0" "0" "0*MTWITHMT" "0" "0" "0" "0"
PK "0" "0" "0" "0*PKWITHPK" "0" "0" "0"
PE "0" "0" "0" "0" "0*PEWITHPE" "0" "0"
PS "0" "0" "0" "0" "0" "0*PSWITHPS" "0"
META "0*LCompreMETA" "0" "0" "0" "0" "0" "1"
I'm sorry I'm asking too much.
Yo
Log in or register to post comments
Hi Yo,
Please see the attached PDF that shows two equivalent models--one with a latent variable and one without any latent variable.
Mike
Log in or register to post comments
Hi Mike,
Thanks very much for your help. I have been able to reproduce the results. Referring to your examples and past answers to this forum, I always thought that the intervals.type="LB" works better than the intervals.type="z" and that diag.constraints=FALSE works better than diag.constraints=TRUE. I will be more careful when I analyze models in the future.
Best wishes,
Yo
Log in or register to post comments
Hi Yo,
Yes. intervals.type="LB" should be preferable. But intervals.type="z" works much faster.
diag.constraints=FALSE and diag.constraints=TRUE are usually the same. But they are different in this case because there is a latent variable with 0 variance. diag.constraints=FALSE, which does not consider the error variance as a parameter, does not work here.
Best,
Mike
Log in or register to post comments
In reply to Hi Yo, by Mike Cheung
Regarding the diag.constraints=TRUE
My name is Chloe. I was hoping to ask for some clarification regarding the usage of 'Smatrix' and the choice of diagnostic constraints. I have a similar task as the one mentioned in this post. My model has two latent variables, each with two indicators. I received a warning stating that "The variances of dependent variables in 'Smatrix' should be free." My understanding is that the residual variance of the latent variable should not be constrained to 1 because it is influenced by other variables in the model. After manually setting the Smatrix, the warning no longer appears.
However, I am confused about why here you chose diag.constraints=TRUE, as I thought the residual variance of the (dependent) latent variables should not be constrained. I may have misunderstood something, so I would greatly appreciate your help in clarifying this.
Thank you,
Chloe
Log in or register to post comments
In reply to Regarding the diag.constraints=TRUE by jennies001
Hi Chloe,
Let's assume a simple example: y = b1*x + e.
var(y) =b1^2*var(x) + var(e)
Since the data are standardized, var(y)=var(x)=1. Then, 1=b1^2+var(e).
The above example also applies to latent and observed variables.
The metaSEM package uses two approaches. The first one applies nonlinear constraints on the diagonals (diag.constraints=TRUE) to ensure 1=b12+var(e). The second approach only considers b1 as a parameter, whereas var(e) is not a parameter at all (diag.constraints=FALSE). Then, the program calculates var(e) by using 1-b12.
Both approaches should give the exact parameter estimates and model fit.
Mike
Log in or register to post comments
Hi Mike,
Your responses have really helped me learn a lot about how the metaSEM package works. I don't know how to thank you enough.
Cheers,
Yo
Log in or register to post comments