[R] bivariate kernel density estimates at point locations (rather than at grid locations)
Strickland, Matthew
cro6 at cdc.gov
Wed Dec 21 18:21:54 CET 2005
Hello Dr. Adelchi Azzalini,
Thank you for your quick response to my question that I posted on the r-help board about bivariate kernel density estimates. I have been using your sm package the past few days and have encountered a problem with estimating the density for only 1 point. I am using R 2.2.0, sm version 2.1-0 on a Windows machine. Example code below:
#The code below creates 3 point locations
x.locs = c(74, 75, 77)
y.locs = c(64, 63, 61)
points = cbind(x.locs, y.locs)
#If I send this data into sm.density everything works fine.
dens = sm.density(points, h=c(1, 1))
#However, if I only wish to send 1 point location to sm.density, i.e.,
points.2 =points[1,]
dens.2 = sm.density(points.2, h=c(1, 1))
R returns to me the error:length(h) != 1
It appears to me that sm.density thinks that my 1 point is a 1-dimensional location rather than a 2-dimensional location, and I am getting an error when I request a bivariate kernel. Do you have any suggestions?
Best,
Matt
-----Original Message-----
From: Adelchi Azzalini [mailto:azzalini at stat.unipd.it]
Sent: Friday, December 16, 2005 2:42 AM
To: Strickland, Matthew
Cc: r-help at stat.math.ethz.ch; adrian at stats.gla.ac.uk
Subject: Re: [R] bivariate kernel density estimates at point locations (rather than at grid locations)
On Thu, 15 Dec 2005 14:21:17 -0500, Strickland, Matthew wrote:
SM> Hi,
SM>
SM> My data consists of a set of point locations (x,y).
SM>
SM> I would like to know if there is a procedure for bivariate kernel
SM> density estimation in R that returns the density estimates at the
SM> observed point locations rather than at grid locations. I have
SM> looked at a number of different routines and they all seem to return
SM> estimates at grid locations.
SM>
One option is to use (from package sm),
sm.density(xy, eval.points=xy, eval.grid=FALSE) where xy in a (n\times 2) matrix.
Best wishes,
Adelchi Azzalini
--
Adelchi Azzalini <azzalini at stat.unipd.it> Dipart.Scienze Statistiche, Università di Padova, Italia tel. +39 049 8274147, http://azzalini.stat.unipd.it/
More information about the R-help
mailing list