[R] help--kernel distribution dynamics

Deepayan Sarkar deepayan at stat.wisc.edu
Sat Aug 23 20:22:40 CEST 2003

On Saturday 23 August 2003 13:02, Eugene Salinas wrote:
> Hi, Thanks a lot. This seems like what I want to do. I
> don't know all the syntax yet so just a
> clarification...
> Is the  [....]n = 100)$y there in order to condition
> on y which is the year and derive the conditional
> kernel density? The structure of my data looks like
> this

Nothing so complicated. The value returned by density() is an R object 
(technically a list) with a lot of information, of which the actual density 
estimates are stored in the component named "y", extracted here with $y. (You 
may also want to look at $x if you want to label X-axis of persp, but that 
should be the same for all the density() calls.)

>From help(density),


     If 'give.Rkern' is true, the number R(K), otherwise an object with
     class '"density"' whose underlying structure is a list containing
     the following components. 

       x: the 'n' coordinates of the points where the density is

       y: the estimated density values.

      bw: the bandwidth used.

       N: the sample size after elimination of missing values.

    call: the call which produced the result.

data.name: the deparsed name of the 'x' argument.

  has.na: logical, for compatibility (always FALSE).

To 'condition' on the year, you would somehow have to extract as a numeric 
vector the values of your variable that correspond to that year (this vector 
would go in place of the rnorm(5000) in my example) --- how to do that 
depends on the structure of your data.


More information about the R-help mailing list