# Error in running fixed effect TSSEM1 with clusters

10 posts / 0 new
Offline
Joined: 03/21/2017 - 02:58
Error in running fixed effect TSSEM1 with clusters

Dear Mike and others,

I would like to conduct a fixed effect MASEM with clusters and I am stuck when I try to run TSSEM1. At first I tried to use a cluster variable that I labeled, and then I tried to use the cluster variable without labels (just "0" and "1" codes). I got different error messages each time.

I don't use R much and I don't know how to format the data in exactly the same way they are formatted in the examples on Mike's website (all data in a single file). I was able to run a random effects TSSEM1 and TSSEM2 the way my data were formatted, without clusters.

I have pasted the error messages below and also attached the R script and data files.

Mei Yi

> #Run fixed-effect TSSEM1 according to cluster labels
> cluster1 <- tssem1(vector, n, method="FEM",
+ cluster=mod$IPT1) Error in if (!all(isPD)) warning(paste("Group ", (1:no.groups)[!isPD], : missing value where TRUE/FALSE needed In addition: Warning message: Unknown or uninitialised column: 'IPT1'. > #Run fixed-effect TSSEM1 according to cluster labels > cluster1 <- tssem1(vector, n, method="FEM", + cluster=mod$IPT)
Error in tssem1FEM(data.cluster[[i]], n.cluster[[i]], cor.analysis = cor.analysis, :
Lengths of "df" and "n" are different.
In split.default(x = seq_len(nrow(x)), f = f, drop = drop, ...) :
data length is not a multiple of split variable
> summary(cluster1)

Offline
Joined: 10/08/2009 - 22:37
Dear Mei Yi,

Dear Mei Yi,

I am not able to read the data. For example, v_pre_post.txt is not present; n <- read.table("vectormaxn.txt") returns n as a data frame.

Could you please check the script whether the data and sample sizes can be imported?

Best,
Mike

Offline
Joined: 03/21/2017 - 02:58
Dear Mike,

Dear Mike,

Thanks for your quick response, and apologies for the errors in my script. I have checked the script and made a few changes, the revised script is attached (cluster.R).

1. v_pre_post.txt is changed to v_pre_posti.txt in the script and should be able to be imported (same data file that I have sent you)

2. n <- read.table("vectormaxn.txt") was what I used to run random effects analyses successfully, so I had assumed it would be ok for fixed effects analyses. In case it is helpful I have attached my random effects script, random.R, which uses this syntax without problems.

3. In case n being read as data frame was causing problems for fixed effects analyses, I have created another data file, nmod.txt that contains n and data for one moderator. The cluster.R script has been changed to read n using the syntax:
nmod$n 4. I tried to run the fixed effects analyses, without cluster, and then with cluster, and now I am getting the error message below for TSSEM1 in both analyses: Error in if (!all(isPD)) warning(paste("Group ", (1:no.groups)[!isPD], : missing value where TRUE/FALSE needed Thank you for your help with this issue, Mei Yi File attachments: Offline Joined: 03/21/2017 - 02:58 Dear Mike, Dear Mike, Sorry to post so many messages, I have just realized that I may have gotten the above error message because I may have too much missing data in the correlation matrices. When I run is.pd I get TRUE for the matrices without missing data, and NA for the matrices with missing data. Thus I have rerun the fixed effects analyses without cluster, and then with cluster, and there were no longer any error messages, and openmx status was 0 for all analyses. My questions now are: 1. Is there a way to run the fixed effects analyses with clusters and include the matrices with missing data? 2. For the fixed effects analyses with clusters that I have run, the Stage 1 fit is not good in one cluster or both clusters (depending on which dataset I use). However, Stage 2 fit is ok. I have already run random effects analyses (without clusters) and fit was good, but I wanted to see whether clusters could explain some of the heterogeneity. I also have hypotheses that the mediation model I was testing should apply in one cluster but not in the other--true enough, indirect effect was significant in one cluster but not in the other. Can I use this as evidence to support my hypotheses, or would that not be advisable given that the cluster stage 1 analyses showed poor fit? In case it helps, I have attached the new script, correlation matrix data file, and sample size/moderator data file, where all matrices have no missing data. Thanks so much, Mei Yi File attachments: Offline Joined: 10/08/2009 - 22:37 Dear Mei Yi, Dear Mei Yi, The fixed-effects TSSEM is more sensitive to the presence of missing data. You may use the following code to conduct the fixed-effects model with missing data. fixed1 <- tssem1(vector, nmod$n, method="REM", RE.type="Zero")

It does not work with the "cluster" argument yet. I hope to add it later.

Regards,
Mike

Offline
Joined: 03/21/2017 - 02:58
Thank you Mike for the syntax

Thank you Mike for the syntax to run fixed-effects TSSEM when there is missing data. I look forward to hearing more about the syntax to work with missing data for the cluster argument.

Also, what are your thoughts on interpreting the Stage 2 cluster TSSEM results if Stage 1 fit is not good for one or both clusters? I have already run random effects analyses (without clusters) and fit was good, but I wanted to see whether clusters could explain some of the heterogeneity.

I also have hypotheses that the mediation model I was testing should apply in one cluster but not in the other--true enough, indirect effect was significant in one cluster but not in the other. Can I use this as evidence to support my hypotheses, or would that not be advisable given that the cluster stage 1 analyses showed poor fit?

Mei Yi

Offline
Joined: 10/08/2009 - 22:37
Hi Mei Yi,

Hi Mei Yi,

If the model works in one cluster but not the other, it seems that there is evidence for the moderating effect. For the cluster that does not work, a different model may be required.

Best,
Mike

Offline
Joined: 03/21/2017 - 02:58
Thank you Mike! That makes

Thank you Mike! That makes sense. If I understand correctly, the fit needs to be good in both Stage 1 and Stage 2 of the cluster analyses to say that there is evidence that the data fit the mediation model. If Stage 1 AND Stage 2 fit are good for one cluster, but Stage 1 OR Stage 2 fit (or BOTH) are poor for the second cluster, then there is evidence that the data fit the mediation model in the first cluster but not in the second cluster. This suggests that there is moderated mediation by cluster, and a different model may be needed to fit the data in the second cluster better. If there is something that I misunderstood, I hope you can clarify. Thank you!

Offline
Joined: 10/08/2009 - 22:37
You are correct. If Stage 1

You are correct. If Stage 1 (fixed-effects model) does not fit in one cluster, it suggests that the studies are not homogeneous. You should not fit the Stage 2 analysis.

Offline
Joined: 10/08/2009 - 22:37
Hi Mei Yi,

Hi Mei Yi,

The following code demonstrates how to apply the "cluster" argument to fixed-effects model. Hope it helps.

Regards,
Mike

library(metaSEM)

## Sample cluster
cluster <- ifelse(Digman97$cluster %in% c("Children","Adolescents"), yes="Younger participants", no="Older participants") ## Split the correlation matrices and sample sizes according to the cluster data.cluster <- tapply(Digman97$data, cluster, function(x) {x})
n.cluster <- tapply(Digman97$n, cluster, function(x) {x}) ## Stage 1 analysis rand1 <- mapply(tssem1, Cov=data.cluster, n=n.cluster, method="REM", RE.type="Zero", SIMPLIFY = FALSE) ## Summary lapply(rand1, summary) ## Stage 2 analysis model <- "## Factor loadings Alpha=~A+C+ES Beta=~E+I ## Factor correlation Alpha~~Beta" RAM <- lavaan2RAM(model, obs.variables=c("A","C","ES","E","I"), A.notation="on", S.notation="with") rand2 <- lapply(rand1, tssem2, Amatrix=RAM$A, Smatrix=RAM$S, Fmatrix=RAM$F)

## Summary
lapply(rand2, summary)