Estimating percentage time foraging using binomial data I have collected data on an animal that is either in its burrow (0) or out foraging (1). Each data point has a time stamp associated with it.
What I want to know is, what percentage of time does the animal spend in the burrow? 
Example data
Date  Time Foraging
10/1  10:00   1
10/1  10:30   0
10/1  13:30   0
. . . 
10/1  17:00   1

Here is some sample code that will create a toy data set:
state = rep(seq(0,1),5000)
time = NULL
for (i in 1:length(state)){
    if (state[i]==0) {time[i] = rpois(1,4)*10}
    if (state[i] == 1) {time[i] = rexp(1,1) * 10}
}

df = data.frame(state,time)

the dataset df represents state (0 = "in burrow", 1 = "foraging") and a time spent doing the activity. I wrote the code so that the animal spends ~ 40 minutes in its burrow and 10 minutes foraging, drawing from different distributions. I am assuming that I should be able to sample from the toy data set and recover the values. If I can do this, I may be reasonably sure of the estimates that I obtain from the collected data.
I thought that I would do a simple binomial, but the data points are not equidistant, so then I thought possibly a poisson distribution, but that would get me a rate. 
 A: A simple continuous-time, discrete-state Markov model would be to assume that 
$$P(Y(t+dt)=1|Y(t)=0)=\lambda_{01}dt$$
and
$$P(Y(t+dt)=0|Y(t)=1)=\lambda_{10}dt.$$
Let $p(t)=P(Y(t)=1)$.  From the above assumptions it follows that
$$
\frac{dp}{dt} = -\lambda_{10}p + \lambda_{01}(1-p). \tag{1}
$$
Suppose the state is known at some time $t_0$, say $p(t_0)=1$ or $p(t_0)=0$.  With this initial condition, the solution of (1) is
$$
p(t) = p_\infty + (p(t_0) - p_\infty)e^{-\lambda(t-t_0)}
$$
where $p_\infty = \lambda_{01}/\lambda$ and $\lambda = \lambda_{01}+\lambda_{10}$.
Let $y_i \in \{0,1\}$ be the observed state at time point $t_i$, $i=1,2,\dots,n$.  From the Markov property of the model, the likelihood function becomes
\begin{align}
L(p_\infty,\lambda) &= P(Y(t_1)=y_1 \cap \dots \cap Y(t_n) = y_n) \\
&= P(Y(t_1)=y_1)\prod_{i=2}^n P(Y(t_i)=y_i|Y(t_{i-1})=y_{i-1}) \\
&= f(y_1;p_\infty)\prod_{i=2}^n f(y_i; p_\infty + (y_{i-1} - p_\infty)e^{-\lambda(t_i-t_{i-1})})
\end{align}
where $f(y;p)$ is the Bernoulli probability mass function with parameter $p$ (dbinom( ,size=1, ) below).  Numerical maximisation of the log of this can be implemented in R as follows:
lnL <- function(par,y,t) {
  pinf <- par[1]
  lambda <- par[2]
  n <- length(y)
  i <- 2:n
  tmp <- dbinom(y[1], 1, pinf, log=TRUE) + 
         sum(dbinom(y[i], 1, pinf + (y[i-1]-pinf)*exp(-lambda*(t[i]-t[i-1])), log=TRUE))
  -tmp
}

# fake data with some autocorrelation
y <- c(1,1,1,0,0,1,0,0,0,1) 
t <- c(1,2,3,4,5,6,7,8,9,15)

# fit the model
fit <- optim(c(.5,1),lnL,y=y,t=t,hessian=TRUE)
fit$par # MLEs of p_infinity and lambda = lambda_10 + labmda_01
sqrt(diag(solve(fit$hessian))) # approximate standard errors 

## Estimate based on possibly incorrect binomial model
n <- length(y)
(phat <- sum(y)/n)
sqrt(phat*(1-phat)/n)

Note that this model assumes that the times spent in each state are exponentially distributed which may not be very realistic.
A: 
I thought that I would do a simple binomial, but the data points are not equidistant

But if you don't know anything about how often the animal changes state, or at what times it's most likely to change state, or anything else like that, then there's no way to exploit the timing information. The best you can do is divide the number of 1s by the number of observations. This corresponds to a model in which the animal's probability of being in the burrow at any given moment is constant over time.
