Re: [R] Probability weights with density estimation

From: David Winsemius <>
Date: Fri, 18 Jan 2008 04:00:13 +0000 (UTC)

"Charles C. Berry" <> wrote in

> On Wed, 16 Jan 2008, David Winsemius wrote:

>> I am a physician examining an NHANES dataset available at the
>> NCHS website: snip
>> TC.ran <- exp(rnorm(400,1.5,.3))
>> HDL.ran <- exp(rnorm(400,.4,.3) )
>> f1<-kde2d(HDL.ran,TC.ran,n=25,lims=c(0,4,2,10))
>> contour(f1$x,f1$y,f1$z,ylim=c(0,8),xlim=c(0,3),ylab="TC mmol/L",
>> xlab="HDL mmol/L")
>> lines(f1$x,5*f1$x) # iso-ratio lines
>> lines(f1$x,4*f1$x)
>> lines(f1$x,3*f1$x)
>> Two questions:
>> Is there a 2d density estimation function that has provision for
>> probability weights (or inverse sampling probabilities)?
> It looks like you can use bkde2D from the KernSmooth package.
> You might look at the function sqlocpoly in surveyNG which uses 
> the KernSmooth package for details.

The prospect of setting up an SQL database was rather daunting and I continued my search. There were references in the the sql.. functions' documentation that they were providing the functions in package Locfit. Finding locfit() provided the weighting options I needed. This is what I came up with: <- with(small.nh.chol,

plot(        #give warnings but does work                  
title(main="Weighted", xlab="HDL", ylab="TC")
# add labels _after_ plotting.
# never could figure out how to get plot() to accept xlab or ylab 
# when passing the locfit object to it. 
with(, lines(x,x*4))
and thank you, Andy Liaw, for helpful earlier posts;
David Winsemius

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 18 Jan 2008 - 04:06:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 18 Jan 2008 - 07:30:06 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive