# Expected time in half-line for random walk

For a one-dimensional random walk (starting at $$0$$) for which we move $$1$$ unit to the right with probability $$p$$ and $$1$$ unit to the left with probability $$q=1-p>p$$, what is the expected time spent in the interval $$(0,\infty)$$ (equivalently, $$[1,\infty)$$)?

It is not too hard to come up with an expression for this involving infinite sums and binomial coefficients, but there does not seem to be a straightforward way to put it in closed form. Alternatively, I'm looking for some sort of (asymptotic) estimate if possible.

There are several combinatorial shortcuts which make the calculation not too difficult, and it is worth knowing that $$\frac{x}{1-x}=x(1-x)+2x^2(1-x)+3x^3(1-x)+\cdots$$ for $$|x|<1$$

Assuming $$0 < p < \frac12$$, the probability of moving right initially and then returning to $$0$$ is $$p$$. By symmetry, the probability of moving left initially and then returning to $$0$$ is also $$p$$, so the probability of moving left initially but never returning to $$0$$ is $$1-2p$$.

So the expected number of returns to $$0$$ is $$1\times 2p(1-2p) + 2\times (2p)^2(1-2p)+3\times (2p)^3(1-2p)+ \cdots = \frac{2p}{1-2p}$$ and half of these are expected to start by moving right into positive territory, so $$\dfrac{p}{1-2p}$$.

Suppose the conditional expected time positive on a trip which starts at $$0$$, moves right, and then returns to $$0$$ is $$T$$. Then the first step takes you to $$+1$$ and then

• with probability $$1-p$$ you return immediately to $$0$$ having spent time $$1$$ positive,
• with probability $$p(1-p)$$ you take a trip to the left of expected time $$T+1$$ returning to $$+1$$ and then immediately to $$0$$ having spent and expected time $$T+2$$ positive,
• with probability $$p^2(1-p)$$ you take two trips to the left each of expected time $$T+1$$ returning to $$+1$$ and then immediately to $$0$$ having spent and expected time $$2T+3$$ positive,

and so on. This means $$T= 1\times (1-p) + (T+2)\times p(1-p)+(2T+3)\times p^2(1-p) + \cdots \\= 1+ (T+1)\frac{p}{1-p}$$

which gives $$T=\dfrac{1}{1-2p}$$.

Multiplying by the overall expected number of trips into positive territory then gives the overall expected time in positive territory of $$\frac{p}{(1-2p)^2}.$$

For $$p=0.4$$ this would give an expected time in positive territory of $$10$$, though with a widely dispersed distribution of possible values. To check, here is a simulation in R:

above0 <- function(p, top){
steps <- sample(c(+1,-1), ceiling(top/(1-2*p)), replace=TRUE, prob=c(p,1-p))
cumsteps <- cumsum(steps)
sum(cumsteps > 0)
}

set.seed(2021)
simabove0 <- replicate(10^5, above0(0.4, 1000))
max(simabove0)
# 350
mean(simabove0)
# 10.03401