# activeSetLogCon.mode: Computes the Modally-Constrained Log-Concave Probability... In logcondens.mode: Compute MLE of Log-Concave Density on R with Fixed Mode, and Perform Inference for the Mode.

## Description

This is an adapted version of activeSetLogCon from the logcondens package for computing the MLE of a log-concave density with known location of mode.

Given a vector of observations x_n = (x_1, …, x_n) with potentially distinct or nondistinct entries, activeSetLogCon.mode first computes vectors x_m = (x_1, …, x_m) and w = (w_1, …, w_m) where w_i is the weight of each x_i s.t. ∑_{i=1}^m w_i = 1. The vector \bold{x}_m contains the fixed location of the mode, mode. Then, activeSetLogCon.mode computes a concave, piecewise linear function \widehat φ_m^0 on [x_1, x_m] with p knots only in {x_1, …, x_m} and with mode value, mode, such that

L(φ) = ∑_{i=1}^m w_i φ(x_i) - int_{-∞}^∞ exp(φ(t)) dt

is maximal. To accomplish this, an active set algorithm is used.

## Usage

 1 2 activeSetLogCon.mode(x, xgrid = NULL, mode=x[1], print = FALSE, w = NA, prec=10^-10)

## Arguments

 x Vector of independent and identically distributed numbers, not necessarily unique. xgrid Governs the generation of weights for observations. See preProcess for details. mode This is the constrained value for the location of the mode. print print = TRUE outputs the log-likelihood in every loop, print = FALSE does not. Make sure to tell R to output (press CTRL+W). w Optional vector of weights. If weights are provided, i.e., if w != NA, then xgrid is ignored. prec Governs precision of various subfunctions, e.g., the Newton-Raphson procedure.

## Value

 xn Vector with initial observations x_1, …, x_n. x Vector of observations x_1, …, x_m that was used to estimate the density, i.e., points that include all possible knots of the estimate. Note that \bold{x} always includes the mode value mode, since that point is a possible knot! Note also that this x is not identical to the x passed in (xn is identical). This vector is referred to as 'z' in Doss (2013). w The vector of weights that had been used. Depends on the chosen setting for xgrid. Of the same length as x. The weight corresponding to the mode will be 0 if the mode is not a data point, and otherwise will be nonzero. L The value L(φ_m^0) of the log-likelihood-function L at the maximum \widehat φ_m^0. MI Numeric vector of length 2 giving the endpoints of the modal interval. IsKnot Vector with entries IsKnot_i = 1\{\widehat{φ}_m^0 has a kink at x_i}.
 IsMIC Analogous to IsKnot; stands for "Is Modally Inactive Constraint," i.e., denotes whether the modal constraints are active or inactive. It is a numeric vector of length 2, corresponding to whether the mode is a left-knot or a right-knot. Just as with IsKnot, a 1 denotes an inactive constraint and a 0 denotes an active one. Thus a 0 indicates that the constraint that the estimate be equal in value at the mode and the nearest knot to the left or to the right, respectively, is active. Note also that if max(IsMIC)==1 then the corresponding index in IsKnot is a 1 (i.e., IsKnot[dlcMode$idx] ==1 ). constr knots[constr] is equal to MI; that is, constr is a numeric (integral) vector of length two with values in 1, …, p indicating which of the p knots are the left and right of the modal interval. knots knots equals x[IsKnot>0], gives the values of the points that are knots. phi Vector with entries \widehat φ_m(x_i), i=1,…,m. Named "phi" not "phihat" for backwards compatibility. fhat Vector with entries \widehat{f}_m^0(x_i) = e^{\widehat{φ}_m^0(x_i)}, i=1,…, m. Fhat A vector (\widehat F_{m,i}^0)_{i=1}^m of the same size as x with entries \widehat F_{m,i}^0 = \int_{x_1}^{x_i} \exp(\widehat φ_m^0(t)) dt. H Numeric vector (H_1, …, H_{m})' where H_i is the derivative of t \to L(φ + tΔ_i) at zero and Δ_i(x) = \min(x - x_i, 0) if x_i is less than dlcMode$val or Δ_i(x) = \min(x_i - x, 0) if x_i is greater than dlcMode$val. If x_i is the mode (i.e., equals dlcMode$val) H_i, is set to 0. The corresponding values for the mode are accessed via H.m. Note that in the unconstrained problems the derivatives in the directions \min(x_i - x, 0) and \min(x-x_i,0) are equal, but in the constrained problem these derivatives are not equal. H.m Vector (H.m_1, H.m_2)' where H.m_1 is the derivative of t \to L(φ + tΔ_i) at zero and Δ_1(x) = \min(x - a, 0) and Δ_2(x) = \min(a-x, 0), where a is the mode. n Number of initial observations, i.e., length of xn. m1 Number of unique observations. This count excludes the mode if the mode is not a data point (or if xgrid is not NULL then excludes the mode if it is not in the output of preProcess). m Number of points used to compute the estimator, i.e., unique observations as well as the mode, i.e., length of x. So is either m_1 + 1 or m_1 depending on whether dlcMode$isx is FALSE or TRUE, respectively. dlcMode A list, of class "dlc.mode", with components$val, $idx, and$isx. dlcMode$val gives the constrained mode value, dlcMode$idx gives the corresponding index in x, and dlcMode$isx is TRUE or FALSE depending on whether the value is or is not equal to an element of the vector preProcess(x, xgrid)$x (where x is the argument passed in, not the value returned). Note, when the mode is not an x value, w[dlcMode$idx] == 0. This can often be used in place of an explicit check via$isx as to whether the mode is or is not an x value. sig The standard deviation of the initial sample x_1, …, x_n. phi.f All outputs named "name.f" are functions corresponding to name. So, phi.f(x) equals \widehat{φ}^0_m(x). fhat.f Is a function such that fhat.f(x) equals \widehat{f}_m^0(x). Fhat.f Is a function such that Fhat.f(x) equals \widehat{F}_m^0(x). EL.f EL.f(l,u) = \int_{l}^{u} \widehat{F}_m^0(t) dt Note that this is not analogous to H or H.m, which are derivatives of the log likelihood and so have subtracted an integral of the empirical cdf. ER.f ER.f(l,u) = \int_{l}^{u} (1-\widehat{F}_m^0(t)) dt E.f Equals EL.f. Included so as to be compatible (i.e., follow inheritance principles) with activeSetLogCon, which returns an E.f variable. phiPL Numeric vector of length m with values (\widehat{φ}_m^0)'(x_i-) phiPR Numeric vector of length m with values (\widehat{φ}_m^0)'(x_i+) phiPL.f Is a function such that phiPL.f(x) equals (\widehat{φ}_m^0)'(x-) . phiPR.f Is a function such that phiPR.f(x) equals (\widehat{φ}_m^0)'(x+) .

## Note

Adapted from activeSetLogCon in the package logcondens.

## Author(s)

Kaspar Rufibach, kaspar.rufibach@gmail.com,
http://www.kasparrufibach.ch

Lutz Duembgen, duembgen@stat.unibe.ch,
http://www.staff.unibe.ch/duembgen

## References

Duembgen, L, Huesler, A. and Rufibach, K. (2010) Active set and EM algorithms for log-concave densities based on complete and censored data. Technical report 61, IMSV, Univ. of Bern, available at http://arxiv.org/abs/0707.4643.

Duembgen, L. and Rufibach, K. (2009) Maximum likelihood estimation of a log-concave density and its distribution function: basic properties and uniform consistency. Bernoulli, 15(1), 40–68.

Duembgen, L. and Rufibach, K. (2011) logcondens: Computations Related to Univariate Log-Concave Density Estimation. Journal of Statistical Software, 39(6), 1–28. http://www.jstatsoft.org/v39/i06

Doss, C. R. (2013). Shape-Constrained Inference for Concave-Transformed Densities and their Modes. PhD thesis, Department of Statistics, University of Washington, in preparation.

Doss, C. R. and Wellner, J. A. (2013). Inference for the mode of a log-concave density. Technical Report, University of Washington, in preparation.

The following functions are used by activeSetLogCon.mode:

logConDens (or activeSetLogCon) can be used to estimate an unconstrained log-concave density.

## 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 ## estimate gamma density set.seed(1977) n <- 200 x <- rgamma(n, 2, 1) TRUEMODE <- 1; ## (2-1)*1 res <- activeSetLogCon.mode(x, mode=TRUEMODE, w = rep(1 / n, n), print = FALSE) ## plot resulting functions par(mfrow = c(2, 2), mar = c(3, 2, 1, 2)) plot(res$x, res$fhat, type = 'l'); rug(res$xn) plot(res$x, res$phi, type = 'l'); rug(res$xn) plot(res$x, res$Fhat, type = 'l'); rug(res$xn) plot(res$x, res$H, type = 'l'); rug(res$xn) ## Or can use the ".f" functions xpts <- seq(from=0, to=9, by=.01) par(mfrow = c(2, 2), mar = c(3, 2, 1, 2)) plot(xpts, res$fhat.f(xpts), type = 'l'); rug(res$xn) plot(xpts, res$phi.f(xpts), type = 'l'); rug(res$xn) ## these are not analogous to res$H. plot(xpts, res$EL.f(upper=xpts), type = 'l'); rug(res$xn) plot(xpts, res$ER.f(lower=xpts), type = 'l'); rug(res$xn) ## compute and plot function values at an arbitrary point x0 <- (res$x[100] + res$x[101]) / 2 Fx0 <- evaluateLogConDens(x0, res, which = 3)[, "CDF"] plot(res$x, res$Fhat, type = 'l'); rug(res$x) abline(v = x0, lty = 3); abline(h = Fx0, lty = 3) ## compute and plot 0.9-quantile of Fhat alpha <- .1 q <- quantilesLogConDens(1-alpha, res)[2] plot(res$x, res$Fhat, type = 'l'); rug(res\$x) abline(h = 1-alpha, lty = 3); abline(v = q, lty = 3)

### Example output

Attaching package: 'logcondens.mode'

The following objects are masked from 'package:logcondens':

activeSetLogCon, intF, logConDens

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

dir.exists

logcondens.mode documentation built on May 2, 2019, 8:26 a.m.