Is there any library that can do kernel smoothing function estimates, similar to the ksdensity function in matlab? I know I can install matlab, but I am simply wondering whether we can achieve such functionality all in fortran and use gnuplot or pgfplot for plotting.
The R package npregfast for obtaining nonparametric estimates of regression models with or without factor-by-curve interactions using local polynomial kernel smoothers or splines has Fortran code.
Lol I believe so. I wrote most of the code I am using, it is just that I never have experience with Kernel smoothing or regression, so I don’t have much clue on how to achieve this by myself.
Thank you again for this guidance. I wrote a wrapper of glkern function that mimic the ksdensity in matlab. Here is the function I wrote:
subroutine ksdensity(x, grid, f, bw)
! A MATLAB-like wrapper around glkern
real(wp), intent(in) :: x(:) ! data
real(wp), intent(in) :: grid(:) ! evaluation points
real(wp), intent(out) :: f(:) ! density estimates
real(wp), intent(in), optional :: bw ! bandwidth
integer :: n, m
integer :: ihom, nue, kord, irnd, m1
integer :: ismo
real(wp) :: tl, tu, sig, b
real(wp), allocatable :: s(:)
n = size(x)
m = size(grid)
! Defaults (like MATLAB)
ihom = 0 ! assume homoskedastic errors
nue = 0 ! density estimation, not derivative
kord = 2 ! kernel order 2 (Gaussian)
irnd = 0
m1 = 400
tl = 1.0_wp
tu = 0.0_wp
sig = -1.0_wp
allocate(s(0:n))
if (present(bw)) then
! Use user-supplied bandwidth
b = bw
ismo = -1
else
! Ask glkern to compute bandwidth
ismo = 0
b = 0.0_wp
end if
call glkern(t = grid, x = x, n = n, tt = grid, m = m, &
ihom = ihom, nue = nue, kord = kord, irnd = irnd, &
ismo = ismo, m1 = m1, tl = tl, tu = tu, s = s, &
sig = sig, b = b, y = f)
deallocate(s)
end subroutine ksdensity
Sorry to bother again. I realize (maybe I am still wrong) that the glkern and lokern subroutine are for Epanechnikov kernel but not the normal Gaussian kernel. Do you know any other subroutine that smoothes with Gaussian kernel?