Re: [R] bivariate kernel density estimates at point locations (rather than at grid locations)

From: Strickland, Matthew <>
Date: Thu 22 Dec 2005 - 04:21:54 EST

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?


-----Original Message-----
From: Adelchi Azzalini [] Sent: Friday, December 16, 2005 2:42 AM
To: Strickland, Matthew
Cc:; 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> My data consists of a set of point locations (x,y). 
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.

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  <> Dipart.Scienze Statistiche, UniversitÓ di Padova, Italia tel. +39 049 8274147,

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Thu Dec 22 04:29:42 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:40 EST