I am facing a problem with a function in survey package. The function svyvar gives the estimated population variance from a given sampling scheme. I am working with a data having more than four continuous variables. In order to have have population total for all those cont. variables I have written in the following format svyvar(~var1+var2+var3+var4+var5+var6,data) ; var1,var2,...,var6 are 6 cont. variables Now the problem is that,this function works properly when the number of cont. variables are less than or equal to three. But when the number of variables goes beyond three it gives a wrong answer,where we have two estimates for the 1st variable (here it is var1),and one of the variable is dropped,and also estimates differs. Sometimes it comes out to be a negative quantity. Please tell me why these problems are happening. -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-svyvar-in-survey-package-tp3932818p3932818.html Sent from the R help mailing list archive at Nabble.com.
On Mon, Oct 24, 2011 at 4:21 AM, amitava <amtv.statpresi at gmail.com> wrote:> I am facing a problem with a function in survey package. The function svyvar > gives the estimated population variance from a given sampling scheme. ?I am > working with a data having more than four continuous variables. In order to > have have population total for all those cont. variables I have written in > the following format > > svyvar(~var1+var2+var3+var4+var5+var6,data) ; var1,var2,...,var6 are 6 cont. > variables > > Now the problem is that,this function works properly when the number of > cont. variables are less than or equal to three. But when the number of > variables goes beyond three it gives a wrong answer,where we have two > estimates for the 1st variable (here it is var1),and one of the variable is > dropped,and also estimates differs. Sometimes it comes out to be a negative > quantity.You will have to give more information: what you describe does not happen when I use svyvar. For example, using one of the built-in data sets:>data(api) >dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc) > vvariance SE api00 11182.82 1386.414 api99 12735.21 1450.082 ell 285.01 54.081 mobility 127.11 55.790 meals 709.07 102.109> v<-svyvar(~api00+api99, dclus1) > v<-svyvar(~api00+api99+ell+mobility+meals, dclus1) > svyvar(~api00+api99, dclus1)variance SE api00 11183 1386.4 api99 12735 1450.1> svyvar(~ell+mobility, dclus1)variance SE ell 285.01 54.081 mobility 127.11 55.790> svyvar(~meals, dclus1)variance SE meals 709.07 102.11 I assume you are using a current version of survey -- there was a bug in printing svyvar results (though not in calculating them), but that was fixed well over a year ago, as listed in the NEWS file. -- Thomas Lumley Professor of Biostatistics University of Auckland
Respected Sir Thanks for your reply.I am giving a part of my output to clarify my problem.> s=sample(N,n,replace=F) > print(s)[1] 6 29 27 44 37 43 1 10 26 20> srswor_sample_data=getdata(salarydata,s) > attach(srswor_sample_data,warn.conflicts=F) > dsrswor=svydesign(id=~1,weights=rep((N/n),n),fpc=rep(N,n),data=srswor_sample_data) > print(dsrswor)Independent Sampling design svydesign(id = ~1, weights = rep((N/n), n), fpc = rep(N, n), data = srswor_sample_data)> print(svyvar(~salary+yrsemp+priorex+educ+super,dsrswor))variance SE salary 7.1883e+07 2.5445e+07 salary 1.1267e+04 4.8569e+03 yrsemp 9.8333e+00 5.5376e+00 educ 1.1267e+04 4.8569e+03 super 3.2889e+00 1.4384e+00> print(svyvar(~salary+yrsemp+priorex,dsrswor))variance SE salary 7.1883e+07 2.5445e+07 yrsemp 5.6732e+04 1.6373e+04 priorex 9.8222e+00 3.9900e+00 Above svyvar returns different results in two different situations(estimates of population variance of salary). -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-svyvar-in-survey-package-tp3932818p3936205.html Sent from the R help mailing list archive at Nabble.com.
Well, you need to use the current version, then. -thomas On Fri, Oct 28, 2011 at 10:09 PM, amitava <amtv.statpresi at gmail.com> wrote:> I am using Package survey version 3.20 and R 2.11.1. > > --Amitava > > -- > View this message in context: http://r.789695.n4.nabble.com/Problem-with-svyvar-in-survey-package-tp3932818p3947306.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Thomas Lumley Professor of Biostatistics University of Auckland
Thank you Sir.Now it is giving results correctly. --Amitava -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-svyvar-in-survey-package-tp3932818p3984390.html Sent from the R help mailing list archive at Nabble.com.