I need some guidance from someone who is familiar/has some experience with the survey package. The data that I am using is from the Medical Expenditure Panel Survey (www.meps.ahrq.gov <http://www.meps.ahrq.gov/> ). The STRATA and PSU variables are varstr01 and varpsu01 respectively. When I try to specify them with the svydesign function I get an error message. An excerpt of my session is as follows... library(foreign)> h60 <- read.xport("h:\\meps\\temptransports\\h60.tpt")> names(h60) <- casefold(names(h60))> names(h60)[1] "dupersid" "sex" "inscov01" "totexp01" "perwt01f" "varstr01" "varpsu01"> library(survey)> meps.design <- svydesign(id=~varpsu01, strata=~varstr01, weight=~perwt01f,data=h60) Error in svydesign(id = ~varpsu01, strata = ~varstr01, weight = ~perwt01f, : Clusters not nested in strata>I'm not sure what is causing this error message or how to get around it (i.e., remedy the problem). Any insight would be much appreciated. Thanks. Marc Marc W. Zodet, MS Senior Health Statistician Agency for Healthcare Research and Quality Center for Financing, Access, and Cost Trends Division of Statistical Research and Methods 540 Gaither Road, Room 5058 Rockville, Maryland 20850 Phone: 301-427-1563 FAX: 301-427-1276 E-mail: <mailto:mzodet@ahrq.gov> mzodet@ahrq.gov [[alternative HTML version deleted]]
On Fri, 23 Jul 2004 12:23:35 -0400 "Zodet, Marc" <MZodet at ahrq.gov> wrote:> I need some guidance from someone who is familiar/has some experience with > the survey package. > > > > The data that I am using is from the Medical Expenditure Panel Survey > (www.meps.ahrq.gov <http://www.meps.ahrq.gov/> ). The STRATA and PSU > variables are varstr01 and varpsu01 respectively. When I try to specify > them with the svydesign function I get an error message. An excerpt of my > session is as follows... > > > > library(foreign) > > > h60 <- read.xport("h:\\meps\\temptransports\\h60.tpt") > > > names(h60) <- casefold(names(h60)) > > > names(h60) > > [1] "dupersid" "sex" "inscov01" "totexp01" "perwt01f" "varstr01" > "varpsu01" > > > library(survey) > > > meps.design <- svydesign(id=~varpsu01, strata=~varstr01, weight=~perwt01f, > data=h60) > > Error in svydesign(id = ~varpsu01, strata = ~varstr01, weight = ~perwt01f, > : > > Clusters not nested in strata > > > > > > > I'm not sure what is causing this error message or how to get around it > (i.e., remedy the problem). Any insight would be much appreciated.Hi, I guess the most common way of proceeding is to first stratify, and then to sample clusters independently within each stratum. If this is the case, your data file can be put together like stratum psu ... 1 1 1 2 1 3 2 1 2 2 2 3 or like stratum psu ... 1 1 1 2 1 3 2 4 2 5 2 6 svydesign only likes the first data structure so if this is not the case (clusters not 'nested' in your strata) you should tell svydesign to nest (relabel) the clusters for you by passing the argument nest = TRUE to svydesign. In other words: meps.design <- svydesign(ids = ~varpsu01, strata = ~varstr01, weights = ~perwt01f, nest = TRUE, data = h60) should work. See ?svydesign. HTH, Tobias
On Fri, 23 Jul 2004, Tobias Verbeke wrote:> I guess the most common way of proceeding is to first stratify, > and then to sample clusters independently within each stratum. > If this is the case, your data file can be put together like > > stratum psu ... > 1 1 > 1 2 > 1 3 > 2 1 > 2 2 > 2 3 > > or like > > stratum psu ... > 1 1 > 1 2 > 1 3 > 2 4 > 2 5 > 2 6 > > svydesign only likes the first data structure soThis is exactly backwards. svydesign by default assumes the *second* data structure.> > meps.design <- svydesign(ids = ~varpsu01, strata = ~varstr01, > weights = ~perwt01f, nest = TRUE, data = h60) > > should work. See ?svydesign.This fix is correct, even if the rationale is backwards. -thomas