Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in mgmsampler function #28

Open
LiuJL1100 opened this issue Oct 25, 2023 · 7 comments
Open

Error in mgmsampler function #28

LiuJL1100 opened this issue Oct 25, 2023 · 7 comments

Comments

@LiuJL1100
Copy link

Hi Jonas,

I run the exampling code in the documantation of mgmsampler function, but got the warning message:

Error in if (!(class(interactions[[i]][[row]]) %in% c("array", "matrix"))) stop("The parameters of each interaction have to be provided as k-dimensional array.") : 
  the condition has length > 1

How to slove this problem?

@Jiahao-ZHU
Copy link

I also came across this problem.

My mgm version is "1.2-14", R version is "4.3.2 (2023-10-31)", and RStudio version is "2023.09.1+494"

When I ran example 1 in the mgmsampler() function, I got the same warning message. However, sexamples 2 and 3 (focus on 3-way interaction) are fine. I wonder if there is any problem with 2-way interaction or else.

Hoping for solutions. Thanks.

@Jiahao-ZHU
Copy link

Jiahao-ZHU commented Nov 3, 2023

I went through the code of the function, and I think this problem might occur because the code: f (!(class(interactions[[i]][[row]]) %in% c("array", "matrix"))) in

for (i in 1:n_order) { n_ints <- length(interactions[[i]]) if (n_ints > 0) for (row in 1:n_ints) if (!(class(interactions[[i]][[row]]) %in% c("array", "matrix"))) stop("The parameters of each interaction have to be provided as k-dimensional array.") }

returns more than one logic element (as for example 1, the result is TRUE TRUE). Therefore, the condition has length > 1.

To solve this problem, I defined a new function mgm_sampler on my own, and replaced the original code with
for(i in 1:n_order) { n_ints <- length(interactions[[i]]) if(n_ints > 0) { for(row in 1:n_ints) { if(!inherits(interactions[[i]][[row]], "array") && !inherits(interactions[[i]][[row]], "matrix")) { stop("The parameters of each interaction have to be provided as k-dimensional array.") } } } }

Hope this solution can help. :)

@TomRow90
Copy link

TomRow90 commented Oct 8, 2024

Hello,

I was hoping to use this for some simulations I need to run. I just installed the latest developmental version and it looks like this error is still present (it was still present in the CRAN version as well). I tried the workaround posted by Jiahao-ZHU above but I can't quite get that to work. So I was just wondering whether anyone has found another workaround or whether an update to the developmental version could be made? Many thanks.

@jmbh
Copy link
Owner

jmbh commented Oct 9, 2024

I'll try to fix this asap. Meanwhile, an alternative and possibly more convenient way to simulate data with multivariate dependencies between variables with different domains is to simulate from a DAG. This avoids the issues arising from needing a proper joint distribution over all variables (see Appendix F in https://osf.io/preprints/psyarxiv/926pv and the accompanying code in corresponding reproducibility repo).

@TomRow90
Copy link

TomRow90 commented Oct 9, 2024

Great, thanks Jonas, and for the tip and link as well.

@jmbh
Copy link
Owner

jmbh commented Dec 13, 2024

I know this has been a while, but any chance yo could send me a reproducible example of this?

@TomRow90
Copy link

TomRow90 commented Dec 19, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants