## Function used to calculate the first derivatives of the log likelihood with respect to the model parameters.

### Description

Function used to calculate the first derivatives of the log likelihood with respect to the model parameters. These are numerical derivatives calculated using the numerical derivative functions of Gilbert and Varadhan (2015).

### Usage

```LL.gradient(parameter, model.type, model.name, link, ntrials, nsuccess,
covariates.matrix.p, covariates.matrix.scalef,
```

### Arguments

 `parameter` A vector of the parameters of the model which is set to initial estimates on function call. `model.type` Takes one of two values i.e. 'p only' or 'p and scale-factor'. The 'p only' value fits linear predictor functions to the probability of a success 'p' as in Faddy and Smith (2012). The 'p and scale-factor' value fits linear predictor functions to both the 'p' and the scale-factor. The default is 'p and scale-factor'. `model.name` If model.type is 'p only' the model being fitted is one of the four 'binomial', 'generalized binomial', 'beta binomial' or 'correlated binomial'. If model.type is 'p and scale-factor' the model being fitted is one of the three 'generalized binomial', 'beta binomial' or 'correlated binomial'. Information about these models is given in Faddy and Smith (2012). The default is 'generalized binomial'. `link` Takes one of nine values i.e., 'logit', 'probit', 'cloglog', 'cauchit', 'log', 'loglog', 'double exponential', 'double reciprocal', 'power logit'. The default is 'cloglog'. The 'power logit' has an attribute of 'power' for which the default is 1 i.e., a logit link. `ntrials` A vector length 'n+1' representing the number of trials 'n' i.e., a vector with all elements equal to 'n'. `nsuccess` A vector representing the frequency distribution of the binomial distribution for fixed number of trials 'n'. `covariates.matrix.p` A matrix of covariates for the mean where rows are the number of values in list.binary and columns the covariates. This matrix is extracted from the formulae in function BinaryEPPM. However, in the accompanying example it is shown how it can be constructed independently of function BinaryEPPM. `covariates.matrix.scalef` A matrix of covariates for the variance where rows are the number of values in list.binary and columns the covariates. The default is a vector of ones. This matrix is extracted from the formulae in function BinaryEPPM. However, in the accompanying example it is shown how it can be constructed independently of function BinaryEPPM. `offset.p` An offset vector for the probability of success p. The default is a vector of ones. `offset.scalef` An offset vector for the scale-factor. The default is a vector of ones. `weights` A vector or list of weights for the modeling of probability of success. The default is a vector of ones. `grad.method` Numerical method used to calculate gradients when the optimization method for optim is BFGS either simple or Richardson. This is the grad.method attribute of argument method of BinaryEPPM. The default is simple.

### Value

A vector of numerical first derivatives.

### Author(s)

David M. Smith <smithdm1@us.ibm.com>

### References

Gilbert P, Varadhan R. (2015). numDeriv: Accurate Numerical Derivatives. R Package version 2014.2-1, https://CRAN.R-project.org/package=numDeriv.

### Examples

```link <- 'cloglog'