Skip to content

Commit 9b832be

Browse files
committed
fixed index error in lscv; now the bandwidth should be correct
1 parent 76b1574 commit 9b832be

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/KernelDensity.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Base: conv
88
import StatsBase: RealVector, RealMatrix
99
import Distributions: twoπ
1010

11-
export kde, UnivariateKDE, BivariateKDE
11+
export kde, UnivariateKDE, BivariateKDE, bandwidth_lscv
1212

1313
include("univariate.jl")
1414
include("bivariate.jl")

src/univariate.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,11 @@ end
167167
#Silverman's book use the special case of gaussian kernel. Here the method is generalized to any symmetric kernel
168168
function lscv(bandwidth::Real, Yl2::RealVector, kernel::DataType, c::Real, ba::Real, n::Int,M::Int)
169169
dist = kernel_dist(kernel,bandwidth)
170-
zeta_star = zeros(length(Yl2))
171-
for j = 1:length(Yl2)
170+
zeta_star = zeros(length(Yl2)-1)
171+
#M is even, length(Yl2) = M/2+1 and Yl2 =[y[l]^2 for l=0 :1: M/2]
172+
for j = 1:length(Yl2)-1
172173
ksl = real(cf(dist,j*c))
173-
zeta_star[j] = Yl2[j] * (ksl * ksl - 2 * ksl)
174+
zeta_star[j] = Yl2[j+1] * (ksl * ksl - 2 * ksl)
174175
end
175176
#Correct the error in silverman's book
176177
#∫ (cf^2 -2cf)u(s)²ds <- ∑(cf^2 - 2cf)*Yl2*ba²/2pi * c

0 commit comments

Comments
 (0)