# Dmean: Differentiate the Mean Function of a Nonlinear Model In nlreg: Higher Order Inference for Nonlinear Heteroscedastic Models

## Description

Calculates the gradient and Hessian of the mean function of a nonlinear heteroscedastic model.

## Usage

 1 Dmean(nlregObj, hessian = TRUE) 

## Arguments

 nlregObj a nonlinear heteroscedastic model fit as obtained from a call to nlreg. hessian logical value indicating whether the Hessian should be computed. The default is TRUE.

## Details

The mean function is differentiated with respect to the regression coefficients as specified in the coef component of the nlreg object. The returned function definition, however, includes all parameters — regression coefficients and variance parameters — as arguments. When evaluated, it implicitly refers to the data to whom the model was fitted and which must be on the search list. The gradient and Hessian are calculated for each data point: the gradient attribute is a \emph{n x p} matrix and the hessian attribute is a \emph{n x p x p} array, where \emph{n} and \emph{p} are respectively the number of data points and the number of regression coefficients.

## Value

a function whose arguments are named according to the parameters of the nonlinear model nlregObj. When evaluated, it returns the value of the mean function along with attributes called gradient and hessian, the latter if requested. These are the gradient and Hessian of the mean function with respect to the regression coefficients.

## Note

Dmean and Dvar are the two workhorse functions of the nlreg library. The details are given in Brazzale (2000, Section 6.1.2).

The symbolic differentiation algorithm is based upon the D function. As this algorithm is highly recursive, the hessian = TRUE argument should only be used if the Hessian matrix is needed. Whenever possible, derivatives should be stored so as to be re-used in further calculations. This is, for instance, achieved by the nonlinear heteroscedastic model fitting routine nlreg through the argument hoa = TRUE.

## References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language: A Programming Environment for Data Analysis and Graphics. London: Chapman \& Hall. Section 9.6.

Brazzale, A. R. (2000) Practical Small-Sample Parametric Inference. Ph.D. Thesis N. 2230, Department of Mathematics, Swiss Federal Institute of Technology Lausanne.

Dvar, nlreg.object, deriv3, D

## Examples

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 library(boot) data(calcium) calcium.nl <- nlreg( cal ~ b0*(1-exp(-b1*time)), start = c(b0 = 4, b1 = 0.1), data = calcium ) Dmean( calcium.nl ) ##function (b0, b1, logs) ##{ ## .expr3 <- exp(-b1 * time) ## .expr4 <- 1 - .expr3 ## .expr6 <- .expr3 * time ## .value <- b0 * .expr4 ## .grad <- array(0, c(length(.value), 2), list(NULL, c("b0", ## "b1"))) ## .hessian <- array(0, c(length(.value), 2, 2), list(NULL, ## c("b0", "b1"), c("b0", "b1"))) ## .grad[, "b0"] <- .expr4 ## .hessian[, "b0", "b0"] <- 0 ## .hessian[, "b0", "b1"] <- .hessian[, "b1", "b0"] <- .expr6 ## .grad[, "b1"] <- b0 * .expr6 ## .hessian[, "b1", "b1"] <- -(b0 * (.expr6 * time)) ## attr(.value, "gradient") <- .grad ## attr(.value, "hessian") <- .hessian ## .value ##} ## param( calcium.nl ) ## b0 b1 logs ## 4.3093653 0.2084780 -1.2856765 ## attach( calcium ) calcium.md <- Dmean( calcium.nl ) attr( calcium.md( 4.31, 0.208, -1.29 ), "gradient" ) ## b0 b1 ## [1,] 0.08935305 1.766200 ## [2,] 0.08935305 1.766200 ## [3,] 0.08935305 1.766200 ## [4,] 0.23692580 4.275505 ## \dots detach() 

nlreg documentation built on May 1, 2019, 9:21 p.m.