Hello 
I have a problem using the package survey:
I'm trying to calculate the prevalence of a disease in animals sampled using
a 2 stages sampling system:
first level: farm randomly chosen within 551 farms
second level: animals randomly chosen in the farms
My data base has this aspect:
        num esp Quarters Totcat Totshp Totgt Tbtpos fpc1         Totanim Id_An
115 2045   G    01-Q1      1          1        12      0          551      14   
115
116 2045   G    01-Q1      1          1        12      0          551      14   
116
117 2045   G    01-Q1      1          1        12      0          551      14   
117
118 2045   G    01-Q1      1          1        12      0          551      14   
118
where "num" is the farm ID and where Id_An is the animal ID
 
R accept to design my sampling with the function svydesign
> clustot<-svydesign(id=~num+Id_An, fpc=~fpc1+Totanim, data=tab1)
> summary(clustot)
2 - level Cluster Sampling design
With (419, 11593) clusters.
svydesign(id = ~num + Id_An, fpc = ~fpc1 + Totanim, data = tab1)
Probabilities:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 0.1086  0.3802  0.4986  0.4952  0.6145  0.7476 
Population size (PSUs): 551 
Data variables:
 [1] "num"      "esp"      "Quarters"
"Totcat"   "Totshp"   "Totgt"   
"Tbtpos"   "fpc1"     "Totanim"  "Id_An"
but when I try to get some stat on it I obtain this error message
svymean(~Tbtpos,clustot,na.rm = TRUE)
Erreur dans switch(lonely.psu, certainty = scale * crossprod(x), remove = scale
*  :
  Stratum (1.629) has only one PSU at stage 2> svytotal(~Tbtpos, clustot)
Erreur dans switch(lonely.psu, certainty = scale * crossprod(x), remove = scale
*  :
  Stratum (1.629) has only one PSU at stage 2
and with options(error=recover) I obtain 
  svymean(~Tbtpos,clustot,na.rm = TRUE)
Erreur dans switch(lonely.psu, certainty = scale * crossprod(x), remove = scale
*  :
  Stratum (1.629) has only one PSU at stage 2
Enter a frame number, or 0 to exit   
 1: svymean(~Tbtpos, clustot, na.rm = TRUE)
 2: svymean.survey.design2(~Tbtpos, clustot, na.rm = TRUE)
 3: svyrecvar(x * pweights/psum, design$cluster, design$strata, design$fpc,
postStrata = design$postStrata)
 4: multistage(x, clusters, stratas, fpcs$sampsize, fpcs$popsize, lonely.psu =
getOption("survey.lonely.psu"), one.stage = one.stage, stage = 1, cal
= cal)
 5: by(1:n, list(as.numeric(clusters[, 1])), function(index) {
 6: by.default(1:n, list(as.numeric(clusters[, 1])), function(index) {
 7: by(as.data.frame(data), INDICES, FUN, ...)
 8: by.data.frame(as.data.frame(data), INDICES, FUN, ...)
 9: eval(substitute(tapply(1:nd, IND, FUNx)), data)
10: eval(expr, envir, enclos)
11: tapply(1:11593, list(c(2045, 2046, 2070, 2070, 2070, 2071, 2230, 2280, 2304,
2045, 2045, 2045, 2045, 2045, 2045, 2046, 2046, 2046, 2046, 2046, 2046, 20
12: lapply(split(X, group), FUN, ...)
13: FUN(X[[23]], ...)
14: FUN(data[x, ], ...)
15: multistage(x[index, , drop = FALSE], clusters[index, -1, drop = FALSE],
stratas[index, -1, drop = FALSE], nPSUs[index, -1, drop = FALSE], fpcs[index, -
16: onestage(x, stratas[, 1], clusters[, 1], nPSUs[, 1], fpcs[, 1], lonely.psu =
lonely.psu, stage = stage, cal = cal)
17: tapply(1:NROW(x), list(factor(strata)), function(index) {
18: lapply(split(X, group), FUN, ...)
19: FUN(X[[1]], ...)
20: onestrat(x[index, , drop = FALSE], clusters[index], nPSU[index][1],
fpc[index][1], lonely.psu = lonely.psu, stratum = strata[index][1], stage =
stage,
21: switch(lonely.psu, certainty = scale * crossprod(x), remove = scale *
crossprod(x), adjust = scale * crossprod(x), average = NA * crossprod(x), fail =
I don't understand the error message and I don't know how to ask R to
give me the stratum which has a problem or the problematic stage either ...???
Thanks in advance
AHOUSSOU Sylvie
Vétérinaire Epidémiologiste
CIRAD Domaine Duclos
97 170 Petit-Bourg
tel : 05 90 25 59 47
	[[alternative HTML version deleted]]