Announcement

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

  • Can we use the command of power to plot the power vs sample size curve for non-inferiority test?

    Hello, guys

    I wish you a nice holiday and you achieve your goals this year!

    Now I know how to plot the power vs sample size curve for a two proportional test.

    Code:
    # Two proportions (Fisher-Irwin's exact conditional test)
    
    power twoproportions 0.50 (0.40 0.30 0.20), n(50(50)500) test(fisher) oneside graph
    I wonder how we do the same thing for a non-inferiority test (H0 p1 not equals p2; Ha: p1 = p2)?

    Thank you very much

  • #2
    To my knowledge, Stata's -power- command does not handle non-inferiority tests. You can use the calculator at https://www.sealedenvelope.com/power...y-noninferior/ to get a series of results, and then you can enter those results into a Stata data set and make your own graph.

    By the way, H0 p1 not equals p2; Ha: p1 = p2 is not a correct description of a non-inferiority test. The same website I cited just above has a correct and clear explanation of the null and alternate hypotheses in such a test.

    Comment


    • #3
      Thanks. Should have been H0: p1 < p2; Ha: p1 => p2; p is the risk for bad outcomes;

      Any other packages in Stata has the function? Thanks

      Comment


      • #4
        Originally posted by Tom Hsiung View Post
        Any other packages in Stata has the function?
        Well, search noninferiority brings up artcat in the Stata Journal collection. It's more general, for ordered-categorical outcomes,but the binary case is a subset of those and so it should work.

        But couldn't you just program the Blackwelder equation shown there in the link that Clyde points to?
        Code:
        version 18.0
        
        clear *
        
        mata:
        mata set matastrict on
        
        class Blackwelder {
            private:
                static real scalar f()
                static void postem()
            public:
                static final void sample_size()
        }
        real scalar function Blackwelder::f(real scalar alpha, real scalar beta)
            return((invnormal(alpha) + invnormal(beta))^2)
        void function Blackwelder::postem(real rowvector Results) {
        
            string vector Names
            Names = "n", "pi0", "pi1", "delta", "power", "alpha"
        
            real scalar index; string scalar name
            for (index=1; index<=length(Names);index++) {
                name = "r(" + Names[index] + ")"
                st_numscalar(name, Results[index])
                printf("%s = %8.0g\n", Names[index], Results[index])
            }
        }
        void function Blackwelder::sample_size(
                real scalar pi0,
                real scalar pi1,
                real scalar delta,
                | real scalar power,
                real scalar alpha) {
        
            if (args() < 5) alpha = 1 - st_numscalar("c(level)") / 100
        
            real scalar beta
            if (args() < 4) beta = 0.2
            else beta = 1 - power
        
            real scalar n
            n = f(alpha, beta) * ( pi0 * (1 - pi0) + pi1 * (1 - pi1) ) /
                (pi0 - pi1 - delta)^2
            n = ceil(n)
        
            postem( (n, pi0, pi1, delta, power, alpha) )
        }
        
        end
        
        // Verification against worked example on website
        mata: Blackwelder::sample_size(0.1, 0.2, 0.1, 0.9, 0.05)
        
        *
        * Success rates: reference 0.5; test 0.55 (blue), 0.65 (red), 0.75 (green)
        * Delta (margin of noninferiority): 0.10
        * Power: 70%, 80%, 90%
        * Alpha: default
        *
        frame create ForGraph double(pi1 power) int n
        
        forvalues pi1 = 0.55(0.1)0.75 {
            forvalues power = 0.7(0.1)0.9 {
                quietly {
                    mata: Blackwelder::sample_size(0.5, `pi1', 0.1, `power')
                }
                frame post ForGraph (`pi1') (`power') (r(n))
            }
        }
        
        frame ForGraph {
            graph twoway ///
                line power n if float(pi1) == float(0.55), sort lcolor(blue) || ///
                line power n if float(pi1) == float(0.65), sort lcolor(red) || ///
                line power n if float(pi1) == float(0.75), sort lcolor(green) ///
                    scheme(s2color) legend(off) ///
                    ytitle(Power) ylabel( , format(%04.2f) angle(horizontal) nogrid) ///
                    xtitle(Sample size (per group))
        }
        
        exit

        Comment


        • #5
          Thanks for the feedback. I was thinking yesterday that if we can use the oneside option of the power command to compute the power for a noninferiority test, since the H0 and Ha hypothesis of a noninferiority test is oneside.

          But, the H0 in the screenshot is p2 = p1; Should have been p2 > p1; Any idea?

          And I wish you have a great holiday! Merry Christmas!

          Example,
          Click image for larger version

Name:	Screenshot 2024-12-25 at 1.49.32 PM.png
Views:	1
Size:	207.7 KB
ID:	1769971

          Last edited by Tom Hsiung; 25 Dec 2024, 00:28.

          Comment


          • #6
            Originally posted by Tom Hsiung View Post
            I was thinking yesterday that if we can use the oneside option of the power command to compute the power for a noninferiority test . . .
            With two treatment groups, you cannot.

            In addition to power (or beta) and alpha, in order to obtain sample size you need to specify three parameters: (i) the population proportion in the reference group, (ii) the population proportion in the test group and (iii) the margin of noninferiority. power twoproportions does not allow this latter.

            Comment


            • #7
              three parameters: (i) the population proportion in the reference group, (ii) the population proportion in the test group and (iii) the margin of noninferiority.
              Maybe we could add the margin of inferiority to the endpoint of the reference group. For instance, in my above figure, the reference outcome is 0.30 (e.g., fatality rate is 30%), say, now we think a mortality of 35% is acceptable (the margin is +5%) for this disease. Therefore, in the power calculation step, we set p1 as 0.35. How about this approach? Thanks.

              Comment


              • #8
                Originally posted by Tom Hsiung View Post
                . . . in the power calculation step, we set p1 as 0.35. How about this approach?
                So
                Code:
                power twoproportions 0.3 0.35, power(0.9) alpha(0.05) onesided
                versus
                Code:
                mata: Blackwelder::sample_size(0.3, 0.35, 0.05, 0.9, 0.05)
                Only one of them is for a test of a noninferiority null hypothesis.

                Comment


                • #9
                  Only one of them is for a test of a noninferiority null hypothesis.
                  Thanks for the feedback, Joseph. I will pick up the power command. And thank all the guys who helped me. Have a nice day!

                  Comment


                  • #10
                    I thought about the issue yesterday. It has a problem.

                    The noninferiority test statistic is [(~p2 - ~p1) - margin] /SDd~p, given the standard error of it is SDd~p. This statistic compares the d~P (i.e.(~p2 - ~p1), ) vs the margin. Meanwhile, in the power method I suggested above, the statistic is [~p2 - (~p1 + margin) - 0] / SDd~p, which used to compare with zero. The problem in it is that the SDd~p is not the standard error of the [~p2 - (~p1 + margin)] because SDd~p is the standard error of [~p2 - (~p1)].

                    Comment


                    • #11
                      You can use -artbin- and/or -ssi- to calculate the power, and then use -twoway- plots via simple loop-based approaches to plot the results.

                      https://pubmed.ncbi.nlm.nih.gov/37461744/

                      https://www.stata.com/statalist/arch.../msg00997.html

                      Comment

                      Working...
                      X