1
vote
$\begingroup$

I've subsetted and plotted my unweighted data, but I don't see how to make use of my weighting variable "FactBx$expwgt"

#####################################################
plot( density(FactB1$BAV_DIST),  
#### xlim=range( c(FactB1$BAV_DIST, FactB2$BAV_DIST, FactB3$BAV_DIST) ), 
     xlim = c(0, 10),
     main = "Density Plots",
     xlab = "miles",
     col = 2  )

lines(density(FactB2$BAV_DIST), col=3)
lines(density(FactB3$BAV_DIST), col=4)      
lines(density(FactB6$BAV_DIST), col=5)  

TextVect <- c("Walk","Bicycle","Auto{Dropped}","Auto{Parked}")
ColorVect <- c(2,3,4,5)             
LineVect <- c(0,1,2,3)          

mtext(TextVect, side = 1, line = LineVect, col = ColorVect)
###########################################################

I've been using the survey package to do weighted summaries, but I don't see how to do weighted density plots.

$\endgroup$
1
  • $\begingroup$ The density function has a "weights = " parameter; would this be what you want? $\endgroup$ – jbowman Feb 3 '12 at 23:07
4
votes
$\begingroup$

The density function takes a 'weights' parameter. It expects the weights to sum to 1. If you give a vector of weights that don't sum to 1 the estimated density won't be a true density but the shape of the estimate will still be the same.

$\endgroup$
0
votes
$\begingroup$

You should check out the function 'svysmooth' in the survey library documentation.

For example: Make an object 'my.svydesign', a svydesign object that takes into account the survey weights and then do the following:

s <- svysmooth(~YOUR_VARIABLE, my.svydesign, main="Survey weighted")
plot(s[[1]][[1]], s[[1]][[2]], main="Weighted density", type="l")
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.