Description Usage Arguments Details Value Author(s) References See Also Examples
Conditional quantile estimation from k-nearest neighbors in the explanatory variable space.
1 | kneigh.condquant(x, y, k = 10, p = 0.9)
|
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. |
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].
A vector of quantile of length n.
Julie Carreau
Bishop, C. (1995), Neural Networks for Pattern Recognition, Oxford
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.