qkdeSorted: A slightly altered version of qkde from package ks

Description Usage Arguments Details Value Author(s) References Examples

Description

Qkde complains if the output is not sorted. Theoretically it is impossible for this to happen, but in practise floating point error can allow this to occur. This function is a cheap work-around to this problem.

Usage

1
qkdeSorted(p, fhat)

Arguments

p

See qkde in package ks

fhat

See qkde in package ks

Details

See qkde in package ks

Value

See qkde in package ks

Author(s)

Luke Mazur

References

see package ks

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
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (p, fhat) 
{
    if (any(p > 1) | any(p < 0)) 
        stop("p must be <= 1 and >= 0")
    cumul.prob <- pkde(q = fhat$eval.points, fhat = fhat)
    ind <- findIntervalSorted(x = p, vec = cumul.prob)
    quant <- rep(0, length(ind))
    for (j in 1:length(ind)) {
        i <- ind[j]
        if (i == 0) 
            quant[j] <- fhat$eval.points[1]
        else if (i >= length(fhat$eval.points)) 
            quant[j] <- fhat$eval.points[length(fhat$eval.points)]
        else {
            quant1 <- fhat$eval.points[i]
            quant2 <- fhat$eval.points[i + 1]
            prob1 <- cumul.prob[i]
            prob2 <- cumul.prob[i + 1]
            alpha <- (p[j] - prob2)/(prob1 - prob2)
            quant[j] <- quant1 * alpha + quant2 * (1 - alpha)
        }
    }
    return(quant)
  }

MaskJointDensity documentation built on May 2, 2019, 8:28 a.m.