# lrttest: Calculate Likelihood Ratio Test (LRT) In BioGeoBEARS: BioGeography with Bayesian (and Likelihood) Evolutionary Analysis in R Scripts

## Description

The Likelihood Ratio Test (LRT) is a standard method for testing whether or not the data likelihood conferred by a more complex is significantly better than the data likelihood conferred by the simpler model, given a certain number of extra free parameters for the complex model. The null hypothesis is that there is no difference; rejection means that there is a statistically significant improvement in the more complex model.

## Usage

 ```1 2``` ``` lrttest(LnL_1, LnL_2, numparams1, numparams2, returnwhat = "pval") ```

## Arguments

 `LnL_1` Log-likelihood of more complex model. `LnL_2` Log-likelihood of simpler complex model. `numparams1` Number of free parameters of the more complex model. `numparams2` Number of free parameters of the less complex model. `returnwhat` If "pval", just return the p-value. If "all", return all of the intermediate outputs.

## Details

The LRT only works for situations in which the simpler model is nested within the more complex model (i.e., by taking some parameters of the more complex model and forcing them to be fixed to a specific value). In addition, the LRT may be unreliable in data-poor situations, and inherits whatever difficulties there may be in ML searches. See Burnham et al. (2002) for discussion.

This function assumes that `LnL_1` and `numparams1` refer to the more complex model, and that `LnL_2` and `numparams2` refer to the simpler model nested within the more complex one.

## Value

`pval` or `LRT_result2`. Depends on `returnwhat`.

Go BEARS!

## Author(s)

Nicholas J. Matzke matzke@berkeley.edu

## References

Burnham_Anderson_2002

Matzke_2012_IBS

`lrttest_on_summary_table`

## Examples

 `1` ```test=1 ```

### Example output

```Loading required package: rexpokit

Attaching package: 'SparseM'

The following object is masked from 'package:base':

backsolve