[R] Problem in calculation of subpopulation mean in Survey package (Specify survey design with replicate weights)

Kristi Glover kristi.glover at hotmail.com
Fri Dec 23 22:56:36 CET 2016

Hi R users,

I got a problem when I was trying to calculate the population mean for different groups (classes) in using "svrepdesign", It worked when I used entire rows  but when I introduced by classes (groups or strata), it did not work out. I read several documents but I could not figure it out to the fix the problem.

Actually, I do have about 500 data points (rows) in which there are several classes (groups). I developed the design using the svrepdesign, but when I introduced group in calculating mean, it says

""Error in qr.default(weights(design, "analysis"), tol = 1e-05) :
  NA/NaN/Inf in foreign function call (arg 1)"

I think I have to introduce groups in the design and I tried it different ways but it did not work it out. Would you mind to give some hints?I would be very grateful if you could give some hints.

here I have attached a example (format of the data) and the code I used. Thanks for your help.
have a great holidays.



dat<-structure(list(ID = 1:6, group = structure(c(8L, 7L, 7L, 8L,
7L, 7L), .Label = c("groupA", "groupB", "groupC", "groupD", "groupE",
"groupF", "groupG", "groupH"), class = "factor"), ProbSelect = c(0.72,
0.62, 0.62, 0.72, 0.72, 0.62), density = c(28, 227, 65, 132,
13, 227), totalSampled = c(96L, 96L, 96L, 96L, 96L, 96L), pop = c(166L,
166L, 166L, 166L, 166L, 166L), wgt = c(2.42, 2.79, 2.79, 2.42,
2.42, 2.79)), .Names = c("ID", "group", "ProbSelect", "density",
"totalSampled", "pop", "wgt"), row.names = c(NA, 6L), class = "data.frame")


design_dat<-svrepdesign(data=dat, type="bootstrap", weights = I(1/dat$ProbSelect), repweights=W[,-1],scale=bootstrap.results$scale,rscale=bootstrap.results$rscales, combined.weights=TRUE)

svymean(~ density,design=subset(design_dat, group=='groupH'),na.rm=T,digits=2)

"Error in qr.default(weights(design, "analysis"), tol = 1e-05) :

	[[alternative HTML version deleted]]

More information about the R-help mailing list