[R] help--kernel distribution dynamics
eugenesalinas2003 at yahoo.com
Sat Aug 23 20:02:53 CEST 2003
--- Deepayan Sarkar <deepayan at stat.wisc.edu> wrote:
> As a first step, you could create a matrix (with 50
> rows, one for each time
> point) where each row holds the kernel density
> estimate for that time point.
> e.g. (with a grid of size 100 for each estimated
> foo <- matrix(0, 50, 100)
> for (i in 1:50)
> foo[i, ] <- density(rnorm(5000), from = -4, to =
> 4, n = 100)$y
> put your put
> variable here ranges
> Whether a 3D view of this will be very informative
> will depend on your data
> (maybe you could play with the density()
> parameters), but persp() should give
> you something:
> persp(foo, theta = 135, phi = 30, scale = FALSE,
> ltheta = -120, shade = 0.75, border = NA)
Hi, Thanks a lot. This seems like what I want to do. I
don't know all the syntax yet so just a
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
Indiv1 1950 . .
Indiv1 1951 . .
Indiv1 1991 . .
IndivN 1991 . .
so to get the matrix of densities I would write...
for (i in 1950:1991)
> foo[i-1949, ] <- density(x, from = -nn, to =nn,
n = 100)$year
Am I right? thanks, e.
More information about the R-help