Mediation with clustered standard errors

I am currently conducting mediation analyses using the mediation package in R. I usually use SAS but this approach seemed more straightforward. I am using a Poisson model (link= log). The mediation runs fine, the issue is that participants in my study contributed more than one sample (for the exposure variable), so their data is correlated. I believe that there is a way to indicate that the standard errors are clustered for a variable, but I cannot figure out how to employ it. I see that there is a ‘cluster’ option but that the ‘cluster’ should be a vector of cluster indicators. I am not quite sure how to incorporate it into the mediation. I have successfully used coeftest to get clustered standard errors for the individual models but that does not help for the mediation. Can anyone provide some clarity? Thank you in advance.


Phineas Packard
you should just be able to say cluster="cluster_id_variable" where cluster_id_variable is the name of the column with the cluster ids.
Thank you so much for your help! Just have one more quick question. Do I need to indicate that the data is clustered in the two models (mediator and outcome) before the mediation or does it not matter? I tried to enter cluster into the meditation model and received a message stating that the length of the cluster vector differs from # of observations for the mediator and outcome models.