Skip to content

density plot for weighted data

5 messages · r student, David Winsemius, Thomas Lumley

#
I'm trying to create a density plot using census data, where the
weights don't sum to 1.
Warning message:
In density.default(oh$FINCP, weights = oh$PWGTP) :
  sum(weights) != 1  -- will not get true density


How would I go about doing this?


Thanks!
#
On Aug 2, 2011, at 12:51 PM, r student wrote:

            
Wouldn't you just divide by the sum?
#
Like below?

plot(density(oh$FINCP,weights=oh$PWGTP/sum(oh$PWGTP)))
On Tue, Aug 2, 2011 at 10:06 AM, David Winsemius <dwinsemius at comcast.net> wrote:
#
On Aug 2, 2011, at 1:11 PM, r student wrote:

            
I don't understand why you are asking for approval. You are the one  
with the data and know where they came from. We have none of that  
background.
#
On Wed, Aug 3, 2011 at 5:11 AM, r student <studentofr at gmail.com> wrote:
Yes

If you are doing lots of analyses with weighted data you might want to
look at the survey package.  It also has a density estimator, in
svysmooth(), which works very much the same way as density() for
weighted data, but doesn't complain about rescaling the weights.

    -thomas