plot - implementation of transformed KDE in R -


i following steps @ end of this post implement transformed kernel density estimate (kde) on bounded support [0,+inf[. use transformation trick avoid boundary bias of traditional kde on bounded support (in case, near zero). basically, kde allocates weights observations not exist (outside support), severely underestimates pdf @ boundary (as shows on figure below).

1) regular approach (we observe undesirable boundary bias of kde near zero)

# sample exponential distribution obs=rexp(5e2) hist(obs,freq=false) k=density(obs) lines(k$x,k$y) 

enter image description here

2) transformation approach

enter image description here

# 1) log transform obs pseudo.obs=log(obs) # 2) estimate density of pseudo obs kde pseudo.k=density(pseudo.obs,n=length(obs)) # 3) estimate density of original obs t.density=pseudo.k$y/obs # plot estimation lines(obs,t.density) 

instead of getting similar blue line below should

enter image description here

i'm getting horrible thing enter image description here

i use kde on stupidity without using transformation, because unbounded. here code works:

# before same # 2) estimate density of pseudo obs kde pseudo.k=approxfun(density(pseudo.obs)) # 3) estimate density of original obs seq=seq(min(obs),max(obs),length.out=500) t.density=as.numeric(vector(length=length(seq))) (i in 1:length(seq)){ x=seq[i] t.density[i]=pseudo.k(log(x))/x } # plot result lines(seq,t.density,col="red") 

enter image description here


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -