EMfit EMfit 0.2

# A Boilerplate for EM algorithms¶

## Description¶

`EMfit` provides the boilerplate for EM algorithms and EM-NR accelerated EM algorithms (also known as the Louis-method of acceleration)

## Usage¶

```EMfit(psi.start, mk_cpl_data, ll_cpl, completeInfo, Jacobian, ...,
Mstep = Mstep.default, eps = 1e-07, maxiter = 200,
maxiter.EM = maxiter, maxiter.inner = 25, Information = TRUE,
verbose = TRUE, verbose.inner = FALSE, show.psi = FALSE)
```

## Arguments¶

`psi.start`

A numeric vector with starting values

`mk_cpl_data`

A function that creates the ‘complete data’ from the ‘observed’ data. Its return value can be anything that can be used by the other functions given as arguments. The return value can also have a component “weights”.

`ll_cpl`

A function that computes the complete-data contributions to the log-likelihood. It should at least accept the arguments `psi`, the parameter vector, and `cpl_data`, the complete-data structure. It should return the complete-data contributions to the log-likelihood, with an attributed named “i” that indicates unconditionally independent groups of observations.

`completeInfo`

A function that computes the ‘complete-data’ information matrix It should at least accept the arguments `psi`, the parameter vector, `cpl_data`, the complete-data structure, and `weights`, which are weights determined e.g. by posterior probabilities and a-priori weights.

`Jacobian`

A function that computes the Jacobian of the log-likelihood function. It should return a matrix with the same number of rows as the length of the result of `ll_cpl` and the same number of colums as elements of `psi` and should have an attribute named “i” that indicates unconditionally independent groups of observations.

`Mstep`

A function that conducts the M-step. It should accept the parameter vector as first argument, the complete-data structure as second argument, a vector `wPPr` of posterior probabilities (weighted if applicable), and should accept anything that is passed via …

`eps`

Numeric; a criterion for convergence

`maxiter`

Maximal number of iterations

`maxiter.EM`

Maximal number of iterations after which the algorithm should switch to Newton-Raphson steps

`maxiter.inner`

Maximal number of iterations for the M-step

`Information`

Logical; should the observed-data information matrix be returned?

`verbose`

Logical; should an interation trace be displayed?

`verbose.inner`

Logical; should the iteration trace of the M-step be displayed (if applicable)?

`show.psi`

Logical; should the current parameter value be displayed along with the iteration history?

`...`

Further arguments passed to `ll_cpl`, `mk_cpl_data`, etc.

## Value¶

A list with the following components:

psi

The MLE of the parameter vector

logLik

The maximized observed-data log-likelihood

The gradient of the log-likelihood function

cplInfo

The complete-data information matrix

missInfo

The missing-data information matrix

obsInfo

The observed-data information matrix. Use this to compute standard errors.

converged

A logical value, indicating whether the algorithm converged.

psi.trace

A matrix which contains the parameter values for each iteration

logLik.trace

A vector with the log-likelihood values of each iteration
{"ft_lang_label":"__label__en","ft_lang_prob":0.69484544,"math_prob":0.9494009,"size":3209,"snap":"2023-40-2023-50","text_gpt3_token_len":720,"char_repetition_ratio":0.12480499,"word_repetition_ratio":0.074152544,"special_character_ratio":0.20473668,"punctuation_ratio":0.13577981,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98815453,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-29T12:58:17Z\",\"WARC-Record-ID\":\"<urn:uuid:d27e0697-15e9-4f54-a057-b5ade23c4faf>\",\"Content-Length\":\"181971\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ec36459c-01d0-4d13-924e-b8c2f1918f51>\",\"WARC-Concurrent-To\":\"<urn:uuid:d6ee8447-d622-4dc7-ad56-b391654c722d>\",\"WARC-IP-Address\":\"46.4.65.50\",\"WARC-Target-URI\":\"https://www.martin-elff.net/software/EMfit/manual/EMfit/\",\"WARC-Payload-Digest\":\"sha1:C2BEX6ABMPEK2X2UCHNE2WF2QTGU5GMJ\",\"WARC-Block-Digest\":\"sha1:QLVS46UDQJQHT2WYMF6ZVB5VGPKEV5LZ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510516.56_warc_CC-MAIN-20230929122500-20230929152500-00427.warc.gz\"}"}