Good afternoon! I'm trying to use the Survey package for a stratified sample which has 4 criteria on which the stratification is based. I would like to get the corrected weights and for every element i get a weight of 1 E.g: tipping design <- svydesign (id=~1, strata= ~regiune + size_loc + age_rec_hhh + size_hh, data= tabel) and then weights(design) gives me: 1,1,1,1,1,1,1,1,1,1,1,........... for each element Why is that? What do i do wrong? Thank you! --------------------------------- [[alternative HTML version deleted]]
On 7/9/07 12:36 AM, eugen pircalabelu wrote: > I'm trying to use the Survey package for a stratified sample which has 4 criteria on which the stratification is based. I would like to get the corrected weights and for every element i get a weight of 1 > > E.g: tipping > > design <- svydesign (id=~1, strata= ~regiune + size_loc + age_rec_hhh + size_hh, data= tabel) > and then weights(design) > > gives me: 1,1,1,1,1,1,1,1,1,1,1,........... for each element The weights are all 1 because you haven't told R how they should be calculated. If the sampling weights should be constant within strata, you can simply specify the population figures for each stratum in svydesign's fpc argument and it will calculate the weights for you. Various techniques for adjusting the weights are also supported; see http://faculty.washington.edu/tlumley/survey/example-poststrat.html James -- James Reilly Department of Statistics, University of Auckland Private Bag 92019, Auckland, New Zealand
Hi R-users! I have a problem with the survey package and i would be very grateful if you can help me. A short example: stratum id weight nh Nh y sex 1 1 3 5 15 23 1 1 2 3 5 15 25 1 1 3 3 5 15 27 2 1 4 3 5 15 21 2 1 5 3 5 15 22 1 2 6 4 3 12 33 1 2 7 4 3 12 27 1 2 8 4 3 12 29 2 where nh is size of sample stratum and Nh the corresponding population value, and y is metric variable. Now if i let design <- svydesign( id=~1, data=age, strata=~stratum, fpc=~Nh) then weights(design) gives me 3,3,3,3,3,4,4,4. If i then let x<- postStratify( design, strata=~sex, data.frame(sex=c("1","2"), freq=c(10,15))) the weights become 1 2 3 4 5 6 7 8 2.17 2.17 5.35 5.35 2.17 1.73 1.73 4.28 If i define design <- svydesign( id=~1, data=age ) x<- postStratify( design, strata=~sex, data.frame(sex=c("1","2"), freq=c(10,15))) weights become 2 2 5 5 2 2 2 5 The question: does poststratify recognize that i have already stratified in the first design by stratum and then it post stratifies by sex? and why is that? (because i don't have the full joint distribution, the sex*stratum crossing, in order to apply correctly the post stratify function) I see that Mr Lumley uses the postStratify function when the design does not include strata (eg from ?poststratify: dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc) rclus1<-as.svrepdesign(dclus1) rclus1p<-postStratify(rclus1, ~stype, pop.types) and i use design <- svydesign( id=~1, data=age, strata=~stratum, fpc=~Nh) x<- postStratify( design, strata=~sex, data.frame(sex=c("1","2"), freq=c(10,15))) which has a first strata (stratum from svydesign) and a second strata(sex, from poststratify) Is it correct to use the functions as use them or am i doing something wrong? Thank you ! --------------------------------- Park yourself in front of a world of choices in alternative vehicles. [[alternative HTML version deleted]]
On Thu, 6 Sep 2007, eugen pircalabelu wrote:> Good afternoon! > > I'm trying to use the Survey package for a stratified sample which has > 4 criteria on which the stratification is based. I would like to get the > corrected weights and for every element i get a weight of 1 > > E.g: tipping > > design <- svydesign (id=~1, strata= ~regiune + size_loc + age_rec_hhh > + size_hh, data= tabel) > and then weights(design) > gives me: 1,1,1,1,1,1,1,1,1,1,1,........... for each element >There are two problems. The first is that you have the wrong syntax for strata. If you have one stage of sampling with multiple stratifying factors you need to create a single factor representing the strata. One way is with interaction() design <- svydesign (id=~1, strata= ~interaction(regiune, size_loc, age_rec_hhh, size_hh), data= tabel) Second, you have not specified either weights or population sizes, so R has no way to work out the sampling weights. That's why you get weights of 1. You should also get a warning. -thomas