possible error in medmod

Discuss the jamovi platform, possible improvements, etc.
Post Reply
jochen
Posts: 3
Joined: Wed Aug 18, 2021 1:18 pm

possible error in medmod

Post by jochen »

dear jamovi makers,

first, we would like to make you a compliment. jamovi is great!

but we may have encountered an error on medmod.
generate a data set wirh the followin r-code

rm(list = ls(all = TRUE)) # clears workspace

require(MASS)
n <- 1000 # set sample size
x <- mvrnorm(n = n, 0, 1, tol = 1e-6, empirical = FALSE, EISPACK = FALSE)
z <- mvrnorm(n = n, 0, 1, tol = 1e-6, empirical = FALSE, EISPACK = FALSE)
y <- 2*x + 3*z + 4*x*z + 1 + mvrnorm(n = n, 0, 1, tol = 1e-6, empirical = FALSE, EISPACK = FALSE)
xyz <-data.frame(x, y, z)
lm(y ~ x*z, xyz)
save(xyz, file="d:/xyz.RData")

if you run now the analysis with medmod, you will get different results than the lm comand provided (additionally, no constant is displayed. if you analyse via jamovi with linear regression, resuls are correct.

best, camila and jochen
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: possible error in medmod

Post by jonathon »

hi,

i'll get ravi to comment on this (he usually takes a few days to respond), but the difference here likely reflects the difference between lm() and lavaan (medmod is based on lavaan) which do things a bit differently.

cheers

jonathon
jochen
Posts: 3
Joined: Wed Aug 18, 2021 1:18 pm

Re: possible error in medmod

Post by jochen »

thanks jonathon for your fast response. but when i use lavaan, i get results identical to the ones i get from lm. and for such simple data without missings i have expected this. have a look:

rm(list = ls(all = TRUE)) # clears workspace

require(MASS)
require(lavaan)
n <- 1000 # set sample size
x <- mvrnorm(n = n, 0, 1, tol = 1e-6, empirical = FALSE, EISPACK = FALSE)
z <- mvrnorm(n = n, 0, 1, tol = 1e-6, empirical = FALSE, EISPACK = FALSE)
y <- 2*x + 3*z + 4*x*z + 1 + mvrnorm(n = n, 0, 1, tol = 1e-6, empirical = FALSE, EISPACK = FALSE)
xyz <-data.frame(x, y, z)
lm(y ~ x*z, xyz)
summary(sem(model="y ~ x+z+x:z", xyz)) # here is the lavaan command
write.csv(xyz, file="d:/xyz.csv") # here i switched to csv-data. works perfectly with jamovi

i am afraid something else is wrong.

best, jochen
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: possible error in medmod

Post by jonathon »

sure. i guess we'll wait for ravi then. in the mean time, the code for medmod is here, if you'd like to take a look:

https://github.com/raviselker/medmod/tree/master/R

cheers

jonathon
User avatar
Ravi
Posts: 194
Joined: Sat Jan 28, 2017 11:18 am

Re: possible error in medmod

Post by Ravi »

Could have something to do with medmod centering variables before passing them on to the model: https://github.com/raviselker/medmod/bl ... #L198-L201
User avatar
MAgojam
Posts: 421
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: possible error in medmod

Post by MAgojam »

Hi, @jochen.

Moderation of jamovi's medmod module, as Estimate reports the Average as the effect of the predictor (x) on the dependent variable (y) at the different levels of the moderator (z) and vice versa
Try selecting the "Simple Slope Analysis" Estimates checkbox and swapping x and z as predictor and moderator.
You will have confirmation of what was said above.

Cheers,
Maurizio


For Jonathon
Just to keep third place. :stuck_out_tongue_winking_eye: :')
jochen
Posts: 3
Joined: Wed Aug 18, 2021 1:18 pm

Re: possible error in medmod

Post by jochen »

the point goes to ravi: centering is the solution.

many thanks to all of you,

camila and jochen
Post Reply