Calculating the first derivative of the pendensity likelihood function w.r.t. parameter beta.
1  Derv1(penden.env)

penden.env 
Containing all information, environment of pendensity() 
We calculate the first derivative of the pendensity likelihood function w.r.t. the parameter beta. The calculation of the first derivative of the pendensity likelihood function w.r.t. parameter beta is done in four steps. The first derivative equals in the case of covariates
\eqn{s(beta) = sum si(beta),}
where
\eqn{s[i](beta) = Z^T(x[i]) C^T (x[i],beta) phi[i] / f(y[i]x[i])}.
Without covariates, the matrix 'Z' doesn't appear. Starting density calculation, the groupings of the covariates are indexed in the main program. The groupings are saved in 'x.factor'. Creating an index that reports which response belongs to which covariate group, saving in 'Z.index'. Therefore, one can link to the rows in the object 'ck' to calculate the matrix 'C.bold', which depends only on the grouping of the covariate. Without any covariate, 'C.bold' is equal for every observation.
The calculation of the first derivative of the pendensity likelihood function w.r.t. parameter beta is done in four steps. Firstly, we calculate the matrix 'C.bold', depending on the groups of 'x.factor'.
Secondly, for calculating we need the fitted values of each observation, 'f.hat'. These values are calculated for the actual parameter set beta in the program 'f.hat'. Of course, we need the value of the base for each observation, φ[i].
Moreover, for the case of conditional density estimation, we need a ZMatrix, due to the rules for derivations of the function 'exp()'. This Zmatrix doesn't appear directly in the calculations. We construct the multiplication with this Zmatrix with using an outer product between the corresponding grouping in 'x.factor' and the product of the corresponding values 'C.bold' and 'base.den', divided by the fitted value 'f.hat'. Finally, we add some penalty on the derivative, which is calculated in the fourth step. The penalty equals λ D_m β .
For later use, we save the unpenalized first derivative as a matrix, in which the ith column contains the first derivative of the pendensity likelihood function, evaluated for the ith value of the response. The needed values are saved in the environment.
Derv1.cal 
matrix, in which the ith column contains the first derivative, evaluated for the ith value of the response variable without penalty. Needed for calculating the second order derivative, called s(β) 
Derv1.pen 
first order derivation of the penalized likelihood function w.r.t. parameter beta, called \eqn{sp(beta)} 
f.hat.val 
fitted values of the response for actual parameter beta, called \hat{f} 
Christian Schellhase <cschellhase@wiwi.unibielefeld.de>
Density Estimation with a Penalized Mixture Approach, Schellhase C. and Kauermann G. (2012), Computational Statistics 27 (4), p. 757777.
Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
All documentation is copyright its authors; we didn't write any of that.