Announcement

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

  • Can table1_mc show kruskal wallis testing (or is there similar code to do this, akin to table1_mc)?

    Hi Statalisters!

    I'm a huge fan of table1_mc and use it frequently. I've come across a situation where I have several 4-level variables that I'd like to compare across another four level variable, and would like to present Kruskal Wallis testing (instead of chi-square or exact testing). It looks like table1_mc doesn't currently do this. Is that right?

    Does anyone else have a suggestion for how to present something like this? I'm comparing a list of about 30 laboratory test results across a four-level stratification, and the thought of doing this manually fills me with existential dread.

    I could just run table1_mc without any testing, and manually fill in the p value for the KW test, but the likelihood of errors ... looms large.

    Any recommendation?

    Thanks in advance. I've said it before but it bears repeating: you Statalisters are truly amazing and very helpful.


  • #2
    You have a continuous outcome and you want to joint test of a difference (or uniformity) across the categorical variable by test?

    Comment


    • #3
      Code:
      help table1_mc
      shows this:

      The vars option is required and contains a list of the variable(s) to be included as rows in the table. Each variable must also have a type specified (contn, contln, conts, cat, cate, bin or bine - see above). If the observations are grouped using by(), a significance test is performed to compare each characteristic between groups. contln and contn variables are compared using ANOVA (with and without log transformation of positive values respectively) [equivalent to an independent t-test when 2 groups], conts variables are compared using the Wilcoxon rank-sum (2 groups) or Kruskal-Wallis (>2 groups) test, cat and bin variables are compared using Pearson's chi-square test, and cate and bine variables are compared using Fisher's exact test. Specifying the test option adds a column to the table describing the test used. And specifying the statistic option adds a column to the table describing the value of the test statistic. pairwise123 reports p-values from applying those same tests between 2 groups.
      Code:
          where vartype is one of:
              contn  - continuous, normally distributed  (mean and SD will be reported)
              contln - continuous, log normally distributed (geometric mean and GSD reported)
              conts  - continuous, neither log normally or normally distributed (median and IQR reported)
              cat    - categorical, groups compared using Pearson's chi-square test
              cate   - categorical, groups compared using Fisher's exact test
              bin    - binary (0/1), groups compared using Pearson's chi-square test
              bine   - binary (0/1), groups compared using Fisher's exact test
      --
      Bruce Weaver
      Email: [email protected]
      Version: Stata/MP 18.5 (Windows)

      Comment


      • #4
        This make sense?

        Code:
        clear all
        ** DATA GENERATION
        set obs 4  // 4 groups
        g strat = _n
        expand 30    // 30 tests
        bys strat: g tid = _n
        expand 60
        g result = rgamma(2,2)
        drop if runiform()>0.8  //create some variety in N
        
        ** HLINE PROGRAM  (I'd save this as an ado in your personal files.  Pretty handy.)
        program hline
            args lll
            di `"{hline `lll'}"'
        end
        
        ** GET TEST RESULTS
        capture program drop dotest
        program dotest
        hline 90
        di _col(20) "Group1" _col(35) "Group2" _col(50) "Group3" _col(65) "Group4" _col(80) "p-value"
        hline 90
        forv i = 1/30 {
            qui tabstat result if tid==`i' , by(strat) stats(mean) save
            matrix M = r(Stat1) \ r(Stat2) \ r(Stat3) \ r(Stat4)
            qui tabstat result if tid==`i' , by(strat) stats(sd) save
            matrix S = r(Stat1) \ r(Stat2) \ r(Stat3) \ r(Stat4)
            qui tabstat result if tid==`i' , by(strat) stats(N) save
            matrix N = r(Stat1) \ r(Stat2) \ r(Stat3) \ r(Stat4)
            qui anova result strat if tid==`i'
            local pvalue = Ftail(e(df_m),e(df_r),e(F))
            di "Test `i'" _col(20) "N=" N[1,1] _col(35) "N=" N[2,1] _col(50) "N=" N[3,1] _col(65) "N=" N[4,1] 
            di     _col(20) %3.2f M[1,1] " (" %3.2f S[1,1] ")" ///
                _col(35) %3.2f M[2,1] " (" %3.2f S[2,1] ")" ///
                _col(50) %3.2f M[3,1] " (" %3.2f S[3,1] ")" ///
                _col(65) %3.2f M[4,1] " (" %3.2f S[4,1] ")" ///
                _col(80) %5.4f `pvalue' 
            hline 90
        }
        end
        
        ** DO THE TEST
        dotest

        Comment


        • #5
          Originally posted by George Ford View Post
          You have a continuous outcome and you want to joint test of a difference (or uniformity) across the categorical variable by test?
          Edit: I should have been more clear. I don't have a continuous outcome. This was an internet interview administered to health care providers across the globe.

          I have a variable over which I would like to stratify (World Bank Classification of countries by income level, with four strata: Low Income, Lower Middle Income, Medium Income, and High Income)

          And I have about thirty test variables, each for a specific diagnostic test of differing sophistication, each with three levels of possible answers:

          Test 1: Routinely Accessible, Accessible with some difficulty, Never Accessible
          Test 2: Routinely Accessible, Accessible with some difficulty, Never Accessible
          etc.

          Comment


          • #6
            Originally posted by Bruce Weaver View Post
            Code:
            help table1_mc
            shows this:



            Code:
             where vartype is one of:
            contn - continuous, normally distributed (mean and SD will be reported)
            contln - continuous, log normally distributed (geometric mean and GSD reported)
            conts - continuous, neither log normally or normally distributed (median and IQR reported)
            cat - categorical, groups compared using Pearson's chi-square test
            cate - categorical, groups compared using Fisher's exact test
            bin - binary (0/1), groups compared using Pearson's chi-square test
            bine - binary (0/1), groups compared using Fisher's exact test
            Huh. I looked at the helpfile, and did not find that... Even searching on "Kruskal" didn't find it (I likely misspelled kruskal...)

            Thanks everyone.

            Comment


            • #7
              I suppose my next question might be (less related to Stata, per se), is the Kruskal Wallis test OK to use? I have some small sample sizes in cells (only 8 responses from health care providers in "Lower Income" countries), the data aren't normally distributed, the scales can be interpreted as ordinal...

              Can I force Stata to show me the results for KW, or do I have to go with the provided Chi Square (which may be OK too?)

              Thanks

              Comment

              Working...
              X