Library: | kernel |
See also: | repa rqua rtri rtrian runi |
Quantlet: | rkernpq | |
Description: | Computes the radial kernel of the form: C (1-r^q)^p. |
Usage: | y = rkernpq (x, p, q) | |
Input: | ||
x | n x d matrix of user-defined data | |
p | scalar, positive integer | |
q | scalar, positive integer | |
Output: | ||
y | n x 1 matrix containing the radial kernel |
p=1 q=1 triangle
p=0 q=. uniform
p=1 q=2 epanechnikov
p=2 q=2 quartic/biweight
p=3 q=2 triweight
; Quartic kernel in d dimensions library("kernel") p = 2 q = 2 d = 3 ; choose n points, uniformly distributed in [-1,1]^d n = 1000 x = 2*uniform(n,d)-1 ; compute kernel values y = rkernpq(x, p, q) ; approximate the integral about the kernel ; function in [-1,1]^d sum(y.*2^d/n)
Independent of p, q and d you should get approximately 1 as result. Note that for higher dimensions n has to be increased!
; Quartic kernel in d dimensions library("kernel") p = 2 q = 2 d = 2 ; create uniform grid in [-1,1]^d o = matrix(d) n = 50.*o h = 2/(n-1).*o x0 = -o x = grid(x0, h, n) ; compute kernel values y = rkernpq(x, p, q) ; show kernel function(d<3) library("plot") plot(x~y)
Shows the radial kernel. Note that d can only take the values d=1 or d=2 to show something useful!