kneigh.condquant: Conditional quantile estimation from nearest neighbors.

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/condmixt.R

Description

Conditional quantile estimation from k-nearest neighbors in the explanatory variable space.

Usage

1
kneigh.condquant(x, y, k = 10, p = 0.9)

Arguments

x

Matrix of explanatory (independent) variables of dimension d x n, d is the number of variables and n is the number of examples (patterns)

y

Vector of n dependent variables

k

Number of neighbors, default is 10.

p

Probability level, default is 0.99.

Details

For each example j (each column) in the matrix x, its k nearest neighbors in terms of Euclidean distance are identified. Let j1,..., jk be the k nearest neighbors. Then, the conditional quantile is estimated by computing the sample quantile over y[j1],...,y[jk].

Value

A vector of quantile of length n.

Author(s)

Julie Carreau

References

Bishop, C. (1995), Neural Networks for Pattern Recognition, Oxford

See Also

quantile

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
# generate train data
ntrain <- 500
xtrain <- runif(ntrain) 
ytrain <- rfrechet(ntrain,loc = 3*xtrain+1,scale =
0.5*xtrain+0.001,shape=xtrain+1)
plot(xtrain,ytrain,pch=22) # plot train data
qgen <- qfrechet(0.99,loc = 3*xtrain+1,scale =
 0.5*xtrain+0.001,shape=xtrain+1) # compute quantile from generative model
points(xtrain,qgen,pch=".",col="orange")

kquant <- kneigh.condquant(t(xtrain),ytrain,p=0.99) # compute estimated quantile
                                                               
points(xtrain,kquant,pch="o",col="blue")
# sample quantiles are not good in the presence of heavy-tailed data


ytrain <- rlnorm(ntrain,meanlog = 3*xtrain+1,sdlog =
0.5*xtrain+0.001)
dev.new()
plot(xtrain,ytrain,pch=22) # plot train data
qgen <- qlnorm(0.99,meanlog = 3*xtrain+1,sdlog =
 0.5*xtrain+0.001) # compute quantile from generative model
points(xtrain,qgen,pch=".",col="orange")
# compute estimated quantile
kquant <- kneigh.condquant(t(xtrain),ytrain,p=0.99) 

points(xtrain,kquant,pch="o",col="blue") # a bit more reasonable 

condmixt documentation built on July 1, 2020, 6:04 p.m.