3

I am trying to plot the densities by using non-parametric kernel estimation method. For this purpose 'm using asymmetrical kernels like Weibull, Gamma, Inverse Gaussian, etc. i have successfully plotted the densities as given in their articles. My query is about those graphs which are plotted on single point of x, specially x=0 as given in Birnbaum-Saunders and Lognormal Kernel Estimators for Modelling Durations in High Frequency Financial Data on page # 108 and also some others presented the same thing. Simple density plots can be plotted by using following R code. Kindly guide me how to plot on specific point.

n <- 200
k <- 400
y <- rexp(n, 1)

h <- 0.79 * IQR(y) * length(y) ^ (-1/5)
x <- seq(min(y) + 0.05, max(y), length=k)
Kbs <- matrix(rep(0, k * n), ncol=k)
fhat <- rep(0, k)

########### BS ###########

for (j in 1:k) {
  for (i in 1:n) {
    Kbs[i, j] <- (1 / (2*sqrt(2*h*pi))) *
      ((sqrt(1 / (x[j]*y[i]))) + (sqrt(x[j] / (y[i]^3)))) *
      exp(- (y[i] / (2*h*x[j])) + (1/h) - (x[j]/(2*h*y[i])))
    Kbs[is.nan(Kbs)] <- 0
  }
  fhat[j] <- 1/n * (sum(Kbs[, j]))
}

d1 <- density(y, bw=h)

plot(x, fhat, type="s", ylab="Density Function", lty=1, xlab="Time")
lines(d1, type="p", col="red")
legend("topright", c("Real Density", "Density by Birnbaum-Saunders Kernel"),
       col=c("red", "black"), lty=c(1, 2))

Regards.

jay.sf
  • 60,139
  • 8
  • 53
  • 110
Angel
  • 184
  • 1
  • 14

0 Answers0