I'm currently dealing with time series data about sales of beverages in a supermarket. I have data for each minute, but I'm aggregating by hour since the dataset is already huge with a daily granularity.
I would like to detect stock outs occurring to a product, where a stock out happens when all the items of a given product where sold and the product is not available until refilled. I was suggested to use a Hidden Markov Model, but having little knowledge about it I don't know how to set up the problem, so I ask for help with references and suggestions of the statistical and mathematical assumptions to use. My idea would be something like:
$Y_i$ = hourly time series of sales, $i=1,...,n$,
$Y_i \in Z^+$
$Z_i $ = hourly time series of latent states, $i=1,...,n$
$Z_i \in {0,1}$, with $0$ corresponding to no items available/stock out
Basically I would like to infer the latent state given the observable sequence of sales.
I'm currently trying to find it using depmixS4 library in R:
dep2 <- depmix(resp ~ xreg,nstates=2,family=poisson(),ntimes=length(resp))
hmm2 <- fit(dep2)
ba2 <- BIC(hmm2)
summary(hmm2)
Thank you in advance