I am trying to estimate the parameters for a shifted beta-geometric distribution to model user churn, as shown in this paper. The log-likelihood function is described there and solved via Excel, and I am attempting to do the paramter estimation in R.
The function is below.
$$ LL(\alpha,\beta \space|\space data)=\Sigma \space n_t \ln[\frac{B(\alpha+1,\beta+t-1)}{B(\alpha,\beta)}]+(n-\Sigma \space n_t)\ln[\frac{B(\alpha,\beta+t)}{B(\alpha,\beta)}] $$
where $n_t$ is how many people were lost in a period, and $n$ is the number of people in the original cohort. I have $n_t$ in the vector lost
and precalculate $ n -\Sigma n_t$ in active[tmax]
My attempt to do so in R is as follows:
sbg.lik<-function(params,t,n,active,lost,tmax) {
a<-params[1]
b<-params[2]
logl<-sum(lost*log(beta(a+1,b+t-1)/beta(a,b)))+active[tmax]*log(beta(a,b+t)/beta(a,b))
return(-logl)
}
optim(c(1,1),sbg.lik,t=1:7,n=1000,active=active,lost=lost,tmax=7)
This is unfortunately not working, with the error
Error in optim(c(1, 1), sbg.lik, t = 1:7, n = 1000, active = active, lost = lost, :
objective function in optim evaluates to length 7 not 1
Any ideas? Am i approaching the log likelihood maximation correctly? Any advice would be greatly appreciated!