Probability distribution for two-state system that depends on residence time I am a statistical physicist, and I've come across a problem that I don't know how to solve. I believe my issue lies with how to formulate it mathematically. I'd be very grateful for any assistance, as I've really struggled with this.
Suppose we have a system with two states, say $+$ and $-$. The waiting time distribution for switching from either state to the other is an exponential, $\psi_{\pm}(t) = \kappa_{\pm} e^{-\kappa_{\pm} t}$. So $\psi_{\pm}(t)$ is the probability distribution for the time spent in the $\mp$ state.
Let $X$ be the random variable that we are interested in. If we enter state $+$ at $t = 0$, then its probability distribution at a later time $t$ is $p_{+}(x, t)$, assuming it does not switch to $-$. Define $p_{-}(x, t)$ likewise. These distributions depend on the time spent in the state.
I would like the full probability distribution $p(x, t)$, assuming the initial state is known, say $+$. I simply don't know how to write down a general equation for $p(x, t)$...
Again, any help would be wonderful. Thanks!
 A: You seem to be after $p(x,t)=P[S_t=+]p_+(x,t)+P[S_t=-]p_-(x,t)$ where $S_t$ is the state at time $t$. One knows that $S_0=+$ and that $S_t$ switches from $\pm$ to $\mp$ at rate $\kappa_\pm$. 
Thus, $p(x,t)=q(t)p_+(x,t)+(1-q(t))p_-(x,t)$ where $q(t)=P[S_t=+]$ and the task is to compute $q(t)$. Note that $q(0)=1$ and that, when $s\to0$,
$$
q(t+s)=P[S_{t+s}=+]=q(t)(1-\kappa_+s+o(s))+(1-q(t))\kappa_-s+o(s),
$$
that is,
$$
q'(t)=-\kappa_+q(t)+\kappa_-(1-q(t)).
$$
This ODE yields $q(t)$ for every $t$, hence $p(x,t)$.
Edit: Second try, the model the OP is interested in might (or might not) be the following. Some quantities $p_+(x,t)$ and $p_-(x,t)$ are given for every $t\geqslant0$ and a state process $(S_t)$ is switching back and forth between states $+$ and $-$ at rates $\kappa_+$ and $\kappa_-$ and starting from $S_0=+$. Call $T_t$ the time of the last switch before $t$ (if no switch occurred before $t$, $T_t=0$). One is interested in 
$$
p(x,t)=E[p_{S_t}(x,t-T_t)]=
E[p_+(x,t-T_t);S_t=+]+E[p_-(x,t-T_t);S_t=-].
$$
From now on, let us choose $x$ and shorten $p(x,t)$, $p_+(x,t)$ and $p_-(x,t)$, $q(t)$ and $1-q(t)$ into $p(t)$, $p_+(t)$, $p_-(t)$, $q_+(t)$ and $q_-(t)$ respectively. When $r\to0$, during the time interval $(t,t+r)$ and assuming that $S_t=s$ with $s\in\{\pm\}$, either no switch happen and then $S_{t+r}=s$ and $t+r-T_{t+r}=t-T_t+r$, or a switch happen and then $S_{t+r}=-s$ and $t+r-T_{t+r}=o(1)$. Hence,
$$
p(t+r)=\sum_s\kappa_s rq_s(t)p_{-s}(0)+(1-\kappa_sr)E((p_s(t-T_t)+rp'_s(t-T_t));S_t=s)+o(r),
$$
which implies that
$$
p'(t)=\sum_s\kappa_s q_s(t)p_{-s}(0)+E(p'_s(t-T_t);S_t=s)-\kappa_sE(p_s(t-T_t);S_t=s).
$$
Conditionally on $S_t=s$, $t-T_t$ is distributed like $\min\{t,U_s\}$, where $U_s$ is exponential with parameter $\kappa_s$, hence, for every function $v$,
$$
E(v(t-T_t);S_t=s)=\mathrm e^{-\kappa_st}q_s(t)v(0)+q_s(t)\int_0^tv(u)\kappa_s\mathrm e^{-\kappa u}\mathrm du.
$$
Applying this to $v=p_s$ and to $v=p'_s$ shows that $t\mapsto p(t)$ solves an explicit integro-differential equation.
A: first simple case: $p_+=p_-\equiv p_0$ and $\kappa_+=\kappa_-\equiv \kappa$; then all you need to know is the time $\delta t$ since the last switching event, which has an exponential distribution, hence:
$$p(x,t)=(1-e^{-\kappa t})^{-1}\int_0^t d\delta t\; \kappa e^{-\kappa \delta t}p_0(x,\delta t)$$
now the general case; you'll need to distinguish even from odd number of switching events, and find the distribution $P_{\rm even}(\delta t)$ of the time $\delta t$ since the last switching event, given that there have been an even number of switches in a time $t$, and similarly for an odd number; the a priori probability that there have been an even or odd number of switches is just given by the Poisson distribution (summing over $n$ even or $n$ odd). The integral over $P_{\rm even}(\delta t)p_{+}(x,\delta t)$ and $P_{\rm odd}(\delta t)p_{-}(x,\delta t)$ then gives the full answer.
a bit more explicit, still assuming $\kappa_+=\kappa_-\equiv \kappa$ for simplicity; it is convenient to set the first switching event at time $0$, so that the number of switching events $m=n+1$ in a time $t>0$ is $\geq 1$; the probability $P_{m,t}(\delta t)$ that there have been $m=n+1\geq 1$ switching events in a time $t$, while the last switching event was a time $\delta t\in[0,t)$ ago is given by a slight modification of the Poisson distribution,
$$ P_{m,t}(\delta t)=\frac{1}{(m-1)!}[\kappa(t-\delta t)]^{m-1}\kappa e^{-\kappa t}.$$
summing over all $m=1,2,3,\ldots$ we recover the exponential probability $\sum_{m}P_{m,t}(\delta t)=\kappa\exp(-\kappa\delta t)$ we had before, but now we have to distinguish between even $m$ (= odd $n$) and odd $m$ (= even $n$):
$$P_{\rm even}(\delta t)=\sum_{m=1,3,5}^{\infty}P_{m,t}(\delta t)=\cosh[\kappa(t-\delta t)]\kappa e^{-\kappa t}$$
$$P_{\rm odd}(\delta t)=\sum_{m=2,4,6}^{\infty}P_{m,t}(\delta t)=\sinh[\kappa(t-\delta t)]\kappa e^{-\kappa t}$$
and we're done:
$$p(x,t)=(1-e^{-\kappa t})^{-1}\int_0^t d\delta t\; [P_{\rm even}(\delta t)p_+(x,\delta t)
+P_{\rm odd}(\delta t)p_-(x,\delta t)]$$
$$\quad\quad=(1-e^{-\kappa t})^{-1}\int_0^t d\delta t\; \kappa e^{-\kappa t}\left[\cosh[\kappa(t-\delta t)]p_+(x,\delta t)
+\sinh[\kappa(t-\delta t)]p_-(x,\delta t)\right]$$
if we take $p_+=p_-\equiv p_0$ we recover the earlier result.
