Ahoussou Sylvie
2008-Sep-12 13:57 UTC
[R] Fw: Complex sampling survey _ Use of survey package
-------------------------------------------------- From: "Ahoussou Sylvie" <sylvie.ahoussou at antilles.inra.fr> Sent: Friday, September 12, 2008 9:48 AM To: "Thomas Lumley" <tlumley at u.washington.edu> Subject: Re: [R] Complex sampling survey _ Use of survey package> Thanks for your answer > > I think I made a mistake when I recopied the 5 first rows of my database > > here is the table with the comlums of interest > > num esp fpc1 Totanim Id_An > 2045 G 551 12 10 > 2046 C 551 68 11 > 2070 G 551 9 50 > 2070 S 551 9 51 > 2070 S 551 9 52 > > > > yes Totanim is the total number of animals in the farm and num is the > total number of herds > > I keep on obtaining this error message > > clustot<-svydesign(id=~num+ ~ Id_An, fpc=~fpc1+~Totanim, data=tab1) > > Erreur dans as.fpc(fpc, strata, ids) : > FPC implies >100% sampling in some strata. > > > -------------------------------------------------- > From: "Thomas Lumley" <tlumley at u.washington.edu> > Sent: Friday, September 12, 2008 12:02 AM > To: "Ahoussou Sylvie" <sylvie.ahoussou at antilles.inra.fr> > Cc: <r-help at r-project.org> > Subject: Re: [R] Complex sampling survey _ Use of survey package > >> On Thu, 11 Sep 2008, Ahoussou Sylvie wrote: >> >>> Data base = tab1 here are the five first rows of the database (nrow = >>> 11792) >>> >>> >>> >>> >>> num >>> esp >>> Quarters >>> Totcat >>> Totshp >>> Totgt >>> Tbtpos >>> fpc1 >>> Totanim >>> Id_An >>> >>> 10 >>> 2045 >>> G >>> 01-Q1 >>> 0 >>> 0 >>> 12 >>> 1 >>> 551 >>> 10 >>> 10 >>> >>> 11 >>> 2046 >>> G >>> 01-Q1 >>> 8 >>> 0 >>> 60 >>> 1 >>> 551 >>> 11 >>> 11 >>> >>> 50 >>> 2070 >>> G >>> 01-Q1 >>> 0 >>> 3 >>> 6 >>> 1 >>> 551 >>> 50 >>> 50 >>> >>> 51 >>> 2070 >>> S >>> 01-Q1 >>> 0 >>> 3 >>> 6 >>> 1 >>> 551 >>> 51 >>> 51 >>> >>> 52 >>> 2070 >>> S >>> 01-Q1 >>> 0 >>> 3 >>> 6 >>> 1 >>> 551 >>> 52 >>> 52 >>> >>> >> >> This has 11 data values in each row but only 10 variable names. If we >> assume the first number doesn't belong it, the fpc1 column lines up >> correctly, so I will do that. >> >> It is surprising that Id_An is the same as Totanim for each of these five >> records >> >>> >>> - First strata = herds >>> >>> herd's id column = num >>> >>> sampled in 551 herds (column fpc1) >>> >>> >>> >>> - Second strata = animals >>> >>> animal id column= Id_An >>> >>> sampled in Totanim >>> >>> >>> >>> I tried : >>> >>> clustot <- svydesign (id=~num+Id_An, fpc=~fpc1+~Totanim, data=tab1) >>> >> This should be >> clustot <- svydesign (id=~num+Id_An, fpc=~fpc1+Totanim, data=tab1) >> but that doesn't explain the problem >> >> Your svydesign() call looks correct if fpc1 is the total number of herds >> in the population and Totanim is the total number of animals in the >> particular herd. I am not sure from your explanation whether this is how >> the variables are defined. >> >> -thomas >> >> >>> >>> and I get this error message >>> >>> >>> >>>> clustot <- svydesign(id=~num+Id_An, fpc=~fpc1+~Totanim, data=tab1) >>> >>> Erreur dans as.fpc(fpc, strata, ids) : >>> >>> FPC implies >100% sampling in some strata. >>> >>> >>> >>> I don't have any strata with 100% sampling so do you know which >>> arguments of the fonction svydesign I'm supposed to use ? >>> >>> >>> >>> 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]] >>> >>> >> >> Thomas Lumley Assoc. Professor, Biostatistics >> tlumley at u.washington.edu University of Washington, Seattle >> >> >>
Ahoussou Sylvie
2008-Sep-12 14:58 UTC
[R] Fw: Complex sampling survey _ Use of survey package
Hi Tobias, Thanks for your answer but it doesn't change the error message clustot <- svydesign(id=~num+Id_An, fpc=~fpc1+Totanim, data=tab1) Erreur dans as.fpc(fpc, strata, ids) : FPC implies >100% sampling in some strata Maybe the probleme is that in some farms all the animals were examined (100% sampling) which is the case in my study sometimes -------------------------------------------------- From: "Tobias Verbeke" <tobias.verbeke at gmail.com> Sent: Friday, September 12, 2008 10:25 AM To: "Ahoussou Sylvie" <sylvie.ahoussou at antilles.inra.fr> Subject: Re: [R] Fw: Complex sampling survey _ Use of survey package> Hi Sylvie, > > You still use too much tilde signs (~) as Thomas Lumley already pointed > out. > > Replace your line > > clustot <- svydesign(id=~num+ ~ Id_An, fpc=~fpc1+~Totanim, data=tab1) > > with > > clustot <- svydesign(id=~num+Id_An, fpc=~fpc1+Totanim, data=tab1) > > Hope this helps, > Tobias > > P.S. > > "~ num + Id_An" is called a formula in R and is omnipresent as > an interface in R functions > > > Ahoussou Sylvie wrote: >> >> >> -------------------------------------------------- >> From: "Ahoussou Sylvie" <sylvie.ahoussou at antilles.inra.fr> >> Sent: Friday, September 12, 2008 9:48 AM >> To: "Thomas Lumley" <tlumley at u.washington.edu> >> Subject: Re: [R] Complex sampling survey _ Use of survey package >> >>> Thanks for your answer >>> >>> I think I made a mistake when I recopied the 5 first rows of my database >>> >>> here is the table with the comlums of interest >>> >>> num esp fpc1 Totanim Id_An >>> 2045 G 551 12 10 >>> 2046 C 551 68 11 >>> 2070 G 551 9 50 >>> 2070 S 551 9 51 >>> 2070 S 551 9 52 >>> >>> >>> >>> yes Totanim is the total number of animals in the farm and num is the >>> total number of herds >>> >>> I keep on obtaining this error message >>> >>> clustot<-svydesign(id=~num+ ~ Id_An, fpc=~fpc1+~Totanim, data=tab1) >>> >>> Erreur dans as.fpc(fpc, strata, ids) : >>> FPC implies >100% sampling in some strata. >>> >>> >>> -------------------------------------------------- >>> From: "Thomas Lumley" <tlumley at u.washington.edu> >>> Sent: Friday, September 12, 2008 12:02 AM >>> To: "Ahoussou Sylvie" <sylvie.ahoussou at antilles.inra.fr> >>> Cc: <r-help at r-project.org> >>> Subject: Re: [R] Complex sampling survey _ Use of survey package >>> >>>> On Thu, 11 Sep 2008, Ahoussou Sylvie wrote: >>>> >>>>> Data base = tab1 here are the five first rows of the database (nrow = >>>>> 11792) >>>>> >>>>> >>>>> >>>>> >>>>> num >>>>> esp >>>>> Quarters >>>>> Totcat >>>>> Totshp >>>>> Totgt >>>>> Tbtpos >>>>> fpc1 >>>>> Totanim >>>>> Id_An >>>>> >>>>> 10 >>>>> 2045 >>>>> G >>>>> 01-Q1 >>>>> 0 >>>>> 0 >>>>> 12 >>>>> 1 >>>>> 551 >>>>> 10 >>>>> 10 >>>>> >>>>> 11 >>>>> 2046 >>>>> G >>>>> 01-Q1 >>>>> 8 >>>>> 0 >>>>> 60 >>>>> 1 >>>>> 551 >>>>> 11 >>>>> 11 >>>>> >>>>> 50 >>>>> 2070 >>>>> G >>>>> 01-Q1 >>>>> 0 >>>>> 3 >>>>> 6 >>>>> 1 >>>>> 551 >>>>> 50 >>>>> 50 >>>>> >>>>> 51 >>>>> 2070 >>>>> S >>>>> 01-Q1 >>>>> 0 >>>>> 3 >>>>> 6 >>>>> 1 >>>>> 551 >>>>> 51 >>>>> 51 >>>>> >>>>> 52 >>>>> 2070 >>>>> S >>>>> 01-Q1 >>>>> 0 >>>>> 3 >>>>> 6 >>>>> 1 >>>>> 551 >>>>> 52 >>>>> 52 >>>>> >>>>> >>>> >>>> This has 11 data values in each row but only 10 variable names. If we >>>> assume the first number doesn't belong it, the fpc1 column lines up >>>> correctly, so I will do that. >>>> >>>> It is surprising that Id_An is the same as Totanim for each of these >>>> five records >>>> >>>>> >>>>> - First strata = herds >>>>> >>>>> herd's id column = num >>>>> >>>>> sampled in 551 herds (column fpc1) >>>>> >>>>> >>>>> >>>>> - Second strata = animals >>>>> >>>>> animal id column= Id_An >>>>> >>>>> sampled in Totanim >>>>> >>>>> >>>>> >>>>> I tried : >>>>> >>>>> clustot <- svydesign (id=~num+Id_An, fpc=~fpc1+~Totanim, data=tab1) >>>>> >>>> This should be >>>> clustot <- svydesign (id=~num+Id_An, fpc=~fpc1+Totanim, data=tab1) >>>> but that doesn't explain the problem >>>> >>>> Your svydesign() call looks correct if fpc1 is the total number of >>>> herds in the population and Totanim is the total number of animals in >>>> the particular herd. I am not sure from your explanation whether this >>>> is how the variables are defined. >>>> >>>> -thomas >>>> >>>> >>>>> >>>>> and I get this error message >>>>> >>>>> >>>>> >>>>>> clustot <- svydesign(id=~num+Id_An, fpc=~fpc1+~Totanim, data=tab1) >>>>> >>>>> Erreur dans as.fpc(fpc, strata, ids) : >>>>> >>>>> FPC implies >100% sampling in some strata. >>>>> >>>>> >>>>> >>>>> I don't have any strata with 100% sampling so do you know which >>>>> arguments of the fonction svydesign I'm supposed to use ? >>>>> >>>>> >>>>> >>>>> 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]] >>>>> >>>>> >>>> >>>> Thomas Lumley Assoc. Professor, Biostatistics >>>> tlumley at u.washington.edu University of Washington, Seattle >>>> >>>> >>>> >> >> ______________________________________________ >> 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
2008-Sep-14 21:57 UTC
[R] Fw: Complex sampling survey _ Use of survey package
On Fri, 12 Sep 2008, Ahoussou Sylvie wrote:> > > -------------------------------------------------- > From: "Ahoussou Sylvie" <sylvie.ahoussou at antilles.inra.fr> > Sent: Friday, September 12, 2008 9:48 AM > To: "Thomas Lumley" <tlumley at u.washington.edu> > Subject: Re: [R] Complex sampling survey _ Use of survey package > >> Thanks for your answer >> >> I think I made a mistake when I recopied the 5 first rows of my database >> >> here is the table with the comlums of interest >> >> num esp fpc1 Totanim Id_An >> 2045 G 551 12 10 >> 2046 C 551 68 11 >> 2070 G 551 9 50 >> 2070 S 551 9 51 >> 2070 S 551 9 52 >> >> yes Totanim is the total number of animals in the farm and num is the total >> number of herdsDo you mean 'fpc1 is the total number of herds'? That is what your svydesign() call says.>> I keep on obtaining this error message >> >> clustot<-svydesign(id=~num+ ~ Id_An, fpc=~fpc1+~Totanim, data=tab1) >> >> Erreur dans as.fpc(fpc, strata, ids) : >> FPC implies >100% sampling in some strata.Well, we seem to have either a bug or a problem with the data. If you do options(error=recover) before the svydesign() call you can go into as.fpc() and look at the data. As an example; Error in as.fpc(fpc, strata, ids) : FPC implies >100% sampling in some strata. Enter a frame number, or 0 to exit 1: svydesign(id = ~dnum + snum, fpc = ~fpc1 + I(pmin(fpc2, 4)), data = apiclus2) 2: svydesign.default(id = ~dnum + snum, fpc = ~fpc1 + I(pmin(fpc2, 4)), data = apiclus2) 3: as.fpc(fpc, strata, ids) Selection: 3 Called from: eval(expr, envir, enclos) Browse[1]> which(sampsize>popsize, arr.ind=TRUE) row col 22 22 2 23 23 2 24 24 2 ... Browse[1]> sampsize[22,2] [1] 5 Browse[1]> popsize[22,2] [1] 4 Browse[1]> ids[22,] dnum snum 22 200 200.841 So in this case one of the problems is in dnum 200, snum 841, where the population size was specified as 4 but the sample size is 5. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle