There is an issue with your data. I recommend investigating the cause, such as whether it is due to using pairwise deletion.
While adjusting the data with near PD may help, the more critical question is whether the results obtained from this modified data can be considered trustworthy.
Thanks, Mike. Do you mean investigating whether the primary studies had used pairwise deletion when calculating their correlations OR investigating whether I, as the meta-analyst, have used some kind of deletion, such as na.omit(data), when preparing my data for meta-analysis??
In my case, several of the primary studies have NOT reported on correlations between some pairs of variables. Therefore, the data prepared for meta-analysis contains many NAs for those pairs of variables which I deleted using listwise deletion.
Thank you, Mike. As I mentioned, several of the primary studies have NOT reported on correlations between some pairs of variables. Therefore, the data prepared for meta-analysis contains many NAs for those pairs of variables which I deleted using listwise deletion i.e., na.omit(data).
Are you suggesting that I don't remove the rows where r values are missing?
I am new with MetaSEM. I am trying to fit a simple meta-analysis (I just want to analyse 2 correlations; see attached file).
Here you can find the code that I am using with some simulated data but if there are no regressions I cannot make it work. It should be an easy model but I am stuck. I just want two covariances and I have fixed all the variances to one.
Correlations between S and D, S and I and D and I are stored here:
Dear Mike, I am trying to test a partial mediation model within the MASem framework, and a possible moderator effect, using subgroup analysis. I followed your instructions (https://suzannejak.nl/OneStageMASEM%20-%20Illustration%201.pdf), and everything went well, until I reached the last command line, when I got an error message (see below). I think I've checked everything, possible code errors, but found nothing. I have attached the whole code; maybe you can help me spot the source of the error. Many thanks! Robert
subgroup.summary (submodels.fit, stage2_constrained.fit) Error in subgroup.summary(submodels.fit, stage2_constrained.fit) : could not find function "subgroup.summary"
bootstrapping of indirect effects
Hi Mike,
Hope you're well. I was just wondering whether there's a simple way to bootstrap the indirect effect in metasem (tssem2 or osmasem).
Thanks,
Best wishes,
Pasco
Log in or register to post comments
meta-analytic SEM, why non positive definite message is thrown?
Hello All,
In my reproducible example below, you'll see that `Cov_R` (sampling covariances for the R matrix) is positive definite.
However, why when I run the following I get an error message saying?:
metaSEM::wls(R, aCov = Cov_R, RAM = RAM3, n = 9201)
> [1] Error: "Cov" is not positive definite.
Thanks,
Simon
#--- Full Reproducible R code:
R <- structure(c(1, 0.5846, 0.5476, 0.4127, 0.6029, 0.5104, 0.4724,
0.4289, 0.5846, 1, 0.2701, 0.4449, 0.3114, 0.3607, 0.5946, 0.605,
0.5476, 0.2701, 1, 0.4459, 0.5791, 0.4243, 0.4671, 0.5854, 0.4127,
0.4449, 0.4459, 1, 0.4677, 0.5889, 0.6848, 0.5456, 0.6029, 0.3114,
0.5791, 0.4677, 1, 0.466, 0.578, 0.607, 0.5104, 0.3607, 0.4243,
0.5889, 0.466, 1, 0.6488, 0.5677, 0.4724, 0.5946, 0.4671, 0.6848,
0.578, 0.6488, 1, 0.3737, 0.4289, 0.605, 0.5854, 0.5456, 0.607,
0.5677, 0.3737, 1), dim = c(8L, 8L), dimnames = list(c("L2R",
"L2DA", "L2DF", "L2V", "L2G", "L2P", "L2M", "L2L"), c("L2R", "L2DA", "L2DF", "L2V", "L2G", "L2P", "L2M", "L2L")))
Cov_R <- structure(c(0.0149, 0.0087, 0.0092, 0.0086, 0.0088, 0.0089, 0.0089,
0.0094, 0.009, 0.0094, 0.0093, 0.0088, 0.0087, 0.0087, 0.0088,
0.0096, 0.0085, 0.0089, 0.0093, 0.0085, 0.009, 0.0087, 0.0087,
0.0086, 0.0085, 0.009, 0.0087, 0.0087, 0.0087, 0.018, 0.0086,
0.0087, 0.0087, 0.0089, 0.0087, 0.0087, 0.0087, 0.0087, 0.0087,
0.0088, 0.0092, 0.0095, 0.0087, 0.0087, 0.0085, 0.0088, 0.0087,
0.0088, 0.0087, 0.0087, 0.0087, 0.0086, 0.0088, 0.0087, 0.0087,
0.0087, 0.0092, 0.0086, 0.0143, 0.0087, 0.0086, 0.0088, 0.0088,
0.0093, 0.0088, 0.009, 0.009, 0.0088, 0.0087, 0.0086, 0.0092,
0.0095, 0.0084, 0.0089, 0.0091, 0.0085, 0.0092, 0.0087, 0.0086,
0.0086, 0.0085, 0.009, 0.0087, 0.0085, 0.0086, 0.0087, 0.0087,
0.0132, 0.0087, 0.0087, 0.0086, 0.0086, 0.0088, 0.0087, 0.0086,
0.0085, 0.0089, 0.0087, 0.0089, 0.0086, 0.0088, 0.0087, 0.0086,
0.0084, 0.0086, 0.0089, 0.0086, 0.0084, 0.0084, 0.0086, 0.0088,
0.0087, 0.0088, 0.0087, 0.0086, 0.0087, 0.0122, 0.0088, 0.0086,
0.0087, 0.0087, 0.009, 0.0087, 0.0085, 0.0087, 0.0089, 0.0086,
0.009, 0.0087, 0.0088, 0.0087, 0.0084, 0.0086, 0.0087, 0.0089,
0.0084, 0.0084, 0.0085, 0.0086, 0.0089, 0.0089, 0.0089, 0.0088,
0.0087, 0.0088, 0.0108, 0.0087, 0.0088, 0.0087, 0.0088, 0.0088,
0.0086, 0.0088, 0.0088, 0.0088, 0.0087, 0.0086, 0.0088, 0.0088,
0.0085, 0.0087, 0.0087, 0.0087, 0.0085, 0.0085, 0.0087, 0.0087,
0.0088, 0.0089, 0.0087, 0.0088, 0.0086, 0.0086, 0.0087, 0.0243,
0.0091, 0.0093, 0.0088, 0.0093, 0.0092, 0.0092, 0.0087, 0.0092,
0.0088, 0.0084, 0.0087, 0.0095, 0.009, 0.009, 0.0087, 0.0086,
0.0088, 0.0089, 0.0091, 0.0088, 0.0085, 0.0094, 0.0087, 0.0093,
0.0086, 0.0087, 0.0088, 0.0091, 0.0181, 0.0091, 0.0092, 0.0093,
0.009, 0.009, 0.0087, 0.0091, 0.0099, 0.0084, 0.0089, 0.0092,
0.0086, 0.0092, 0.0087, 0.0087, 0.0087, 0.0086, 0.0092, 0.0087,
0.0086, 0.009, 0.0087, 0.0088, 0.0088, 0.0087, 0.0087, 0.0093,
0.0091, 0.0238, 0.0092, 0.0094, 0.009, 0.0092, 0.0087, 0.0093,
0.0089, 0.0087, 0.0088, 0.0092, 0.0087, 0.0089, 0.0091, 0.0087,
0.0087, 0.0087, 0.009, 0.0091, 0.0087, 0.0094, 0.0087, 0.009,
0.0087, 0.009, 0.0088, 0.0088, 0.0092, 0.0092, 0.0237, 0.0092,
0.0087, 0.0087, 0.0087, 0.0088, 0.0105, 0.0087, 0.0089, 0.0092,
0.0085, 0.0088, 0.0087, 0.0089, 0.0086, 0.0085, 0.0088, 0.0087,
0.0089, 0.0093, 0.0087, 0.009, 0.0086, 0.0087, 0.0088, 0.0093,
0.0093, 0.0094, 0.0092, 0.014, 0.0089, 0.0089, 0.0087, 0.009,
0.009, 0.0085, 0.0088, 0.0093, 0.0087, 0.009, 0.0088, 0.0087,
0.0087, 0.0086, 0.009, 0.0088, 0.0087, 0.0088, 0.0088, 0.0088,
0.0085, 0.0085, 0.0086, 0.0092, 0.009, 0.009, 0.0087, 0.0089,
0.0163, 0.009, 0.0087, 0.0091, 0.0087, 0.0083, 0.0087, 0.0089,
0.0092, 0.0094, 0.0087, 0.0085, 0.0088, 0.0091, 0.0096, 0.0086,
0.0084, 0.0087, 0.0092, 0.0087, 0.0089, 0.0087, 0.0088, 0.0092,
0.009, 0.0092, 0.0087, 0.0089, 0.009, 0.0237, 0.0092, 0.0092,
0.0087, 0.0086, 0.0088, 0.0088, 0.0088, 0.0088, 0.009, 0.0086,
0.0086, 0.0088, 0.0089, 0.009, 0.0087, 0.0087, 0.0095, 0.0086,
0.0087, 0.0089, 0.0088, 0.0087, 0.0087, 0.0087, 0.0087, 0.0087,
0.0087, 0.0092, 0.0309, 0.0087, 0.0087, 0.0087, 0.0088, 0.0087,
0.0087, 0.0086, 0.0087, 0.0089, 0.0086, 0.0087, 0.0087, 0.0087,
0.009, 0.0088, 0.0087, 0.0092, 0.0089, 0.0086, 0.0088, 0.0092,
0.0091, 0.0093, 0.0088, 0.009, 0.0091, 0.0092, 0.0087, 0.0236,
0.0088, 0.0085, 0.0088, 0.0089, 0.0087, 0.0091, 0.009, 0.0086,
0.0087, 0.0087, 0.0092, 0.0091, 0.0086, 0.0096, 0.0087, 0.0095,
0.0086, 0.009, 0.0087, 0.0088, 0.0099, 0.0089, 0.0105, 0.009,
0.0087, 0.0087, 0.0087, 0.0088, 0.0532, 0.0085, 0.009, 0.0093,
0.0085, 0.0091, 0.0086, 0.009, 0.0085, 0.0085, 0.0088, 0.0086,
0.0086, 0.0085, 0.0085, 0.0084, 0.0088, 0.0087, 0.0086, 0.0084,
0.0084, 0.0087, 0.0087, 0.0085, 0.0083, 0.0086, 0.0087, 0.0085,
0.0085, 0.0161, 0.0086, 0.0085, 0.0082, 0.0084, 0.0087, 0.0087,
0.0083, 0.0082, 0.0084, 0.0087, 0.0087, 0.0089, 0.0088, 0.0089,
0.0087, 0.0088, 0.0088, 0.0087, 0.0089, 0.0088, 0.0089, 0.0088,
0.0087, 0.0088, 0.0088, 0.0088, 0.009, 0.0086, 0.0104, 0.0088,
0.0085, 0.0088, 0.0087, 0.0087, 0.0085, 0.0085, 0.0088, 0.0087,
0.0087, 0.0093, 0.0087, 0.0091, 0.0086, 0.0087, 0.0088, 0.0095,
0.0092, 0.0092, 0.0092, 0.0093, 0.0089, 0.0088, 0.0087, 0.0089,
0.0093, 0.0085, 0.0088, 0.0122, 0.0086, 0.0089, 0.0087, 0.0087,
0.0087, 0.0086, 0.0089, 0.0087, 0.0086, 0.0085, 0.0088, 0.0085,
0.0084, 0.0084, 0.0085, 0.009, 0.0086, 0.0087, 0.0085, 0.0087,
0.0092, 0.0088, 0.0087, 0.0087, 0.0085, 0.0082, 0.0085, 0.0086,
0.011, 0.0088, 0.0085, 0.0084, 0.0086, 0.009, 0.0089, 0.0084,
0.0083, 0.009, 0.0087, 0.0092, 0.0086, 0.0086, 0.0087, 0.009,
0.0092, 0.0089, 0.0088, 0.009, 0.0094, 0.0088, 0.0086, 0.0091,
0.0091, 0.0084, 0.0088, 0.0089, 0.0088, 0.0118, 0.0087, 0.0086,
0.0087, 0.0087, 0.0093, 0.0087, 0.0085, 0.0087, 0.0087, 0.0087,
0.0089, 0.0087, 0.0087, 0.0087, 0.0087, 0.0091, 0.0087, 0.0088,
0.0087, 0.009, 0.0087, 0.009, 0.0086, 0.0087, 0.0087, 0.0087,
0.0085, 0.0087, 0.0124, 0.0086, 0.0085, 0.0085, 0.0087, 0.0089,
0.0086, 0.0087, 0.0087, 0.0086, 0.0086, 0.0089, 0.0087, 0.0086,
0.0087, 0.0087, 0.0089, 0.0087, 0.0085, 0.0086, 0.0089, 0.0086,
0.009, 0.0087, 0.0087, 0.0087, 0.0084, 0.0086, 0.0086, 0.0116,
0.0085, 0.0084, 0.0086, 0.0086, 0.0088, 0.0086, 0.0086, 0.0086,
0.0084, 0.0084, 0.0085, 0.0088, 0.0087, 0.0087, 0.0086, 0.0087,
0.0088, 0.0086, 0.0086, 0.0087, 0.0085, 0.0083, 0.0085, 0.0087,
0.0086, 0.0087, 0.0085, 0.0085, 0.0095, 0.0086, 0.0088, 0.0085,
0.0084, 0.0085, 0.0088, 0.0085, 0.0084, 0.0084, 0.0085, 0.0089,
0.0086, 0.0087, 0.0085, 0.0086, 0.0091, 0.0088, 0.0087, 0.0087,
0.0085, 0.0082, 0.0085, 0.0086, 0.009, 0.0087, 0.0085, 0.0084,
0.0086, 0.011, 0.0089, 0.0084, 0.0083, 0.009, 0.0087, 0.009,
0.0086, 0.0085, 0.0087, 0.0091, 0.0092, 0.009, 0.0088, 0.009,
0.0096, 0.0089, 0.0087, 0.0092, 0.0088, 0.0084, 0.0088, 0.0089,
0.0089, 0.0093, 0.0087, 0.0086, 0.0088, 0.0089, 0.0127, 0.0087,
0.0085, 0.0087, 0.0087, 0.0087, 0.0088, 0.0086, 0.0087, 0.0088,
0.0087, 0.0091, 0.0087, 0.0088, 0.0086, 0.009, 0.0087, 0.0091,
0.0086, 0.0087, 0.0087, 0.0087, 0.0084, 0.0087, 0.0089, 0.0086,
0.0085, 0.0084, 0.0087, 0.013, 0.0086, 0.0087, 0.0087, 0.0085,
0.0087, 0.0089, 0.0088, 0.0085, 0.0086, 0.0087, 0.0089, 0.0087,
0.0084, 0.0087, 0.009, 0.0086, 0.0086, 0.0087, 0.0087, 0.0086,
0.0083, 0.0085, 0.0086, 0.0088, 0.0084, 0.0083, 0.0085, 0.0086,
0.0131), dim = c(28L, 28L))
library(metaSEM)
# Positive definite checks OK:
is.pd(Cov_R, cor.analysis=FALSE)
> [1] TRUE
ModelC <-
'Comprehension =~ L2L + L2V + L2G
Decoding =~ L2DA + L2DF
Meta =~ L2P + L2M
L2R ~ Comprehension + Decoding
Comprehension ~~ 0 * Meta
Decoding ~ 0 * Meta
Comprehension ~~ Decoding'
RAM3 <- lavaan2RAM(ModelC, obs.variables = varnames,
A.notation = "on", S.notation = "with")
wls(R, aCov = Cov_R, RAM = RAM3, n = 9201)
[1] > "Cov" is not positive definite.
Log in or register to post comments
Dear Simon,
Dear Simon,
The problem is due to the R, not Cov_R.
> is.pd(R)
[1] FALSE
By the way, please use a new subject next time, as unrelated follow-ups may confuse readers.
Mike
Log in or register to post comments
In reply to Dear Simon, by Mike Cheung
Dear Mike,
Dear Mike,
Many thanks for your response. Do you have any suggestion to resolve the problem?
I can think of using nearest PD of R like: is.pd(Matrix::as.matrix(nearPD(R, corr = TRUE)$mat))
Log in or register to post comments
There is an issue with your
There is an issue with your data. I recommend investigating the cause, such as whether it is due to using pairwise deletion.
While adjusting the data with near PD may help, the more critical question is whether the results obtained from this modified data can be considered trustworthy.
Log in or register to post comments
In reply to There is an issue with your by Mike Cheung
Thanks, Mike. Do you mean
Thanks, Mike. Do you mean investigating whether the primary studies had used pairwise deletion when calculating their correlations OR investigating whether I, as the meta-analyst, have used some kind of deletion, such as na.omit(data), when preparing my data for meta-analysis??
In my case, several of the primary studies have NOT reported on correlations between some pairs of variables. Therefore, the data prepared for meta-analysis contains many NAs for those pairs of variables which I deleted using listwise deletion.
Log in or register to post comments
It is the latter, as it is a
It is the latter, as it is a meta-analysis.
Log in or register to post comments
Thank you, Mike. As I
Thank you, Mike. As I mentioned, several of the primary studies have NOT reported on correlations between some pairs of variables. Therefore, the data prepared for meta-analysis contains many NAs for those pairs of variables which I deleted using listwise deletion i.e., na.omit(data).
Are you suggesting that I don't remove the rows where r values are missing?
Log in or register to post comments
There is no need to remove
There is no need to remove studies with NA. The tssem1() function uses FIML in OpneMx to handle missing data.
Please refer to the relevant literature and examples.
Log in or register to post comments
In reply to There is no need to remove by Mike Cheung
Thank you, Mike. I'm not
Thank you, Mike. I'm not using tssem1() for the first stage of meta-analysis. Instead, I'm using metafor::rma.mv().
Log in or register to post comments
All correlations meta-analysis
Hi,
I am new with MetaSEM. I am trying to fit a simple meta-analysis (I just want to analyse 2 correlations; see attached file).
Here you can find the code that I am using with some simulated data but if there are no regressions I cannot make it work. It should be an easy model but I am stuck. I just want two covariances and I have fixed all the variances to one.
Correlations between S and D, S and I and D and I are stored here:
rSD <- c(0.85, 0.8, 0.90, 0.78, 0.70,NA,NA,NA,NA,NA)
rSI <- c(NA,NA,NA,NA,NA,0.85,NA,NA,NA,NA)
rDI <- c(NA,NA,NA,NA,NA,0.60, 0.50, 0.55, 0.60, 0.55)
rSI could be al NAs since I am not interested in that correlation.
Any help and guidance would be really appreciated.
library(metaSEM)
source("http://www.suzannejak.nl/MASEM_functions.R")
rSD <- c(0.85, 0.8, 0.90, 0.78, 0.70,NA,NA,NA,NA,NA)
rSI <- c(NA,NA,NA,NA,NA,0.85,NA,NA,NA,NA)
rDI <- c(NA,NA,NA,NA,NA,0.60, 0.50, 0.55, 0.60, 0.55)
N <- c(10000,40000, 30000, 10000, 10000,20000,10000, 50000, 10000, 10000 )
data <- as.data.frame(cbind(rSD,rSI,rSI, N))
nvar <- 3
varnames <- c("S","D", "I")
labels <- list(varnames,varnames)
cormatrices <- readstack(data[,c(2,1,3)], no.var = nvar, var.names = varnames, diag = FALSE)
n <- data$N
pattern.na(cormatrices, show.na=F)
pattern.n(cormatrices, n=n)
my.df <- Cor2DataFrame(cormatrices, n, acov = "weighted")
## Specify model using lavaan syntax
model <-
'
# Covariances
D ~~ I
D ~~ S
# Variances
D ~~ 1*D
S ~~ 1*S
I ~~ 1*I
'
RAM1 <- lavaan2RAM(model, obs.variables=varnames)
RAM1
## Create the model implied correlation structure with implicit diagonal constraints
M0 <- create.vechsR(A0=RAM1$A, S0=RAM1$S)
## Create the heterogeneity variance-covariance matrix
T0 <- create.Tau2(RAM=RAM1, RE.type="Diag", Transform="expLog", RE.startvalues=0.05)
## Fit the model
mx.fit0 <- osmasem(model.name="No moderator", Mmatrix=M0, Tmatrix=T0, data=my.df)
## View the results
summary(mx.fit0, fitIndices = TRUE)
VarCorr(mx.fit0)
Log in or register to post comments
Hi Juan, I answered your…
Hi Juan,
I answered your question here:
r - All correlations meta-analysis - Cross Validated (stackexchange.com)
Log in or register to post comments
In reply to Hi Juan, I answered your… by suzannejak
Hi Suzanne, Thank you so…
Hi Suzanne,
Thank you so much for that. It is really helpful. I have replied there.
BW
Log in or register to post comments
subgroup.summary error
Dear Mike,
I am trying to test a partial mediation model within the MASem framework, and a possible moderator effect, using subgroup analysis. I followed your instructions (https://suzannejak.nl/OneStageMASEM%20-%20Illustration%201.pdf), and everything went well, until I reached the last command line, when I got an error message (see below). I think I've checked everything, possible code errors, but found nothing. I have attached the whole code; maybe you can help me spot the source of the error.
Many thanks!
Robert
subgroup.summary (submodels.fit, stage2_constrained.fit)
Error in subgroup.summary(submodels.fit, stage2_constrained.fit) :
could not find function "subgroup.summary"
Log in or register to post comments