Compute $P(X > Y)$ for two random variables with unknown distributions from Markov chains I would like to compute the probability $P(X > Y)$ with R.
I used JAGS to sample from the posterior distribution of each variable, so I have a Markov chain for each variable (of length $3\times 10^{5}$).
Could someone point me in the right direction?
EDIT: preferably with a Bayesian mindset.
 A: Based on your question and your elaboration in the comment section, it appears that what you are trying to find is the posterior probability that one parameter $X$ exceeds another parameter $Y$.  (It is unusual to represent parameters with English letters; usually we represent data with English letters and parameters with Greek letters.)
You report have a posterior simulation using MCMC methods in JAGS, and you sampled from the posterior distribution of each variable.  Be careful here: parameters are usually not independent a posteriori, so you need to sample from a chain that generates the joint posterior of the parameters; don't sample separately from two chains generating the marginal posteriors.  Assuming you have done this correctly, the simplest way to estimate the probability is via the proportion of cases where the posterior event of interest holds in your simulation.  (Hat-tip to Dezmond Goff in the comments for being the first to point this out.)
Suppose you have $b$ burn-in iterations in your chain, and then an additional $n$ simulated values, so your simulated values are $\{x_k, y_k\}_{k=1}^{b+n}$.  Using these simulated MCMC values you can estimate the posterior probability of interest by discarding the burn-in simulations and using the rest:
$$\hat{\mathbb{P}}(X>Y|\text{Data}) = \frac{1}{n} \sum_{k=b+1}^{b+n} \mathbb{I}(x_k > y_k).$$
Without any additional information about the distributions, this is the best you can do.  You are using your simulated MCMC values to directly estimate the posterior probability of your event.  Ergodic properties of MCMC methods and the laws-of-large numbers ensure that this estimator converges to the rue probability as $n \rightarrow \infty$, so you should get a good answer with $n=3 \times 10^5$.
