daniel258 / GEEmediate

R package, development version. Mediation analysis in generalized linear nodels using the difference method
0 stars 1 forks source link

Problem when using corstr = 'AR-M' #4

Closed labed73 closed 6 months ago

labed73 commented 7 months ago

Hello Daniel, working on an environmental study, we came across the question of potential mediation on our GEE models previously used. These GEE have a first order autoregressive structure and thus need the parameter corstr = 'AR-M' in gee. I tried using the package GEEmediate which didn't seemed to work for:

GEEmediate::GEEmediate(formula = Y ~ X + M, exposure = 'X', mediator = 'M', family = 'gaussian', corstr = 'AR-M', id = ID, df = df)

returning the following error: Error in gee::gee(formula = dupl.formula, id = ID, data = dupl.df, family = family, : cgee: M-dependence, M=1, but clustsize=1 fatal error for this model

While I cannot send the data I used because of privacy, I went into the code to figure out why it didn't work, and solved my problem by changing some functions. I'd rather post here in case someone might have the same issue or to see if my solution is completely wrong.

First I found that within GEEmediateFit(), the call of DupliData() doesn't transfer 'ID', which lead to the replacement of an existing ID by rep(1:n.row,2) in DupliData().

Secondly for some reason, gee::gee didn't work for the given dupl.df. and dupl.formula, leading to the following error : Error in min(eigen(z$wcor)$values) : invalid 'type' (complex) of argument I solved this error by using geepack::geeglm() rather than gee:gee()

Finally within GEEmediate I changed fit$robust.variance by vcov(fit) as geepack::geeglm doesn't have a robust variance calculated automatically.

As my superiors and colleagues told me they often want to perform mediation analysis and that we're mostly using environmental data i.e GEE, I think it would be great if GEEmediate would have a possibility to use autoregressive models (possibly with geepack).

Thank you.

daniel258 commented 6 months ago

Thank you so much for sharing this! This should be very helpful in the future, and I will see if some of these ideas can be included in the code. Thanks again!