# EM.BD.SC: Expectation-Maximization on Linear Birth Death (_S_pecial... In DOBAD: Analysis of Discretely Observed Linear Birth-and-Death(-and-Immigration) Markov Chains

## Description

EM Algorithm for estimating rate parameters of a linear Birth-Death process, in which the data is the state at discrete time points

## Usage

 ```1 2 3 4 5 6``` ```EM.BD.SC(dat, initParamMat, tol = 1e-04, M = 30, beta.immig, dr = 1e-07, n.fft = 1024, r=4, prec.tol=1e-12, prec.fail.stop=TRUE, verbose=1, verbFile=NULL) EM.BD.SC.1(dat,init.params, tol = 0.001, M = 30, beta.immig, dr = 1e-07, n.fft = 1024, r=4, prec.tol=1e-12, prec.fail.stop=TRUE, verbose=1, verbFile=NULL) ```

## Arguments

 `initParamMat` nx2 matrix. Each row is an initial parameter setting. n is the number of times to run the full EM algorithm. On the nth time the initial "guess" of the lambda is initParamMat[n,1] and of mu it's initParamMat[n,2]. Used to automate starting at dispersed values to ensure global maximum. Frequently n is one. `init.params` Vector of length two, first number is the first guess for lambda, second is the guess for mu. This is like a single row from initParamMat. `M` Maximum number of iterations for (each) EM algorithm to run through. EM algorithm stops at Mth iteration. `tol` Tolerance for EM algorithm; when two iterations are within tol of each other the algorithm ends. Algorithm also ends after M iterations have been reached. (note: One can debate whether 'tol' should refer to the estimates or to the actual likelihood. here it is the estimates, though). `beta.immig` Immigration rate is constrained to be a multiple of the birth rate. immigrationrate = beta.immig * lambda where lambda is birth rate. `n.fft` Number of terms to use in the fast fourier transform or the riemann integration when using the generating functions to compute probabilities or joint expectations for the birth-death process. See the add.cond.mean.many, etc, functions. `dat` Partially observed chain. Either of class "CTMC_PO_many" for several independent histories, of class "CTMC_PO_1" for one history, or a list with components \$times and \$states where dat\$states[i] is the state observed at time dat\$times[i] (ie, if it is a list then it is analogous to "CTMC_PO_1"). `dr` Parameter for numerical differentiation `r` Parameter for numerical differentiation; see numDeriv package documentation. `prec.tol` "Precision tolerance"; to compute conditional means, first the joint means are computed and then they are normalized by transition probabilities. The precision parameters govern the conditions under which the function will quit if these values are very small. If the joint-mean is smaller than prec.tol then the value of prec.fail.stop decides whether to stop or continue. `prec.fail.stop` If true, then when joint-mean values are smaller than prec.tol the program stops; if false then it continues, usually printing a warning. `verbose` Chooses level of printing. Increasing from 0, which is no printing. `verbFile` Character signifying the file to print to. If NULL just to standard output.

## Details

Assume we have a linear-birth-death process X_t with birth parameter lambda, death parameter mu, and immigration parameter beta*lambda (for some known, real beta). We observe the process at a finite set of times over a time interval [0,T]. Runs EM algorithm to do maximum likelihood.

EM.BD.SC will run the algorithm on multiple starting values and return the history for the best starting value. EM.BD.SC.1 only runs the algorithm for one starting value. Otherwise they are the same.

## Value

Returns a M+1x2 matrix, the nth row being the estimators at the nth iteration. The first column is for lambda (birth), the second for mu (death). If tol is reached before M iterations then many of the rows will be empty, but the M+1st always contains the estimators.

## Author(s)

Charles Doss

`add.cond.mean.many`