0% found this document useful (0 votes)
8 views52 pages

Logcondens

Uploaded by

Nix
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views52 pages

Logcondens

Uploaded by

Nix
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Package ‘logcondens’

August 22, 2023


Type Package
Title Estimate a Log-Concave Probability Density from Iid Observations
Version 2.1.8
Date 2023-08-21
Author Kaspar Rufibach <kaspar.rufibach@gmail.com> and Lutz Duemb-
gen <duembgen@stat.unibe.ch>
Maintainer Kaspar Rufibach <kaspar.rufibach@gmail.com>
Depends R (>= 2.10)
Imports ks, graphics, stats
Description Given independent and identically distributed observations X(1), ..., X(n), com-
pute the maximum likelihood estimator (MLE) of a density as well as a smoothed ver-
sion of it under the assumption that the density is log-concave, see Rufibach (2007) and Duemb-
gen and Rufibach (2009). The main function of the package is 'logConDens' that allows compu-
tation of the log-concave MLE and its smoothed version. In addition, we provide func-
tions to compute (1) the value of the density and distribution function esti-
mates (MLE and smoothed) at a given point (2) the characterizing functions of the estima-
tor, (3) to sample from the estimated distribution, (5) to compute a two-sample permuta-
tion test based on log-concave densities, (6) the ROC curve based on log-concave esti-
mates within cases and controls, including confidence intervals for given values of false posi-
tive fractions (7) computation of a confidence interval for the value of the true den-
sity at a fixed point. Finally, three datasets that have been used to illustrate log-concave den-
sity estimation are made available.
License GPL (>= 2)

URL http://www.kasparrufibach.ch ,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html
NeedsCompilation no
Repository CRAN
Date/Publication 2023-08-22 13:20:02 UTC

1
2 logcon-package

R topics documented:
logcon-package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
activeSetLogCon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
activeSetRoutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
brightstar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
confIntBootLogConROC_t0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
evaluateLogConDens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
icmaLogCon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
intECDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
intF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
isoMean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Jfunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Lhat_eta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Local_LL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Local_LL_all . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
logConCI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
logConCIfunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
logConDens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
logConROC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
logconTwoSample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
maxDiffCDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
MLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
pancreas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
plot.dlc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
preProcess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Q00 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
qloglin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
quadDeriv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
quantilesLogConDens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
reliability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
reparametrizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
rlogcon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
robust . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
ROCx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
summary.dlc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

Index 51

logcon-package Estimate a Log-Concave Probability Density from iid Observations


logcon-package 3

Description
The main function of this package is logConDens: compute the maximum likelihood estimator
(MLE) of a log-concave density from one-dimensional i.i.d. observations as well as the kernel
smoothed version derived from it. A list of additional functions that can be used to compute quan-
tities relevant in that context can be found below.
Two algorithms are offered to compute the estimate: An active set (logConDens) and an iterative
algorithm based on the pool-adjacent-violaters algorithm (icmaLogCon). The latter of these func-
tions is only part of this package for historical reasons: it was the first method that was proposed
to estimate a log-concave density, see Rufibach (2007). The more efficient way of computing the
estimate is via an active set algorithm. The smoothed versions of the log-concave density and dis-
tribution function estimates discussed in Section 3 of Duembgen and Rufibach (2009) are available
in the function evaluateLogConDens.
To compute a log-concave density, CDF, and survival function from interval- or right-censored ob-
servations use the package logconcens. A log-concave probability mass function can be computed
using the package logcondiscr, see Balabdaoui et al (2012) for details. For the computation of a
log-concave estimate in any dimension the package LogConDEAD can be used.

Details

Package: logcondens
Type: Package
Version: 2.1.8
Date: 2023-08-21
License: GPL (>=2)

The following additional functions and datasets are provided in the package:
evaluateLogConDens Computes the value of the estimated log-density, density, and distribution
function of the MLE and the smoothed estimator at a given x0.
quantilesLogConDens Computes quantiles of the estimated distribution function at a given x0.
intECDF Compute the integrated empirical distribution function of the observations at a given x0.
intF Compute the integral of the distribution function corresponding to the log-concave density
estimator at a given x0.
logconTwoSample Compute a permutation test for the difference between two distribution func-
tions.
logConROC Compute ROC curve based on log-concave density estimates within cases and controls.
confIntBootLogConROC_t0 Compute bootstrap confidence intervals at given false positive frac-
tions (= 1 - specificity) for the ROC curve based on log-concave density estimates.
logConCI Compute a confidence interval for the value of the true density at a fixed point, based
on the theory developed in Balabdaoui et al (2009). This function was contributed by Mahdis
Azadbakhsh and Hanna Jankowski, see Azadbakhsh et al (2012).
isoMean Compute the weighted least squares regression under a monotonicity constraint (the Grenan-
der estimator). This function is used as part of icmaLogCon but is also of independent interest.
4 logcon-package

The following datasets have been used in several publications to illustrate log-concave density esti-
mation and are therefore included in this package:
reliability Dataset that contains the data analyzed in Duembgen and Rufibach (2009, Figure 2).
See the help file for logConDens for the analysis of this data.
brightstar Dataset that contains the data analyzed in Mizera and Koenker (2009, Section 5). The
sample consists of measurements of radial and rotational velocities for the stars from the Bright Star
Catalog, see Hoffleit and Warren (1991).
pancreas Data from pancreatic cancer serum biomarker study, first published by Wieand et al
(1989). Contains data on serum measurements for a cancer antigen (CA-125) and a carbohydrate
antigen (CA19.9) both of which are measured on a continuous non-negative scale. The measure-
ments were taken within a case-control study on 90 cases with pancreatic cancer and 51 controls
who did not have cancer but pancreatitis.
A print and summary for objects of class dlc, generated by logConDens, are available as well.

Author(s)
Kaspar Rufibach (maintainer), <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html
Kaspar Rufibach gratefully acknowledges support by the Swiss National Science Foundation SNF,
http://www.snf.ch.
MatLab code with an implementation of the active set algorithm is available on request from Lutz
Duembgen.

References
Azadbakhsh, M., Jankowski, H. and Gao, X. (2014). Computing confidence intervals for log-
concave densities. Comput. Statist. Data Anal., 75, 248–264.
Balabdaoui, F., Jankowski, H., Rufibach, K. and Pavlides, M. (2012). Asymptotics of the discrete
log-concave maximum likelihood estimator and related applications. J. R. Stat. Soc. Ser. B Stat.
Methodol., 75(4), 769–790.
Baladbaoui, F., Rufibach, K. and Wellner, J. (2009). Limit distribution theory for maximum likeli-
hood estimation of a log-concave density. Ann. Statist., 37(3), 1299–1331.
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 https://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. doi:10.18637/jss.v039.i06
Hoffleit, D., Warren, W.H. (1991). The Bright Star Catalog. Yale University Observatory, New
Heaven.
Mizera, I., Koenker, R. (2010). Quasi-concave density estimation. Ann. Statist., 38(5), 2998–3027.
activeSetLogCon 5

Rufibach K. (2006). Log-concave Density Estimation and Bump Hunting for i.i.d. Observations.
PhD Thesis, University of Bern, Switzerland and Georg-August University of Goettingen, Ger-
many, 2006.
Available at https://slsp-ube.primo.exlibrisgroup.com/permalink/41SLSP_UBE/17e6d97/
alma99116730175505511.
Rufibach, K. (2007). Computing maximum likelihood estimators of a log-concave density function.
J. Stat. Comput. Simul. 77, 561–574.
Rufibach, K. (2012). A smooth ROC curve estimator based on log-concave density estimates. Int.
J. Biostat., 8(1), 1–29.

Examples
## estimate gamma density
set.seed(1977)
x <- rgamma(100, 2, 1)
res <- logConDens(x, smoothed = FALSE, print = TRUE)
summary(res)

## compare performance to ICMA


res2 <- icmaLogCon(x, T1 = 2000, robustif = TRUE, print = TRUE)

res$L
res2$L

## plot resulting functions


par(mfrow = c(2, 2), mar = c(3, 2, 1, 2))
plot(res, which = "density")
plot(res, which = "log-density")
plot(res, which = "CDF")
xli <- range(res$x) + 0.1 * c(-1, 1) * diff(range(res$x))
plot(res$x, res$H, type = 'l', xlim = xli, yli = c(min(res$H) * 1.1, 0))
segments(res$knots, 0, res$knots, min(res$H) * 1.1, lty = 2)
rug(res$x); abline(h = 0, lty = 2)

## compute function values at an arbitrary point


x0 <- (res$x[50] + res$x[51]) / 2
evaluateLogConDens(x0, res)

## compute 0.5 quantile of Fhat


quantilesLogConDens(0.5, res)

activeSetLogCon Computes a Log-Concave Probability Density Estimate via an Active


Set Algorithm

Description
Given a vector of observations xn = (x1 , . . . , xn ) with not necessarily equal entries, activeSetLogCon
first computes vectors xm = (x1 , . . . , xm ) and w = (w1 , . . . , wm ) where wi is the weight of each
6 activeSetLogCon

Pm
xi s.t. i=1 wi = 1. Then, activeSetLogCon computes a concave, piecewise linear function φbm
on [x1 , xm ] with knots only in {x1 , . . . , xm } such that

m
X Z ∞
L(φ) = wi φ(xi ) − exp(φ(t))dt
i=1 −∞

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

Usage
activeSetLogCon(x, xgrid = NULL, print = FALSE, w = NA)

Arguments
x Vector of independent and identically distributed numbers, not necessarily unique.
xgrid Governs the generation of weights for observations. See preProcess for details.
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.

Value
xn Vector with initial observations x1 , . . . , xn .
x Vector of observations x1 , . . . , xm that was used to estimate the density.
w The vector of weights that had been used. Depends on the chosen setting for
xgrid.
phi Vector with entries φbm (xi ).
IsKnot Vector with entries IsKnoti = 1{φbm has a kink at xi }.
L The value L(φbm ) of the log-likelihood-function L at the maximum φ
bm .
Fhat A vector (Fbm,i )m
i=1 of the same size as x with entries
Z xi
Fbm,i = exp(φbm (t))dt.
x1

H Vector (H1 , . . . , Hm )0 where Hi is the derivative of

t → L(φ + t∆i )
at zero and ∆i (x) = min(x − xi , 0).
n Number of initial observations.
m Number of unique observations.
knots Observations that correspond to the knots.
mode Mode of the estimated density fˆm .
sig The standard deviation of the initial sample x1 , . . . , xn .
activeSetLogCon 7

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

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 https://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. doi:10.18637/jss.v039.i06

See Also
activeSetLogCon can be used to estimate a log-concave density. However, to generate an object
of class dlc that allows application of summary and plot we recommend to use logConDens.
The following functions are used by activeSetLogCon:
J00, J10, J11, J20, Local_LL, Local_LL_all, LocalCoarsen, LocalConvexity, LocalExtend,
LocalF, LocalMLE, LocalNormalize, MLE
Log concave density estimation via an iterative convex minorant algorithm can be performed using
icmaLogCon.

Examples
## estimate gamma density
set.seed(1977)
n <- 200
x <- rgamma(n, 2, 1)
res <- activeSetLogCon(x, w = rep(1 / n, n), print = FALSE)

## plot resulting functions


par(mfrow = c(2, 2), mar = c(3, 2, 1, 2))
plot(res$x, exp(res$phi), type = 'l'); rug(x)
plot(res$x, res$phi, type = 'l'); rug(x)
plot(res$x, res$Fhat, type = 'l'); rug(x)
plot(res$x, res$H, type = 'l'); rug(x)

## 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


8 activeSetRoutines

q <- quantilesLogConDens(0.9, res)[2]


plot(res$x, res$Fhat, type = 'l'); rug(res$x)
abline(h = 0.9, lty = 3); abline(v = q, lty = 3)

activeSetRoutines Auxiliary Numerical Routines for the Function activeSetLogCon

Description
Functions that are used by activeSetLogCon.

Usage
LocalCoarsen(x, w, IsKnot)
LocalConvexity(x, phi)
LocalExtend(x, IsKnot, x2, phi2)
LocalF(x, phi)
LocalNormalize(x, phi)
LocalMLE(x, w, IsKnot, phi_o, prec)
LocalVariance(x, w = NULL, phi)

Arguments
x Vector of independent and identically distributed numbers, with strictly increas-
ing entries.
w Optional vector of nonnegative weights corresponding to x.
IsKnot Vector with entries IsKnoti = 1{φ has a kink at xi }.
phi Vector with entries φ(xi ).
x2 Vector of same type as x.
phi2 Vector of same type as φ.
phi_o Optional starting vector.
prec Threshold for the directional derivative during Newton-Raphson procedure.

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

See Also
All the above functions are used by activeSetLogCon to estimate a log-concave probability density.
Log concave density estimation via an iterative convex minorant algorithm can be performed using
icmaLogCon.
brightstar 9

brightstar Bright star dataset used to illustrate log-concave density estimation

Description

Dataset that contains the data analyzed in Mizera and Koenker (2009, Section 5). The sample con-
sists of measurements of radial and rotational velocities for the stars from the Bright Star Catalog,
see Hoffleit and Warren (1991).

Usage

data(brightstar)

Format

A data frame with 9092 rows on the following 2 variables.

nr Location of measurements.
rad Measurements of radial velocities.
rot Measurements of rotational velocities.

References

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.
Hoffleit, D., Warren, W.H. (1991). The Bright Star Catalog. Yale University Observatory, New
Heaven.
Mizera, I., Koenker, R. (2010). Quasi-concave density estimation. Ann. Statist., 38(5), 2998–3027.

Examples

# ---- load rotational velocity data ----


data(brightstar)

# ---- compute and plot log-concave estimate ----


# See also Figure 3 in Koenker & Mizera (2009)
x0 <- sort(brightstar[, 3])
res <- logConDens(x0, print = FALSE, smoothed = FALSE)
plot(res, which = "density")
10 confIntBootLogConROC_t0

confIntBootLogConROC_t0
Function to compute a bootstrap confidence interval for the ROC
curve at a given t, based on the log-concave ROC curve

Description
This function computes a bootstrap confidence interval for the ROC curve at a given value false
negative fraction (1 - specificity) t. The ROC curve estimate is based on log-concave densities, as
discussed in Rufibach (2011).

Usage
confIntBootLogConROC_t0(controls, cases, grid = c(0.2, 0.8), conf.level = 0.95,
M = 1000, smooth = TRUE, output = TRUE)

Arguments
cases Values of the continuous variable for the cases.
controls Values of the continuous variable for the controls.
grid Values of 1 - specificity where confidence intervals should be computed at (may
be a vector).
conf.level Confidence level of confidence interval.
M Number of bootstrap replicates.
smooth Logical. Compute confidence interval also for ROC curve estimate based on
smoothed log-concave densities.
output Logical. Show progress of computations?

Value
A list containing the following elements:
qs data.frame with the columns t (false positive fractions where confidence in-
terval is computed at) and the confidence intervals for the ROC curve at grid,
based on the log-concave density estimate.
boot.mat Bootstrap samples for the ROC curve based on the log-concave density estimate.
qs.smooth If smooth = TRUE, same as qs but for the ROC curve based on the smooth log-
concave density estimate.
boot.mat.smooth
If smooth = TRUE, bootstrap samples for the ROC curve based on the smoothed
log-concave density estimate.

Note
The confidence intervals are only valid if observations are independent, i.e. eacht patient only
contributes one measurement, e.g.
evaluateLogConDens 11

Author(s)
Kaspar Rufibach (maintainer)
<kaspar.rufibach@gmail.com>
http://www.kasparrufibach.ch.

References
The reference for computation of these bootstrap confidence intervals is:
Rufibach, K. (2012). A smooth ROC curve estimator based on log-concave density estimates. Int.
J. Biostat., 8(1), 1–29.
The bootstrap competitor based on the empirical ROC curve is described in:
Zhou, X.H. and Qin, G. (2005). Improved confidence intervals for the sensitivity at a fixed level of
specificity of a continuous-scale diagnostic test. Statist. Med., 24, 465–477.

See Also
The ROC curve based on log-concave density estimates can be computed using logConROC. In the
example below we analyze the pancreas data.

Examples
## Not run:
## ROC curve for pancreas data
data(pancreas)
status <- factor(pancreas[, "status"], levels = 0:1, labels = c("healthy", "diseased"))
var <- log(pancreas[, "ca199"])
cases <- var[status == "diseased"]
controls <- var[status == "healthy"]

## compute confidence intervals


res <- confIntBootLogConROC_t0(controls, cases, grid = c(0.2, 0.8), conf.level = 0.95,
M = 1000, smooth = TRUE, output = TRUE)
res

## End(Not run)

evaluateLogConDens Evaluates the Log-Density MLE and Smoothed Estimator at Arbitrary


Real Numbers xs

Description
Based on a "dlc" object generated by logConDens, this function computes the values of

φbm (t)
fbm (t) = exp(φbm (t))
12 evaluateLogConDens
Z t
Fbm (t) = exp(φbm (x))dx
x1


fbm (t) = exp(φb∗m (t))
Z t

Fbm (t) = exp(φb∗m (x))dx
x1

at all real number t in xs. The exact formula for Fbm and t ∈ [xj , xj+1 ] is

 t − xj 
Fbm (t) = Fbm (xj ) + (xj+1 − xj )J φbj , φbj+1 ,
xj+1 − xj

for the function J introduced in Jfunctions. Closed formulas can also be given for fbm

(t) and

Fm (t).
b

Usage

evaluateLogConDens(xs, res, which = 1:5, gam = NULL, print = FALSE)

Arguments

xs Vector of real numbers where the functions should be evaluated at.


res An object of class "dlc", usually a result of a call to logConDens.
which A (sub-)vector of 1:5 specifying which of the above quantities should be com-
puted.
gam Only necessary if smoothed = TRUE. The standard deviation of the normal ker-
nel. If equal to NULL, gam is chosen such that the variances of the original sample
x1 , . . . , xn and fbn∗ coincide. See logConDens for details.
print Progress in computation of smooth estimates is shown.

Value
∗ ∗
Matrix with rows (x0,i , φbm (x0,i ), fbm (x0,i ), Fbm (x0,i ), fbm (x0,i ), Fbm (x0,i )) where x0,i is the i-th
entry of xs.

Author(s)

Kaspar Rufibach, <kaspar.rufibach@gmail.com>,


http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html
icmaLogCon 13

Examples

## estimate gamma density


set.seed(1977)
x <- rgamma(200, 2, 1)
res <- logConDens(x, smoothed = TRUE, print = FALSE)

## compute function values at an arbitrary point


xs <- (res$x[100] + res$x[101]) / 2
evaluateLogConDens(xs, res)

## only compute function values for non-smooth estimates


evaluateLogConDens(xs, res, which = 1:3)

icmaLogCon Computes a Log-Concave Probability Density Estimate via an Itera-


tive Convex Minorant Algorithm

Description

Given a vector of observations xn = (x1 , . . . , xn ) with not necessarily equal entries, activeSetLogCon
first computes vectors xm = (x1 , . . . , xm ) and w = (w1 , . . . , wm ) where wi is the weight of each
Pm
xi s.t. i=1 wi = 1. Then, activeSetLogCon computes a concave, piecewise linear function φbm
on [x1 , xm ] with knots only in {x1 , . . . , xm } such that

m
X Z ∞
L(φ) = wi φ(xi ) − exp(φ(t))dt
i=1 −∞

is maximal. In order to be able to apply the pool - adjacent - violaters algorithm, computations are
performed in the parametrization

  i
X m 
η(φ) = φ1 , η1 + (xi − xi−1 )ηi .
i=2
j=2

To find the maximum of L, a variant of the iterative convex minorant using the pool - adjacent -
violaters algorithm is used.

Usage

icmaLogCon(x, xgrid = NULL, eps = 10^-8, T1 = 2000,


robustif = TRUE, print = FALSE)
14 icmaLogCon

Arguments
x Vector of independent and identically distributed numbers, not necessarily equal.
xgrid Governs the generation of weights for observations. See preProcess for details.
eps An arbitrary real number, typically small. Iterations are halted if the directional
derivative of η → L(η) in the direction of the new candidate is ≤ ε.
T1 Maximal number of iterations to perform.
robustif robustif = TRUE performs the robustification and Hermite interpolation proce-
dure detailed in Rufibach (2006, 2007), robustif = FALSE does not. In the latter
case, convergence of the algorithm is no longer guaranteed.
print print = TRUE outputs log-likelihood in every loop, print = FALSE does not.
Make sure to tell R to output (press CTRL+W).

Value
x Vector of observations x1 , . . . , xm that was used to estimate the density.
w The vector of weights that had been used. Depends on the chosen setting for
xgrid.
f Vector with entries fbm (xi ).
xn Vector with initial observations x1 , . . . , xn .
Loglik The value L(φbm ) of the log-likelihood-function L at the maximum φbm .
Iterations Number of iterations performed.
sig The standard deviation of the initial sample x1 , . . . , xn .

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

References
Rufibach K. (2006) Log-concave Density Estimation and Bump Hunting for i.i.d. Observations.
PhD Thesis, University of Bern, Switzerland and Georg-August University of Goettingen, Ger-
many, 2006.
Available at https://slsp-ube.primo.exlibrisgroup.com/permalink/41SLSP_UBE/17e6d97/
alma99116730175505511.
Rufibach, K. (2007) Computing maximum likelihood estimators of a log-concave density function.
J. Stat. Comput. Simul. 77, 561–574.

See Also
icmaLogCon can be used to estimate a log-concave density. However, to generate an object of class
dlc that allows application of summary and plot one has to use logConDens.
The following functions are used by icmaLogCon:
phieta, etaphi, Lhat_eta, quadDeriv, robust, isoMean.
intECDF 15

Examples
set.seed(1977)
x <- rgamma(200, 2, 1)
## Not run:
res <- icmaLogCon(x, T1 = 2000, robustif = TRUE, print = TRUE)

## plot resulting functions


par(mfrow = c(2, 1), mar = c(3, 2, 1, 2))
plot(x, exp(res$phi), type = 'l'); rug(x)
plot(x, res$phi, type = 'l'); rug(x)

## End(Not run)

intECDF Computes the Integrated Empirical Distribution Function at Arbitrary


Real Numbers in s

Description
Computes the value of

Z t
¯ =
I(t) F̄ (r)d r
x1

where F̄ is the empirical distribution function of x1 , . . . , xm , at all real numbers t in the vector s.
¯ is
Note that t (so all elements in s) must lie in [x1 , xm ]. The exact formula for I(t)

i0
¯ =
X i − 1 i0 − 1
I(t) (xi − xi−1 ) + (t − xi0 )
i=2
n n

where i0 = maxi=1,...,m {xi ≤ t}.

Usage
intECDF(s, x)

Arguments
s Vector of real numbers in [x1 , xm ] where I¯ should be evaluated at.
x Vector x = (x1 , . . . , xm ) of original observations.

Value
Vector of the same length as s, containing the values of I¯ at the elements of s.
16 intF

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

References
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. doi:10.18637/jss.v039.i06
Rufibach K. (2006) Log-concave Density Estimation and Bump Hunting for i.i.d. Observations.
PhD Thesis, University of Bern, Switzerland and Georg-August University of Goettingen, Ger-
many, 2006.
Available at https://slsp-ube.primo.exlibrisgroup.com/permalink/41SLSP_UBE/17e6d97/
alma99116730175505511.

See Also
This function together with intF can be used to check the characterization of the log-concave den-
sity estimator in terms of distribution functions, see Rufibach (2006) and Duembgen and Rufibach
(2009).

Examples
# for an example see the function intF.

intF Computes the Integral of the estimated CDF at Arbitrary Real Num-
bers in s

Description
Based on an object of class dlc as output by the function logConDens, this function gives values of
Z t
I(t)
b = Fb(r)dr
x1

at all numbers in s. Note that t (so all elements in s) must lie in [x1 , xm ]. The exact formula for
I(t)
b is

i0
X 
I(t)
b = Ibi (xi+1 ) + Ibi0 (t)
i=1

where i0 =min{m − 1 , {i : xi ≤ t}} and


intF 17

x
x − xj  fb(xj )(x − xj ) 
Z  ∆x 
j+1
Ij (x) = Fb(r)dr = (x−xj )Fb(xj )+∆xj+1 J φbj , φbj+1 , −
xj ∆φbj+1 ∆xj+1 ∆φbj+1

for x ∈ [xj , xj+1 ], j = 1, . . . , m − 1, ∆vi+1 = vi+1 − vi for any vector v and the function J
introduced in Jfunctions.

Usage

intF(s, res)

Arguments

s Vector of real numbers where the functions should be evaluated at.


res An object of class "dlc", usually a result of a call to logConDens.

Value

Vector of the same length as s, containing the values of Ib at the elements of s.

Author(s)

Kaspar Rufibach, <kaspar.rufibach@gmail.com>,


http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

References

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. doi:10.18637/jss.v039.i06
Rufibach K. (2006) Log-concave Density Estimation and Bump Hunting for i.i.d. Observations.
PhD Thesis, University of Bern, Switzerland and Georg-August University of Goettingen, Ger-
many, 2006.
Available at https://slsp-ube.primo.exlibrisgroup.com/permalink/41SLSP_UBE/17e6d97/
alma99116730175505511.

See Also

This function uses the output of activeSetLogCon. The function intECDF is similar, but based on
the empirical distribution function.
18 isoMean

Examples
## estimate gamma density
set.seed(1977)
x <- rgamma(200, 2, 1)
res <- logConDens(x, smoothed = FALSE, print = FALSE)

## compute and plot the process D(t) in Duembgen and Rufibach (2009)
s <- seq(min(res$x), max(res$x), by = 10 ^ -3)
D1 <- intF(s, res)
D2 <- intECDF(s, res$xn)
par(mfrow = c(2, 1))
plot(res$x, res$phi, type = 'l'); rug(res$x)
plot(s, D1 - D2, type = 'l'); abline(h = 0, lty = 2)

isoMean Pool-Adjacent Violaters Algorithm: Least Square Fit under Mono-


tonicity Constraint

Description
Fits a vector gb with nondecreasing components to the data vector y such that

n
X
(yi − gbi )2
i=1

is minimal (pool - adjacent - violators algorithm). In case a weight vector with positive entries (and
the same size as y) is provided, the function produces an isotonic vector minimizing

n
X
wi (yi − gbi )2 .
i=1

Usage
isoMean(y, w)

Arguments

y Vector (y1 , . . . , yn ) of data points.


w Arbitrary vector (w1 , . . . , wn ) of weights.

Value

Returns vector gb.


Jfunctions 19

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

Examples
## simple regression model
n <- 50
x <- sort(runif(n, 0, 1))
y <- x ^ 2 + rnorm(n, 0, 0.2)
s <- seq(0, 1, by = 0.01)
plot(s, s ^ 2, col = 2, type = 'l', xlim = range(c(0, 1, x)),
ylim = range(c(0, 1 , y))); rug(x)

## plot pava result


lines(x, isoMean(y, rep(1 / n, n)), type = 's')

Jfunctions Numerical Routine J and Some Derivatives

Description
J00 represents the function J(x, y, v), where for real numbers x, y and v ∈ [0, 1],

v
exp(x + v(y − x)) − exp(x)
Z
J(x, y, v) = exp((1 − t)x + ty)dt = .
0 y−x

The functions Jab give the respective derivatives Jab for v = 1, i.e.

∂ a+b
Jab (x, y) = J(x, y).
∂xa ∂y b

Specifically,

exp(y) − exp(x) − (y − x) exp(x)


J10 (x, y) = ;
(y − x)2

(y − x)(exp(x) + exp(y)) + 2(exp(y) − exp(x))


J11 (x, y) = ;
(y − x)3

exp(y) − exp(x) − (y − x) exp(x) − (y − x)2 exp(x)


J20 (x, y) = 2 .
(y − x)3
20 Lhat_eta

Usage

J00(x, y, v)
J10(x, y)
J11(x, y)
J20(x, y)

Arguments

x Vector of length d with real entries.


y Vector of length d with real entries.
v Number in [0, 1]d .

Value

Value of the respective function.

Note

Taylor approximations are used if y − x is small. We refer to Duembgen et al (2011, Section 6) for
details.
These functions are not intended to be invoked by the end user.

Author(s)

Kaspar Rufibach, <kaspar.rufibach@gmail.com>,


http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

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 https://arxiv.org/abs/0707.4643.
Duembgen, L. and Rufibach, K. (2011) logcondens: Computations Related to Univariate Log-
Concave Density Estimation. Journal of Statistical Software, 39(6), 1–28. doi:10.18637/jss.v039.i06

Lhat_eta Value of the Log-Likelihood Function L, where Input is in Eta-


Parametrization
Lhat_eta 21

Description

Gives the value of

m
X Z xm
L(φ) = wi φ(xi ) − exp(φ(t))dt
i=1 x1

where φ is parametrized via

  i
X m 
η(φ) = φ1 , η1 + (xi − xi−1 )ηi .
i=2
j=2

Usage

Lhat_eta(x, w, eta)

Arguments

x Vector of independent and identically distributed numbers, with strictly increas-


ing entries.
w Optional vector of nonnegative weights corresponding to xm .
eta Some vector η of the same length as x and w.

Value

Value L(φ) = L(φ(η)) of the log-likelihood function is returned.

Note

This function is not intended to be invoked by the end user.

Author(s)

Kaspar Rufibach, <kaspar.rufibach@gmail.com>,


http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html
22 Local_LL

Local_LL Value of the Log-Likelihood Function L, where Input is in Phi-


Parametrization

Description

Gives the value of

m
X Z xm
L(φ) = wi φ(xi ) − exp(φ(t))dt.
i=1 x1

Usage

Local_LL(x, w, phi)

Arguments

x Vector of independent and identically distributed numbers, with strictly increas-


ing entries.
w Optional vector of nonnegative weights corresponding to xm .
phi Some vector φ of the same length as x and w.

Value

Value L = L(φ) of the log-likelihood function is returned.

Note

This function is not intended to be invoked by the end user.

Author(s)

Kaspar Rufibach, <kaspar.rufibach@gmail.com>,


http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html
Local_LL_all 23

Local_LL_all Log-likelihood, New Candidate and Directional Derivative for L

Description
Computes the value of the log-likelihood function

m
X Z xm
L(φ) = wi φ(xi ) − exp(φ(t))dt,
i=1 x1

a new candidate for φ via the Newton method as well as the directional derivative of φ → L(φ)
into that direction.

Usage
Local_LL_all(x, w, phi)

Arguments
x Vector of independent and identically distributed numbers, with strictly increas-
ing entries.
w Optional vector of nonnegative weights corresponding to xm .
phi Some vector φ of the same length as x and w.

Value
ll Value L(φ) of the log-likelihood function at φ.
phi_new New candidate for φ via the Newton-method, using the complete Hessian ma-
trix.
dirderiv Directional derivative of φ → L(φ) into the direction φnew .

Note
This function is not intended to be invoked by the end user.

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html
24 logConCI

logConCI Compute pointwise confidence interval for a density assuming log-


concavity

Description
Compute approximate confidence interval for the true log-concave density, on a grid of points. Two
main approaches are implemented: In the first, the confidence interval at a fixed point is based on the
pointwise asymptotic theory for the log-concave maximum likelihood estimator (MLE) developed
in Balabdaoui, Rufibach, and Wellner (2009). In the second, the confidence interval is estimated
via the boostrap.

Usage
logConCI(res, xx0, conf.level = c(0.8, 0.9, 0.95, 0.99)[3],
type = c("DR", "ks", "nrd", "ECDFboot", "NPMLboot")[2],
htype = c("hscv", "hlscv", "hpi", "hns")[4], BB = 500)

Arguments
res An object of class dlc, usually a result of a call to logConDens.
xx0 Vector of grid points at which to calculate the confidence interval.
conf.level Confidence level for the confidence interval(s). The default is 95%.
type Vector of strings indicating type of confidence interval to compute. When type
= ks is chosen, then htype should also be specified. The default is type = ks.
htype Vector of strings indicating bandwidth selection method if type = ks. The de-
fault is htype = hns.
BB number of iterations in the bootstrap if type = NPMLboot or type = ECDFboot.
The default is BB = 500.

Details
In Balabdaoui et al. (2009) it is shown that (if the true density is strictly log-concave) the limiting
distribution of the MLE of a log-concave density fbn at a point x is

n2/5 (fbn (x) − f (x)) → c2 (x)C̄(0).

The nuisance parameter c2 (x) depends on the true density f and the second derivative of its loga-
rithm. The limiting process C̄(0) is found as the second derivative at zero of a particular operator
(called the "envelope") of an integrated Brownian motion plus t4 .
Three of the confidence intervals are based on inverting the above limit using estimated quantiles
of C̄(0), and estimating the nuisance parameter c2 (x). The options for the function logConCI
provide different ways to estimate this nuisance parameter. If type = "DR", c2 (x) is estimated using
derivatives of the smoothed MLE as calculated by the function logConDens (this method does not
perform well in simulations and is therefore not recommended). If type="ks", c2 (x) is estimated
logConCI 25

using kernel density estimates of the true density and its first and second derivatives. This is done
using the R package ks, and, with this option, a bandwidth selection method htype must also be
chosen. The choices in htype correspond to the various options for bandwidth selection available in
ks. If type = "nrd", the second derivative of the logarithm of the true density in c2 (x) is estimated
assuming a normal reference distribution.
Two of the confidence intervals are based on the bootstrap. For type = "ECDFboot" confidence in-
tervals based on re-sampling from the empirical cumulative distribution function are computed. For
type = "NPMLboot" confidence intervals based on re-sampling from the nonparametric maximum
likelihood estimate of log-concave density are computed. Bootstrap confidence intervals take a few
minutes to compute!
The default option is type = "ks" with htype = "hns". Currently available confidence levels are
80%, 90%, 95% and 99%, with a default of 95%.
Azadbakhsh et al. (2014) provides an empirical study of the relative performance of the various
approaches available in this function.

Value
The function returns a list containing the following elements:

fhat MLE evaluated at grid points.


up_DR Upper confidence interval limit when type = DR.
lo_DR Lower confidence interval limit when type = DR.
up_ks_hscv Upper confidence interval limit when type = ks and htype = hscv.
lo_ks_hscv Lower confidence interval limit when type = ks and htype = hscv.
up_ks_hlscv Upper confidence interval limit when type = ks and htype = hlscv.
lo_ks_hlscv Lower confidence interval limit when type = ks and htype = hlscv.
up_ks_hpi Upper confidence interval limit when type = ks and htype = hpi.
lo_ks_hpi Lower confidence interval limit when type = ks and htype = hpi.
up_ks_hns Upper confidence interval limit when type = ks and htype = hns.
lo_ks_hns Lower confidence interval limit when type = ks and htype = hns.
up_nrd Upper confidence interval limit when type = nrd.
lo_nrd Lower confidence interval limit when type = nrd.
up_npml Upper confidence interval limit when type = NPMLboot.
lo_npml Lower confidence interval limit when boot = NPMLboot.
up_ecdf Upper confidence interval limit when boot = ECDFboot.
lo_ecdf Lower confidence interval limit when boot = ECDFboot.

Author(s)
Mahdis Azadbakhsh
Hanna Jankowski, <hkj@yorku.ca>
26 logConCIfunctions

References
Azadbakhsh, M., Jankowski, H. and Gao, X. (2014). Computing confidence intervals for log-
concave densities. Comput. Statist. Data Anal., 75, 248–264.
Baladbaoui, F., Rufibach, K. and Wellner, J. (2009) Limit distribution theory for maximum likeli-
hood estimation of a log-concave density. Ann. Statist., 37(3), 1299–1331.
Tarn Duong (2012). ks: Kernel smoothing. R package version 1.8.10. https://CRAN.R-project.
org/package=ks

Examples

## Not run:
## ===================================================
## Confidence intervals at a fixed point for the density
## ===================================================
data(reliability)
x.rel <- sort(reliability)

# calculate 95
grid <- seq(min(x.rel), max(x.rel), length.out = 200)
res <- logConDens(x.rel)
ci <- logConCI(res, grid, type = c("nrd", "ECDFboot"))

par(las = 1, mar = c(2.5, 3.5, 0.5, 0.5))


hist(x.rel, n = 25, col = gray(0.9), main = "", freq = FALSE,
xlab = "", ylab = "", ylim = c(0, 0.0065), border = gray(0.5))
lines(grid, ci$fhat, col = "black", lwd = 2)
lines(grid, ci$lo_nrd, col = "red", lwd = 2, lty = 2)
lines(grid, ci$up_nrd, col = "red", lwd = 2, lty = 2)
lines(grid, ci$lo_ecdf, col = "blue", lwd = 2, lty = 2)
lines(grid, ci$up_ecdf, col = "blue", lwd = 2, lty = 2)
legend("topleft", col = c("black", "blue", "red"), lwd = 2, lty = c(1, 2, 2), legend =
c("log-concave NPMLE", "CI for type = nrd", "CI for type = ECDFboot"), bty = "n")

## End(Not run)

logConCIfunctions Functions that are used by logConCI

Description
Functions that are used by logConCI and are not intended to be called by the user.

Author(s)
Mahdis Azadbakhsh
Hanna Jankowski, <hkj@yorku.ca>
logConDens 27

References

Azadbakhsh, M., Jankowski, H. and Gao, X. (2014). Computing confidence intervals for log-
concave densities. Comput. Statist. Data Anal., 75, 248–264.
Baladbaoui, F., Rufibach, K. and Wellner, J. (2009). Limit distribution theory for maximum likeli-
hood estimation of a log-concave density. Ann. Statist., 37(3), 1299–1331.
Tarn Duong (2012). ks: Kernel smoothing. R package version 1.8.10. https://CRAN.R-project.
org/package=ks

logConDens Compute log-concave density estimator and related quantities

Description

Compute the log-concave and smoothed log-concave density estimator.

Usage

logConDens(x, xgrid = NULL, smoothed = TRUE, print = FALSE,


gam = NULL, xs = NULL)

Arguments

x Vector of independent and identically distributed numbers, not necessarily unique.


xgrid Governs the generation of weights for observations. See preProcess for details.
smoothed If TRUE, the smoothed version of the log-concave density estimator is also com-
puted.
print print = TRUE outputs the log-likelihood in every loop, print = FALSE does not.
Make sure to tell R to output (press CTRL+W).
gam Only necessary if smoothed = TRUE. The standard deviation of the normal ker-
nel. If equal to NULL, gam is chosen such that the variances of the original sample
x1 , . . . , xn and fbn∗ coincide.
xs Only necessary if smoothed = TRUE. Either provide a vector of support points
where the smoothed estimator should be computed at, or leave as NULL. Then, a
sufficiently width equidistant grid of points will be used.

Details

See activeSetLogCon for details on the computations.


28 logConDens

Value
logConDens returns an object of class "dlc", a list containing the following components: xn, x,
w, phi, IsKnot, L, Fhat, H, n, m, knots, mode, and sig as generated by activeSetLogCon. If
smoothed = TRUE, then the returned object additionally contains f.smoothed, F.smoothed, gam,
and xs as generated by evaluateLogConDens. Finally, the entry smoothed of type "logical"
returnes the value of smoothed.
The methods summary.dlc and plot.dlc are used to obtain a summary and generate plots of the
estimated density.

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

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 https://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. doi:10.18637/jss.v039.i06

Examples
## ===================================================
## Illustrate on simulated data
## ===================================================

## Set parameters
n <- 50
x <- rnorm(n)

res <- logConDens(x, smoothed = TRUE, print = FALSE, gam = NULL,


xs = NULL)
summary(res)
plot(res, which = "density", legend.pos = "topright")
plot(res, which = "log-density")
plot(res, which = "CDF")

## Compute slopes and intercepts of the linear functions that


## compose phi
slopes <- diff(res$phi) / diff(res$x)
intercepts <- -slopes * res$x[-n] + res$phi[-n]
logConDens 29

## ===================================================
## Illustrate method on reliability data
## Reproduce Fig. 2 in Duembgen & Rufibach (2009)
## ===================================================

## Set parameters
data(reliability)
x <- reliability
n <- length(x)
res <- logConDens(x, smooth = TRUE, print = TRUE)
phi <- res$phi
f <- exp(phi)

## smoothed log-concave PDF


f.smoothed <- res$f.smoothed
xs <- res$xs

## compute kernel density


sig <- sd(x)
h <- sig / sqrt(n)
f.kernel <- rep(NA, length(xs))
for (i in 1:length(xs)){
xi <- xs[i]
f.kernel[i] <- mean(dnorm(xi, mean = x, sd = h))
}

## compute normal density


mu <- mean(x)
f.normal <- dnorm(xs, mean = mu, sd = sig)

## ===================================================
## Plot resulting densities, i.e. reproduce Fig. 2
## in Duembgen and Rufibach (2009)
## ===================================================
plot(0, 0, type = 'n', xlim = range(xs), ylim = c(0, 6.5 * 10^-3))
rug(res$x)
lines(res$x, f, col = 2)
lines(xs, f.normal, col = 3)
lines(xs, f.kernel, col = 4)
lines(xs, f.smoothed, lwd = 3, col = 5)
legend("topleft", c("log-concave", "normal", "kernel",
"log-concave smoothed"), lty = 1, col = 2:5, bty = "n")

## ===================================================
## Plot log-densities
## ===================================================
plot(0, 0, type = 'n', xlim = range(xs), ylim = c(-20, -5))
legend("bottomright", c("log-concave", "normal", "kernel",
"log-concave smoothed"), lty = 1, col = 2:5, bty = "n")
rug(res$x)
lines(res$x, phi, col = 2)
lines(xs, log(f.normal), col = 3)
30 logConROC

lines(xs, log(f.kernel), col = 4)


lines(xs, log(f.smoothed), lwd = 3, col = 5)

## ===================================================
## Confidence intervals at a fixed point for the density
## see help file for logConCI()
## ===================================================

logConROC Compute ROC curve based on log-concave estimates for the con-
stituent distributions

Description

The receiver operating characteristic (ROC) curve for two constituent distributions F and G is
defined as

R(t; F, G) = 1 − G(F −1 (1 − t))

for t ∈ [0, 1]. It is typically used to assess the performance of a diagnostic test used to discriminate
between healthy and diseased individuals based on a continuous variable.

Usage

logConROC(cases, controls, grid, smooth = TRUE)

Arguments

cases A vector of measurements for the cases.


controls A vector of measurements for the controls.
grid A vector specifying the grid where the ROC curve is computed on.
smooth Logical, indicating whether ROC curve and AUC should also be computed based
on the smoothed log-concave density estimator.

Details

In Rufibach (2011) it was shown that the ROC curve based on log-concave density estimates exhibit
nice properties for finite sample sizes as well as asymptotically. Its performance is typically much
better than that of the empirical ROC curve and only, if at all, sligthly worse compared to the binor-
mal model when in fact the underlying densities are normal. However, log-concavity encompasses
many parametric densities, so this new model is much more flexible than the binormal one, at little
efficiency sacrifice.
logConROC 31

Value
m Number of control measurements.
n Number of case measurements.
fROC Estimated ROC curve based on the log-concave density estimate.
fROC.smooth Estimated ROC curve based on the smoothed log-concave density estimate.
res0 dlc object as a result of a call to logConDens for the data of the controls.
res1 dlc object as a result of a call to logConDens for the data of the cases.

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch

References
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. doi:10.18637/jss.v039.i06
Rufibach, K. (2012). A smooth ROC curve estimator based on log-concave density estimates. Int.
J. Biostat., 8(1), 1–29.

See Also
Confidence intervals at given false-positive fractions for the ROC curve based on log-concave den-
sities can be computed using confIntBootLogConROC_t0. For the computation of the AUC the
function ROCx is used. In the example below we analyze the pancreas data.

Examples
## ROC curve for pancreas data
data(pancreas)
status <- factor(pancreas[, "status"], levels = 0:1,
labels = c("healthy", "diseased"))
var <- log(pancreas[, "ca199"])
cases <- var[status == "diseased"]
controls <- var[status == "healthy"]

## compute and plot empirical ROC curve


## code modified from https://stat.ethz.ch/pipermail/r-help/2008-October/178531.html
xx <- c(-Inf, sort(unique(c(cases, controls))), Inf)
sens <- sapply(xx, function(x){mean(cases >= x)})
spec <- sapply(xx, function(x){mean(controls < x)})

## compute log-concave ROC curve


grid <- seq(0, 1, by = 1 / 500)
roc.logcon <- logConROC(cases, controls, grid)
32 logconTwoSample

## plot
plot(0, 0, xlim = c(0, 1), ylim = c(0, 1), type = 'l',
main = "ROC curves for pancreas data", xlab = "1 - specificity",
ylab = "sensitivity", pty = 's')
legend("bottomright", c("empirical ROC", "log-concave ROC", "smooth log-concave ROC"),
lty = c(1, 1, 2), lwd = 2, col = 2:4, bty = "n")
segments(0, 0, 1, 1, col = 1)
lines(1 - spec, sens, type = 'l', col = 2, lwd = 2)
lines(grid, roc.logcon$fROC, col = 3, lwd = 2)
lines(grid, roc.logcon$fROC.smooth, col = 4, lwd = 2, lty = 2)

## Not run:
## bootstrap confidence intervals at 1 - specificity = 0.2 and 0.8:
res <- confIntBootLogConROC_t0(controls, cases, grid = c(0.2, 0.8), conf.level = 0.95,
M = 1000, smooth = TRUE, output = TRUE)
res

## End(Not run)

logconTwoSample Compute p-values for two-sample test based on log-concave CDF es-
timates

Description
Compute p-values for a test for the null hypothesis of equal CDFs of two samples. The test statistic
is reminiscient of Kolmogorv-Smirnov’s, but instead of computing it for the empirical CDFs, this
function computes it based on log-concave estimates for the CDFs.

Usage
logconTwoSample(x, y, which = c("MLE", "smooth"), M = 999,
n.grid = 500, display = TRUE, seed0 = 1977)

Arguments
x First data sample.
y Second data sample.
which Indicate for which type of estimate the test statistic should be computed.
M Number of permutations.
n.grid Number of grid points in computation of maximal difference between smoothed
log-concave CDFs. See maxDiffCDF for details.
display If TRUE progress of computations is shown.
seed0 Set seed to reproduce results.
logconTwoSample 33

Details
Given two i.i.d. samples x1 , . . . , xn1 and y1 , . . . , yn2 this function computes a permutation test
p-value that provides evidence against the null hypothesis

H0 : F1 = F2

where F1 , F2 are the CDFs of the samples, respectively. A test either based on the log-concave
MLE or on its smoothed version (see Duembgen and Rufibach, 2009, Section 3) are provided. Note
that computation of the smoothed version takes considerably more time.

Value
p.value A two dimensional vector containing the p-values.
test.stat.orig The test statistics for the original samples.
test.stats A M × 2 matrix containing the test statistics for all the permutations.

Warning
Note that the algorithm that finds the maximal difference for the smoothed estimate is of approxi-
mative nature only. It may fail for very large sample sizes.

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

References
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. doi:10.18637/jss.v039.i06

Examples
## Not run:
n1 <- 30
n2 <- 25
x <- rgamma(n1, 2, 1)
y <- rgamma(n2, 2, 1) + 1
twosample <- logconTwoSample(x, y, which = c("MLE", "smooth")[1], M = 999)

## End(Not run)
34 maxDiffCDF

maxDiffCDF Compute maximal difference between CDFs corresponding to log-


concave estimates

Description

Compute the maximal difference between two estimated log-concave distribution functions, either
the MLEs or the smoothed versions. This function is used to set up a two-sample permutation test
that assesses the null hypothesis of equality of distribution functions.

Usage

maxDiffCDF(res1, res2, which = c("MLE", "smooth"), n.grid = 500)

Arguments

res1 An object of class "dlc", usually a result of a call to logConDens for the first
sample.
res2 An object of class "dlc", usually a result of a call to logConDens for the second
sample.
which Indicate for which type of estimate the maximal difference should be computed.
n.grid Number of grid points used to find zeros of fˆ∗ − fˆ∗ for the smooth estimate.
n1 n2

Details

Given two i.i.d. samples x1 , . . . , xn1 and y1 , . . . , yn2 this function computes the maxima of

D1 (t) = F̂n1 (t) − F̂n2 (t)

and

D2 (t) = F̂n∗1 (t) − F̂n∗2 (t).

Value

test.stat A two-dimensional vector containing the above maxima.


location A two-dimensional vector where the maxima occur.

Warning

Note that the algorithm that finds the maximal difference for the smoothed estimate is of approxi-
mative nature only. It may fail for very large sample sizes.
maxDiffCDF 35

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

References
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. doi:10.18637/jss.v039.i06

Examples
n1 <- 100
n2 <- 120
x <- sort(rgamma(n1, 2, 1))
y <- sort(rgamma(n2, 2, 1))
res1 <- logConDens(x, smoothed = TRUE)
res2 <- logConDens(y, smoothed = TRUE)
d <- maxDiffCDF(res1, res2, n.grid = 200)

## log-concave estimate
xs <- seq(min(res1$xs, res2$xs), max(res1$xs, res2$xs), length = 200)
F1 <- matrix(NA, nrow = length(xs), ncol = 1); F2 <- F1
for (i in 1:length(xs)){
F1[i] <- evaluateLogConDens(xs[i], res1, which = 3)[, "CDF"]
F2[i] <- evaluateLogConDens(xs[i], res2, which = 3)[, "CDF"]
}
par(mfrow = c(1, 2))
plot(xs, abs(F1 - F2), type = "l")
abline(v = d$location[1], lty = 2, col = 3)
abline(h = d$test.stat[1], lty = 2, col = 3)

## smooth estimate
xs <- seq(min(res1$xs, res2$xs), max(res1$xs, res2$xs), length = 200)
F1smooth <- matrix(NA, nrow = length(xs), ncol = 2); F2smooth <- F1smooth
for (i in 1:length(xs)){
F1smooth[i, ] <- evaluateLogConDens(xs[i], res1, which = 4:5)[,
c("smooth.density", "smooth.CDF")]
F2smooth[i, ] <- evaluateLogConDens(xs[i], res2, which = 4:5)[,
c("smooth.density", "smooth.CDF")]
}
plot(xs, abs(F1smooth[, 2] - F2smooth[, 2]), type = "l")
abline(h = 0)
abline(v = d$location[2], lty = 2, col = c(3, 4))
abline(h = d$test.stat[2], lty = 2, col = c(3, 4))
36 MLE

MLE Unconstrained piecewise linear MLE

Description
Given a vector of observations x = (x1 , . . . , xm ) with pairwise distinct entries and a vector of
Pm
weights w = (w1 , . . . , wm ) s.t. i=1 wi = 1, this function computes a function φM LE (repre-
b
m
sented by the vector (φM LE (xi ))i=1 ) supported by [x1 , xm ] such that
b

m
X m−1
X
L(φ) = wi φ(xi ) − (xj+1 − xj )J(φj , φj+1 )
i=1 j=1

is maximal over all continuous, piecewise linear functions with knots in {x1 , . . . , xm }

Usage
MLE(x, w = NA, phi_o = NA, prec = 1e-7, print = FALSE)

Arguments
x Vector of independent and identically distributed numbers, with strictly increas-
ing entries.
w Optional vector of nonnegative weights corresponding to xm .
phi_o Optional starting vector.
prec Threshold for the directional derivative during the Newton-Raphson procedure.
print print = TRUE outputs log-likelihood in every loop, print = FALSE does not.
Make sure to tell R to output (press CTRL+W).

Value
phi Resulting column vector (φbM LE (xi ))m
i=1 .

L Value L(φbM LE ) of the log-likelihood at φbM LE .


Fhat Vector of the same length as x with entries FbM LE,1 = 0 and

k−1
X
FbM LE,k = (xj+1 − xj )J(φj , φj+1 )
j=1

for k ≥ 2.

Note
This function is not intended to be invoked by the end user.
pancreas 37

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

pancreas Data from pancreatic cancer serum biomarker study

Description
First published by Wieand et al (1989), this dataset contains data on serum measurements for a
cancer antigen (CA-125) and a carbohydrate antigen (CA19.9) both of which are measured on a
continuous non-negative scale. The measurements were taken within a case-control study on 90
cases with pancreatic cancer and 51 controls who did not have cancer but pancreatitis. The primary
question of the study was which one of the two biomarkers best distinguishes cases from controls.

Usage
data(pancreas)

Format
A data frame with 141 observations on the following 3 variables.

ca199 CA19.9 measurements.


ca125 CA125 measurements.
status Patient status, 0 for controls and 1 for cases.

Source
The data was downloaded from http://labs.fhcrc.org/pepe/book/ on February 2, 2011.

References
Wieand, S., Gail, M. H., James, B. R., and James, K.L. (1989). A family of nonparametric statistics
for comparing diagnostic markers with paired or unpaired data. Biometrika, 76, 585–592.
Pepe, M.S. (2003) The statistical evaluation of medical tests for classification and prediction. Ox-
ford: Oxford University Press (Section 1.3.3).

See Also
This data is analyzed in the help file for the function logConROC.
38 plot.dlc

plot.dlc Standard plots for a dlc object

Description

plot method for class "dlc". Three plots (selectable by which) are currently available: a plot of
the estimated density, the estimated log-density, or the distribution function corresponding to the
estimated log-concave density. By default, a plot of the density estimate is provided. If smoothed =
TRUE, the smoothed version of the log-concave density estimate (saved in x) is added to the density
and log-density plot. For the CDF, the smoothed version is not contained by default in a dlc object
and needs to be computed when asked to be plotted.

Usage

## S3 method for class 'dlc'


plot(x, which = c("density", "log-density", "CDF"),
add.title = TRUE, legend.pos = "topright", ...)

Arguments

x An object of class "dlc", usually a result of a call to logConDens.


which One of "density", "log-density", or "CDF".
add.title Logical, if TRUE adds a standard title to the plot.
legend.pos Placement of the legend. One of "bottomright", "bottom", "bottomleft",
"left", "topleft", "top", "topright", "right", "center"; or "none" for
not displaying a legend. See legend for details.
... Further arguments.

Details

See activeSetLogCon and evaluateLogConDens for details on the computations.

Value

Chosen plot is generated.

Author(s)

Kaspar Rufibach, <kaspar.rufibach@gmail.com>,


http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html
preProcess 39

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 https://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. doi:10.18637/jss.v039.i06

Examples
## See help file of function "logConDens".

preProcess Compute a weighted sample from initial observations

Description
Generates weights from initial sample.

Usage
preProcess(x, xgrid = NULL)

Arguments
x Vector of independent and identically distributed numbers, not necessarily unique.
xgrid Parameter that governs the generation of weights: If xgrid = NULL a new sample
of unique observations is generated with corresponding vector of weights. If
xgrid is a positive number, observations are binned in a grid with grid length
xgrid. Finally, an entire vector specifying a user-defined grid can be supplied.

Value
x Vector of unique and sorted observations deduced from the input x according to
the specification given by xgrid.
w Vector of corresponding weights, normalized to sum to one.
sig Standard deviation of the inputed observations. This quantity is needed when
computing the smoothed log-concave density estimator via evaluateLogConDens.
n Number of initial observations.

Note
This function is not intended to be invoked by the end user.
40 Q00

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

Q00 Numerical Routine Q

Description
This function is used in the computation of fb∗ and Fb∗ .

Usage
Q00(x, a, u, v, gamma, QFhat = FALSE)

Arguments
x Number at which to compute q and/or Q.
a Vector of length m with real entries.
u Vector of length m with real entries.
v Vector of length m with real entries.
gamma Real number. Standard deviation to be used.
QFhat Logical. Should Q be computed?

Value
The vector(s) q and/or Q.

Note
Taylor approximation is used if a is small. In addition, as described in Duembgen and Rufibach
(2011) at the end of Appendix C, in extreme situations, e.g. when data sets contain extreme spac-
ings, numerical problems may occur in the computation of the function qγ (eq. (7) in Duembgen
and Rufibach, 2011). For it may happen that the exponent is rather large while the difference of
Gaussian CDFs is very small. To moderate these problems, we are using the following bounds:

exp(−m2 /2) Φ(δ) − Φ(−δ) ≤ Φ(b) − Φ(a) ≤ exp(−m2 /2) cosh(mδ) Φ(δ) − Φ(−δ)
 

for arbitrary numbers a < b and m := (a + b)/2, δ := (b − a)/2.


However, the function Q00 is not intended to be invoked by the end user.
qloglin 41

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

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

qloglin Quantile Function In a Simple Log-Linear model

Description
Suppose the random variable X has density function

θ exp(θx)
gθ (x) =
exp(θ) − 1

for an arbitrary real number θ and x ∈ [0, 1]. The function qloglin is simply the quantile function
 
G−1
θ (u) = θ −1
log 1 + (e θ
− 1)u

in this model, for u ∈ [0, 1]. This quantile function is used for the computation of quantiles of Fbm
in quantilesLogConDens.

Usage
qloglin(u, t)

Arguments
u Vector in [0, 1]d where quantiles are to be computed at.
t Parameter θ.

Value
z Vector containing the quantiles G−1
n (ui ) for i = 1, . . . , d.

Note
Taylor approximation is used if θ is small.
This function is not intended to be called by the end user.
42 quadDeriv

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

quadDeriv Gradient and Diagonal of Hesse Matrix of Quadratic Approximation


to Log-Likelihood Function L

Description
Computes gradient and diagonal of the Hesse matrix w.r.t. to η of a quadratic approximation to the
reparametrized original log-likelihood function

m
X Z ∞
L(φ) = wi φ(xi ) − exp(φ(t))dt.
i=1 −∞

where L is parametrized via

  i
X m 
η(φ) = φ1 , η1 + (xi − xi−1 )ηi .
i=2
j=2

φ: vector (φ(xi ))m


i=1 representing concave, piecewise linear function φ,
η: vector representing successive slopes of φ.

Usage
quadDeriv(dx, w, eta)

Arguments
dx Vector (0, xi − xi−1 )m
i=2 .

w Vector of weights as in activeSetLogCon.


eta Vector η.

Value
m × 2 matrix. First column contains gradient and second column diagonal of Hesse matrix.

Note
This function is not intended to be invoked by the end user.
quantilesLogConDens 43

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

See Also
quadDeriv is used by the function icmaLogCon.

quantilesLogConDens Function to compute Quantiles of Fhat

Description
Function to compute p0 -quantile of

Z t
Fbm (t) = fbm (t)dt,
x1

where fbm is the log-concave density estimator, typically computed via logConDens and p0 runs
through the vector ps. The formula to compute a quantile at u ∈ [Fbm (xj ), Fbm (xj+1 )] for j =
1, . . . , n − 1 is:

 u − Fbm (xj ) 
−1
Fbm (u) = xj + (xj+1 − xj )G−1 ,
(xj+1 −xj )(φ
bj+1 −φ
bj )
Fbm (xj+1 ) − Fbm (xj )

where G−1
θ is described in qloglin.

Usage
quantilesLogConDens(ps, res)

Arguments
ps Vector of real numbers where quantiles should be computed.
res An object of class "dlc", usually a result of a call to logConDens.

Value
Returns a data.frame with row (p0,i , q0,i ) where q0,i = inf x {Fbm (x) ≥ p0,i } and p0,i runs through
ps.
44 reliability

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

Examples
## estimate gamma density
set.seed(1977)
x <- rgamma(200, 2, 1)
res <- logConDens(x, smoothed = FALSE, print = FALSE)

## compute 0.95 quantile of Fhat


q <- quantilesLogConDens(0.95, res)[, "quantile"]
plot(res, which = "CDF", legend.pos = "none")
abline(h = 0.95, lty = 3); abline(v = q, lty = 3)

reliability Reliability dataset used to illustrate log-concave density estimation

Description
Dataset that contains the data analyzed in Duembgen and Rufibach (2009, Figure 2).

Usage
data(reliability)

Format
A vector containing the 786 observations analyzed in Duembgen and Rufibach (2009, Figure 2).

Source
The data was taken from Duembgen and Rufibach (2009).

References
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. doi:10.18637/jss.v039.i06

See Also
See the example in logConDens for the analysis of this data.
reparametrizations 45

reparametrizations Changes Between Parametrizations

Description

Given a vector (φ1 , . . . , φm ) representing the values of a piecewise linear concave function at
x1 , . . . , xm , etaphi returns a column vector with the entries

  m
X m 
η = φ1 , η 1 + (xi − xi−1 )ηi .
i=2
j=2

The function phieta returns a vector with the entries

  φ − φ m 
i i−1
φ = η1 , .
xi − xi−1 i=2

Usage

etaphi(x, eta)
phieta(x, phi)

Arguments

x Vector of independent and identically distributed numbers, with strictly increas-


ing entries.
eta Vector with entries ηi = η(xi ).
phi Vector with entries φi = φ(xi ).

Note

These functions are not intended to be invoked by the end user.

Author(s)

Kaspar Rufibach, <kaspar.rufibach@gmail.com>,


http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html
46 rlogcon

rlogcon Generate random sample from the log-concave and the smoothed log-
concave density estimator

Description
Generate a random sample from a distribution with density fˆn and fˆn∗ , as described in Duembgen
and Rufibach (2009, Section 3).

Usage
rlogcon(n, x0)

Arguments
n Size of random sample to be generated.
x0 Sorted vector of independent and identically distributed numbers, not necessar-
ily unique.

Value
X Random sample from fˆn .
X_star Random sample from fˆ∗ .
n

U Uniform random sample of size n used in the generation of X.


Z Normal random sample of size n used in the generation of X_star.
f Computed log-concave density estimator.
f.smoothed List containing smoothed log-concave density estimator, as output by evaluateLogConDens.
x Vector of distinct observations generated from x0.
w Weights corresponding to x.

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

References
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. doi:10.18637/jss.v039.i06
robust 47

Examples

## ===================================================
## Generate random samples as described in Section 3 of
## Duembgen and Rufibach (2009)
## ===================================================
x0 <- rnorm(111)
n <- 22
random <- rlogcon(n, x0)

## sample of size n from the log-concave density estimator


random$X

## sample of size n from the smoothed log-concave density estimator


random$X_star

robust Robustification and Hermite Interpolation for ICMA

Description
Performs robustification and Hermite interpolation in the iterative convex minorant algorithm as
described in Rufibach (2006, 2007).

Usage
robust(x, w, eta, etanew, grad)

Arguments
x Vector of independent and identically distributed numbers, with strictly increas-
ing entries.
w Optional vector of nonnegative weights corresponding to xm .
eta Current candidate vector.
etanew New candidate vector.
grad Gradient of L at current candidate vector η.

Value
Returns a (possibly) new vector η on the segment

(1 − t0 )η + t0 ηnew

such that the log-likelihood of this new η is strictly greater than that of the initial η and t0 is chosen
according to the Hermite interpolation procedure described in Rufibach (2006, 2007).
48 ROCx

Note
This function is not intended to be invoked by the end user.

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html

References
Rufibach K. (2006) Log-concave Density Estimation and Bump Hunting for i.i.d. Observations.
PhD Thesis, University of Bern, Switzerland and Georg-August University of Goettingen, Ger-
many, 2006.
Available at https://slsp-ube.primo.exlibrisgroup.com/permalink/41SLSP_UBE/17e6d97/
alma99116730175505511.
Rufibach, K. (2007) Computing maximum likelihood estimators of a log-concave density function.
J. Stat. Comput. Simul. 77, 561–574.

ROCx Compute ROC curve at a given x based on log-concave estimates for


the constituent distributions

Description
Computes the value of the ROC curve at x (which may be a vector) based on log-concave density
estimates of the constituent distributions.

Usage
ROCx(x, res0, res1, smooth = FALSE)

Arguments
x Vector of numbers in [0, 1] where the ROC curve should be computed at.
res0 dlc object as a result of a call to logConDens for the data of the controls.
res1 dlc object as a result of a call to logConDens for the data of the cases.
smooth Logical. If TRUE kernel smoothed log-concave estimate is used.

Value
A real number or a vector of dimension the same as x, the value of the ROC curve at x.
summary.dlc 49

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch

References
Rufibach, K. (2012). A smooth ROC curve estimator based on log-concave density estimates. Int.
J. Biostat., 8(1), 1–29.

See Also
Used for the computation of AUC in logConROC.

summary.dlc Summarizing log-concave density estimation

Description
summary method for class "dlc".

Usage
## S3 method for class 'dlc'
summary(object, ...)

Arguments
object An object of class "dlc", usually a result of a call to logConDens.
... Further arguments.

Details
See activeSetLogCon and evaluateLogConDens for details on the computations.

Value
The function summary.dlc returns a list of summary statistics of the estimated log-concave density
as well as of its smoothed version (depending on the value of smoothed when calling logConDens).

Warning
Note that the numbering of knots in the output relies on the vector of unique observations.

Author(s)
Kaspar Rufibach, <kaspar.rufibach@gmail.com>,
http://www.kasparrufibach.ch
Lutz Duembgen, <duembgen@stat.unibe.ch>,
https://www.imsv.unibe.ch/about_us/staff/prof_dr_duembgen_lutz/index_eng.html
50 summary.dlc

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 https://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. doi:10.18637/jss.v039.i06

Examples
## See help file of function "logConDens".
Index

∗ datasets intECDF, 15
brightstar, 9 intF, 16
pancreas, 37 isoMean, 18
reliability, 44 Jfunctions, 19
∗ htest Lhat_eta, 20
activeSetLogCon, 5 Local_LL, 22
activeSetRoutines, 8 Local_LL_all, 23
confIntBootLogConROC_t0, 10 logcon-package, 2
evaluateLogConDens, 11 logConCI, 24
icmaLogCon, 13 logConCIfunctions, 26
intECDF, 15 logConDens, 27
intF, 16 logConROC, 30
isoMean, 18 logconTwoSample, 32
Jfunctions, 19 maxDiffCDF, 34
Lhat_eta, 20 MLE, 36
Local_LL, 22 plot.dlc, 38
Local_LL_all, 23 preProcess, 39
logcon-package, 2 Q00, 40
logConCI, 24 qloglin, 41
logConCIfunctions, 26 quadDeriv, 42
logConDens, 27 quantilesLogConDens, 43
logconTwoSample, 32 reparametrizations, 45
maxDiffCDF, 34 rlogcon, 46
MLE, 36 robust, 47
ROCx, 48
plot.dlc, 38
summary.dlc, 49
preProcess, 39
Q00, 40
activeSet (activeSetLogCon), 5
qloglin, 41
activeSetLogCon, 5, 5, 6–8, 13, 17, 27, 28,
quadDeriv, 42
38, 42, 49
quantilesLogConDens, 43 activeSetRoutines, 8
reparametrizations, 45
rlogcon, 46 brightstar, 4, 9
robust, 47
summary.dlc, 49 c2hat (logConCIfunctions), 26
∗ nonparametric confIntBootLogConROC_t0, 3, 10, 31
activeSetLogCon, 5
activeSetRoutines, 8 etaphi, 14, 45
evaluateLogConDens, 11 etaphi (reparametrizations), 45
icmaLogCon, 13 evaluateLogConDens, 3, 11, 28, 38, 39, 46, 49

51
52 INDEX

ftilde (logConCIfunctions), 26 phieta, 14, 45


phieta (reparametrizations), 45
icmaLogCon, 3, 7, 8, 13, 14, 43 plot, 7, 14
intECDF, 3, 15, 17 plot.dlc, 28, 38
intF, 3, 16, 16 preProcess, 6, 14, 27, 39
isoMean, 3, 14, 18 print, 4
J00, 7 Q00, 40
J00 (Jfunctions), 19 qloglin, 41, 41, 43
J10, 7 quadDeriv, 14, 42, 43
J10 (Jfunctions), 19 quantilesLogConDens, 3, 41, 43
J11, 7
J11 (Jfunctions), 19 reliability, 4, 44
J20, 7 reparametrizations, 45
J20 (Jfunctions), 19 rLCD (logConCIfunctions), 26
Jfunctions, 12, 17, 19 rlogcon, 46
robust, 14, 47
legend, 38 ROCx, 31, 48
Lhat_eta, 14, 20
Local_LL, 7, 22 summary, 4, 7, 14
Local_LL_all, 7, 23 summary.dlc, 28, 49
LocalCoarsen, 7
LocalCoarsen (activeSetRoutines), 8
LocalConvexity, 7
LocalConvexity (activeSetRoutines), 8
LocalExtend, 7
LocalExtend (activeSetRoutines), 8
LocalF, 7
LocalF (activeSetRoutines), 8
LocalMLE, 7
LocalMLE (activeSetRoutines), 8
LocalNormalize, 7
LocalNormalize (activeSetRoutines), 8
LocalVariance (activeSetRoutines), 8
log-concave (logcon-package), 2
logcon (logcon-package), 2
logcon-package, 2
logConCI, 3, 24, 26
logConCIfunctions, 26
logConDens, 3, 4, 7, 11, 12, 14, 16, 27, 28, 31,
43, 44, 48, 49
logcondens (logcon-package), 2
logcondens-package (logcon-package), 2
logConROC, 3, 11, 30, 37, 49
logconTwoSample, 3, 32

maxDiffCDF, 32, 34
MLE, 7, 36

pancreas, 4, 11, 31, 37

You might also like