Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • chi-square test for r x n tables with weighted data

    stata can carry out a chi-square test for weighted data in a 2 x 2 table using this command svy: tab var1 var 2 , col pearson.

    but it doesnt seem able to do the same for tables with more than 2 levels of outcome or more than two levels of independent variable (RxC).
    any idea on how to mitigate this challenge is highly appreciated
    Last edited by Nazarius Mbona Tumwesigye; 17 Jun 2023, 20:25.

  • #2
    What's your null hypothesis? That frequencies of the outcome are just what you would expect from the joint frequencies of the predictors? That's very specific and limited. I guess most researchers would start with Poisson (loglinear) regression instead.

    Comment


    • #3
      Thanks Nick. our null hypothesis is that there is no significant difference in family planning use in three rounds of surveys (baseline midline and endline) in a community. Actually modified Poisson regression with round of survey as only independent variable and control for a clustering effect can help but i thought there could be a simple start with chi-sq test for the first table in the write up. just like there is with a two by two table. Naz

      Comment


      • #4
        just found that even with linearised poisson the comparison is between two proportions and not more.
        the syntax for comparing attitude to FP use in years 2019, 2021 and 2023 is svy: glm attitudegp3 i.year, family(poisson) link(log) eform
        and you get such a table like below comparing only 2021 and 2019. 2023 is left out.


        Survey: Generalized linear models

        Number of strata = 7 Number of obs = 3,006
        Number of PSUs = 63 Population size = 3,163.3327
        Design df = 56


        Linearized
        attitudegp3 exp(b) Std. Err. t P>t [95% Conf. Interval]

        year

        2021 1.302119 .172184 2.00 0.051 .9990979 1.697046

        _cons .1667956 .0187672 -15.92 0.000 .1331362 .2089648

        Comment


        • #5
          Originally posted by Nazarius Mbona Tumwesigye View Post
          stata can carry out a chi-square test for weighted data in a 2 x 2 table using this command svy: tab var1 var 2 , col pearson.

          but it doesnt seem able to do the same for tables with more than 2 levels of outcome or more than two levels of independent variable (RxC)
          If I'm following you correcty, then I cannot replicate your problem. The command works for me with a 4 × 3 tabulation without a hitch. See below.

          .
          Originally posted by Nazarius Mbona Tumwesigye View Post
          just found that even with linearised poisson the comparison is between two proportions and not more.
          the syntax for comparing attitude to FP use in years 2019, 2021 and 2023 is svy: glm attitudegp3 i.year, family(poisson) link(log) eform
          . . .2023 is left out.
          Ditto, no problem. See below.

          .ÿ
          .ÿversionÿ18.0

          .ÿ
          .ÿclearÿ*

          .ÿ
          .ÿ//ÿseedem
          .ÿsetÿseedÿ502374701

          .ÿ
          .ÿquietlyÿsetÿobsÿ3006

          .ÿgenerateÿbyteÿstratumÿ=ÿruniformint(1,ÿ7)

          .ÿgenerateÿbyteÿpsuÿ=ÿruniformint(1,ÿ9)

          .ÿgenerateÿdoubleÿwgtÿ=ÿruniform(1,ÿ1.1)

          .ÿ
          .ÿgenerateÿbyteÿyearÿ=ÿmod(_n,ÿ3)

          .ÿquietlyÿrecodeÿyearÿ(0=2019)ÿ(1=2021)ÿ(2=2023)

          .ÿ
          .ÿgenerateÿbyteÿattitudegp3ÿ=ÿruniformint(0,ÿ3)

          .ÿ
          .ÿ*
          .ÿ*ÿBeginÿhere
          .ÿ*
          .ÿquietlyÿsvysetÿpsu,ÿweight(wgt)ÿstrata(stratum)

          .ÿ
          .ÿsvy:ÿtabulateÿattitudegp3ÿyear,ÿcolumnÿpearson
          (runningÿtabulateÿonÿestimationÿsample)

          Numberÿofÿstrataÿ=ÿÿ7ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿ=ÿÿÿÿÿÿ3,006
          NumberÿofÿPSUsÿÿÿ=ÿ63ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿPopulationÿsizeÿ=ÿ3,154.5628
          ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿDesignÿdfÿÿÿÿÿÿÿ=ÿÿÿÿÿÿÿÿÿ56

          --------------------------------------
          attitudegÿ|ÿÿÿÿÿÿÿÿÿÿÿÿyearÿÿÿÿÿÿÿÿÿÿÿ
          p3ÿÿÿÿÿÿÿÿ|ÿÿ2019ÿÿÿ2021ÿÿÿ2023ÿÿTotal
          ----------+---------------------------
          ÿÿÿÿÿÿÿÿ0ÿ|ÿ.2636ÿÿ.2644ÿÿ.2534ÿÿ.2605
          ÿÿÿÿÿÿÿÿ1ÿ|ÿ.2429ÿÿ.2503ÿÿ.2383ÿÿ.2438
          ÿÿÿÿÿÿÿÿ2ÿ|ÿ.2206ÿÿ.2151ÿÿ.2566ÿÿ.2308
          ÿÿÿÿÿÿÿÿ3ÿ|ÿ.2729ÿÿ.2702ÿÿ.2517ÿÿ.2649
          ÿÿÿÿÿÿÿÿÿÿ|ÿ
          ÿÿÿÿTotalÿ|ÿÿÿÿÿ1ÿÿÿÿÿÿ1ÿÿÿÿÿÿ1ÿÿÿÿÿÿ1
          --------------------------------------
          Key:ÿColumnÿproportion

          ÿÿPearson:
          ÿÿÿÿUncorrectedÿÿÿchi2(6)ÿÿÿÿÿÿÿÿÿ=ÿÿÿÿ6.0128
          ÿÿÿÿDesign-basedÿÿF(5.52,ÿ309.37)ÿ=ÿÿÿÿ0.9865ÿÿÿÿÿPÿ=ÿ0.4307

          .ÿ
          .ÿsvy:ÿglmÿattitudegp3ÿi.year,ÿfamily(poisson)ÿlink(log)ÿeform
          (runningÿglmÿonÿestimationÿsample)

          Survey:ÿGeneralizedÿlinearÿmodels

          Numberÿofÿstrataÿ=ÿÿ7ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿÿÿ=ÿÿÿÿÿÿ3,006
          NumberÿofÿPSUsÿÿÿ=ÿ63ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿPopulationÿsizeÿ=ÿ3,154.5628
          ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿDesignÿdfÿÿÿÿÿÿÿ=ÿÿÿÿÿÿÿÿÿ56

          ------------------------------------------------------------------------------
          ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿLinearized
          ÿattitudegp3ÿ|ÿÿÿÿÿexp(b)ÿÿÿstd.ÿerr.ÿÿÿÿÿÿtÿÿÿÿP>|t|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
          -------------+----------------------------------------------------------------
          ÿÿÿÿÿÿÿÿyearÿ|
          ÿÿÿÿÿÿÿ2021ÿÿ|ÿÿÿ.9922459ÿÿÿ.0337248ÿÿÿÿ-0.23ÿÿÿ0.820ÿÿÿÿÿ.9269356ÿÿÿÿ1.062158
          ÿÿÿÿÿÿÿ2023ÿÿ|ÿÿÿ1.002579ÿÿÿ.0354516ÿÿÿÿÿ0.07ÿÿÿ0.942ÿÿÿÿÿ.9340181ÿÿÿÿ1.076173
          ÿÿÿÿÿÿÿÿÿÿÿÿÿ|
          ÿÿÿÿÿÿÿ_consÿ|ÿÿÿ1.502739ÿÿÿ.0379495ÿÿÿÿ16.13ÿÿÿ0.000ÿÿÿÿÿ1.428608ÿÿÿÿ1.580717
          ------------------------------------------------------------------------------

          .ÿ
          .ÿexit

          endÿofÿdo-file


          .


          Entirely possible that I'm not getting something right. But could there be something about your dataset that you're not aware of?

          Comment


          • #6
            thanks. let me check with my data set

            Comment

            Working...
            X