How to enter confounding variables and variables competing for exposure into a mixed-effects model in lme4? Let's imagine I am interested in the association between happiness and pain.
I run a study where I ask participants to rate both feelings, daily, for several days. However, I couldn't get all participants to start at the same time so I will have to include calendar date in analysis, as I know it affects happiness.
I record whether my participants take any medication (pill) that affects pain. I also found some great literature that suggests that both apple juice and green tea affect happiness and pain.
In that scenario I have both confounding variables and variables competing for exposure. I created a DAG (following this great comment) to decide which one is which. Based on my data I have the following graph:
Original DAG

EDIT: New DAG

Where:

*

*$time$ is confounding variable because $time \rightarrow happiness$
EDIT: $time \rightarrow happiness/pain$

*$juice$ & $tea$ are confounding variables because $juice/tea \rightarrow happiness \rightarrow pain \leftarrow juice/tea $

*$pill$ is competing exposure because $pill \rightarrow pain$

Based on that DAG interpretation I build a model
m1 <- lmer(pain ~ happiness + pill + time + (1 + time | participant) + (1 | juice) + (1 | tea)

With that model I hope to account for the effect of time, which is a continuous variable. I entered juice and tea as crossed random effects because they change with time and the level of both depends on participant. Lastly, I entered pill as a fixed effect since it is a categorical yes/no variable to denote presence/absence of medication.


*

*Is my interpretation of DAG correct?

*Does my model reflect my DAG?
 A: 
Is my interpretation of DAG correct?

Not quite, but it is VERY nice to see that you are embracing the DAG methodology. You said:

time  is confounding variable because time→happiness

That does not make time a confounder. You have correctly identified that juice and tea are confounder, but time is not a cause of pain, so according your DAG, time is not a confounder.
Pill is indeed a competing exposure and inclusion of it in the model will make the estimate of your causal effect of happiness on pain more precise.
So you should include tea, juice and pill as covariates, either fixed or random.
It is a bit unclear how to treat time here. I would rather of posted this as a comment but there was too much to say so I may update the answer once more information comes to light.

Does my model reflect my DAG?

A slightly better question to ask is "is my model consisent with my DAG, but I am being a little pedantic there. Just remember that DAGs are non parametric, but the model is parametric. According to your DAG we should not condition on time, but I think we need to understand how time is involved in the study design before taking it further.
