Thank you for the reply. I do have another question.

I also want to estimate the derivatives of a density function using the
derivatives of kernel density estimator.

It is easy to write out the estimator, for example, for Gaussian kernel.
The difficulty is
finding the appropriate bandwidth. Is there a function in R that  gives the
bandwidth for derivative kernel estimator for a set of observations?

 I looked at the the function "drvkde". However, it does not seem to return
bandwidth value.

Thank you.



2012/7/26 David L Carlson <dcarl...@tamu.edu>

> If you want a recommendation, why not use the one that comes with the
> manual
> page for density():
>
> ?density
>
> Under bw
>
> "The default, "nrd0", has remained the default for historical and
> compatibility reasons, rather than as a general recommendation, where e.g.,
> "SJ" would rather fit, see also V&R (2002)."
>
> Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S.
> New York: Springer.
>
> ----------------------------------------------
> David L Carlson
> Associate Professor of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
>
> > -----Original Message-----
> > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> > project.org] On Behalf Of Michael Young
> > Sent: Wednesday, July 25, 2012 9:53 PM
> > To: li li
> > Cc: r-help
> > Subject: Re: [R] density
> >
> > I can't help you decide which bandwidth method to use, but here's how
> > you view the density source code...
> >
> > methods("density")
> > density.default
> >
> > On Wed, Jul 25, 2012 at 5:56 PM, li li <hannah....@gmail.com> wrote:
> > >
> > > Hi all,
> > >   I have a question regarding the density function which gives the
> > > kernel density estimator.
> > >   I want to decide the bandwidth when using gaussian kernel, given a
> > set
> > > of
> > > observations. I am not familiar with different methods for  bandwidth
> > > determination.  Below are the different ways in R on deciding the
> > > bandwidth.
> > > Can anyone give an idea on which ones are preferred.
> > >   Also, how can I take a look at the source code for the density
> > function?
> > >   Thank you very much.
> > >         Hannah
> > >
> > >
> > > x <- rnorm(1000)
> > >
> > > > bw.nrd(x)
> > >
> > > [1] 0.2688588
> > >
> > > > bw.nrd0(x)
> > >
> > > [1] 0.2282763
> > >
> > > > bw.ucv(x)
> > >
> > > [1] 0.2112366
> > >
> > > > bw.bcv(x)
> > >
> > > [1] 0.2890085
> > >
> > > Warning message:
> > >
> > > In bw.bcv(x) : minimum occurred at one end of the range
> > >
> > > > bw.SJ(x)
> > >
> > > [1] 0.2716242
> > >
> > > > density(x, give.Rkern=T, kernel="gaussian")
> > >
> > > [1] 0.2820948
> > >
> > > > density(x, kernel="gaussian")
> > >
> > >
> > > Call:
> > >
> > > density.default(x = x, kernel = "gaussian")
> > >
> > >
> > > Data: x (1000 obs.); Bandwidth 'bw' = 0.2283
> > >
> > >
> > >        x                   y
> > >
> > >  Min.   :-3.974672   Min.   :0.0000199
> > >
> > >  1st Qu.:-1.987712   1st Qu.:0.0076405
> > >
> > >  Median :-0.000752   Median :0.0529498
> > >
> > >  Mean   :-0.000752   Mean   :0.1256971
> > >
> > >  3rd Qu.: 1.986208   3rd Qu.:0.2552411
> > >
> > >  Max.   : 3.973168   Max.   :0.3883532
> > >
> > > >
> > >
> > >         [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > R-help@r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide
> > > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> >
> > ______________________________________________
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> > guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to