Skip to content

how to extract weighted data in "survey" package

4 messages · Kristi Glover, Anthony Damico

#
Hi R Users,

Happy New Year


I wanted to see the data after  raw data was adjusted/weighted but I could not get it.  Any suggestions?

I would like to see which data points got more weight after the design was used.


I have given you an example what I tried but I was not successful .


Thanks


library(survey)

data(api)


rawData<-data.frame(API00=apistrat$api00, API99=apistrat$api99)

head(rawData)

dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)

svyplot(api00~api99, design=dstrat, style="bubble")


adjustedData<-data.frame(API00=(~api00, design=dstrat),API99=(~api99, design=dstrat ))

head(adjustedData)
#
# load the survey library
library(survey)

# load the apistrat data.frame
data(api)

# look at the first six records
head(apistrat)

# look at the weight column only
apistrat$pw





On Sun, Jan 1, 2017 at 9:49 AM, Kristi Glover <kristi.glover at hotmail.com>
wrote:

  
  
#
Thank You Anthony for the message.

Why did not I get the same values in the following examples?

To get the adjusted value, should not we just multiphy by weight? For example, I multiplied "api00" by "column "pw" (mean(apistrat$api00*apistrat$pw/100)) but I did not get the same value as of survey package given. I think I did mistake. Any suggestions?




# load the survey library

library(survey)


# load the apistrat data.frame

data(api)


# look at the first six records

head(apistrat)


# look at the weight column only

apistrat$pw

# calcualet mean using raw data and afetr adjusted


svymean(~api00, dstrat)


mean(apistrat$api00*apistrat$pw/100)
#
sum(apistrat$api00*apistrat$pw)/sum(apistrat$pw)

On Sun, Jan 1, 2017 at 11:11 AM, Kristi Glover <kristi.glover at hotmail.com>
wrote: