# [R] How to get the datapoints of an density estimationwithlocfit?

Prof Brian D Ripley ripley at stats.ox.ac.uk
Sun Mar 31 07:18:38 CEST 2002

```On Sun, 31 Mar 2002 Ralf.Kloessinger at student.fh-nuernberg.de wrote:

> Hello!!
>
> At first thank you all for your suggestions and your help.
>
> But I would like to get another group of datas from the density estimation. I don't know if these information are provided by locfit or I should use an other function like plot().
> Description:
> Each number between 1 and 100 (only integer) for example should have only one density value. But I also would like to have the density values of points, where I have no input datas. This is the information I would like to have.
> I tried it with fitted.values(), sink(), locfit()\$x.
> I know this data must be there, because on the graph produced by plot() I can see the values. Or plot() calculates the points for the graph??
>
> Nice to have:
> Input data:   output data :          data range:
> for locfit    density estimation     Result
> 1             0.01                   1
> 2             0.05                   2
>               0.03                   3
>               0.06                   4
> 5             0.02                   5
> ....
>
> Thank you for your help and your time

That's done by predict: see ?predict.locfit.  It's logical: you want to
predict the density at unobserved data points.

There are several other packages in R which do density estimation
and you may find easier to use, for example KernSmooth and its function
locpoly() if you want a close equivalent.

>
> Ralf
>
> > As far as I know, locfit does not store its estimates.  You have to use
> > the fitted.values() function.  So, something like:
> >
> > library(locfit)
> > x <- rnorm(200)
> > f <- locfit( ~ x)
> > fhat <- fitted.values(f)
> > cbind(x, fhat)
> >
> > I think that will give you what you want.
> >
> > -roger
> > _______________________________
> > UCLA Department of Statistics
> > rpeng at stat.ucla.edu
> > http://www.stat.ucla.edu/~rpeng
> >
> > On Fri, 29 Mar 2002, Ralf.Kloessinger at student.fh-nuernberg.de wrote:
> >
> >> Hello!!!
> >>
> >> I'm just a beginner of R.  I work with locfit to get the density from
> >> an numeric vector. It looks good when I plot the graph, but I need the
> >> output data of locfit. For example I need somthing like that (only
> >> integer values for the input): numeric vector (input of locfit)
> >> density (output of locfit)  1 0.05.... 2 0.04.. 3 0.01 ...
> >>
> >> Thank you for your help and your time.
> >>
> >> Ralf Kloessinger
> >> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> >> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> >> Send "info", "help", or "[un]subscribe"
> >> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> >> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> >>
> >
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

--
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```