Announcement

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

  • randomisation in stepped wedge cluster RCT

    Hi Statalisters,

    Does anyone know about any Stata community-contributed command to carry out randomisation in a stepped wedge cluster randomised trial?

    If none, any suggested approach to actualise this will be appreciated. I have searched through the web without any success.

    Thanks you

  • #2
    Code:
    set seed `=strreverse("1521102")'
    
    isid cluster_id, sort // reproducible starting point
    generate double randu = runiform()
    isid randu, sort
    generate int trt_seq = _n

    Comment


    • #3
      It is understood that randomization is an important aspect of any trial. However, what is the purpose of it in the context of the dataset and analysis?

      Also, the code above assigns a randomization number to each observation, but in a stepped-wedged context, all individuals within a cluster should be part of the same randomization sequence.

      Comment


      • #4
        Originally posted by Jack Chau View Post
        . . . the code above assigns a randomization number to each observation
        No, it doesn't. Take another look at it.

        what is the purpose of it in the context of the dataset and analysis?
        See above; your premise is off:
        the dataset referenced is not of the study's results, but rather is the list of IDs assigned to clusters. The sequence of switching clusters to treatment during the course of the study is what's being randomized.
        Maybe the OP's conundrum is what do you do when not all clusters have enrolled—have not even been identified—at the beginning of the study when the sequence of switching them to treatment needs to be randomized?

        Comment


        • #5
          Hi Joseph,
          Thanks for your sample code above. I think in this your example assumes that a cluster forms a step. Assuming groups of clusters forms a step (e.g. 20 hospitals are randomized into 5 intervention periods or 5 steps, which means that 4 hospitals forms a step or are to be randomized into an intervention period), how would you manipulate this?

          Also in this approach as exampled in #2 above, how possible is it to accommodate stratification by 2 factors for example?

          Comment


          • #6
            Originally posted by Madu Abuchi View Post
            Hi Joseph,
            Thanks for your sample code above. I think in this your example assumes that a cluster forms a step. Assuming groups of clusters forms a step (e.g. 20 hospitals are randomized into 5 intervention periods or 5 steps, which means that 4 hospitals forms a step or are to be randomized into an intervention period), how would you manipulate this?

            Also in this approach as exampled in #2 above, how possible is it to accommodate stratification by 2 factors for example?
            I concur with this. In the stepped-wedge, groups of clusters are being randomized to one of X sequences during which they switch from the control to the intervention at a step.

            Maudi - How would this effect your analysis by including the randomization in the data? When you run what I presume is a mixed effects model, it doesn't take this randomization into account.

            Comment


            • #7
              Originally posted by Madu Abuchi View Post
              Assuming groups of clusters forms a step (e.g. 20 hospitals are randomized into 5 intervention periods or 5 steps, which means that 4 hospitals forms a step or are to be randomized into an intervention period), how would you manipulate this?
              Who said that you have to switch one-at-at-time?
              Code:
              version 16.0
              
              clear *
              
              set seed `=strreverse("1521199")'
              quietly set obs 20
              
              generate str cluster_id = string(_n, "%02.0f")
              
              *
              * Begin here
              *
              isid cluster_id, sort
              generate double randu = runiform()
              isid randu, sort
              generate int trt_seq = ceil(_n / 5)
              
              list cluster_id trt_seq, noobs sepby(trt_seq) abbreviate(20)
              
              exit
              Also in this approach as exampled in #2 above, how possible is it to accommodate stratification by 2 factors for example?
              The method is to randomize within levels of each combination of stratification variables.

              But keep in mind that if you don't have equal counts within the two sets of factors together, you won't have balanced randomization.

              You have only 20 clusters. It's chancy that you're going to be able to stratify evenly on even one unassigned factor, let alone two.

              Comment


              • #8
                capture program drop swcrt
                program define swcrt, rclass
                version 15.1
                preserve
                clear

                *Missing code*

                args num_clus ICC_lvl3 ICC_lvl2 clussize intercept timecoeff intrvcoeff sigma_u3 sigma_u2 sigma_error
                assert `num_clus' > 0 & `ICC_lvl3' > 0 & `ICC_lvl2' > 0 & `clussize' > 0 & `intercept' > 0 & `timecoeff' > 0 & `intrvcoeff' > 0 & `sigma_u3' > 0 & `sigma_u2' > 0 & `sigma_error' > 0
                /*Generate simulated multi—level data*/
                qui
                set seed 12345
                clear
                set obs `num_clus'
                qui gen cluster = _n
                //Generate cluster-level errors //
                qui gen u_3 = rnormal(0,`sigma_u3')
                expand `clussize'
                bysort cluster: gen individual = _n
                //Generate patient-level errors //
                qui gen u_2 = rnormal(0,`sigma_u2')
                expand 6
                //Set up time//
                bysort cluster individual: gen time = _n-1
                //Set up intervention variable//
                gen intrv = (time>=cluster)
                //Generate residual errors
                qui gen error = rnormal(0,`sigma_error')

                I have attached parts of the above program that I have written. How would the randomization be incorporated into the program while also accounting for individuals in clusters and time?
                Last edited by CEdward; 21 Oct 2019, 18:04.

                Comment


                • #9
                  Originally posted by Jack Chau View Post
                  How would the randomization be incorporated into the program while also accounting for individuals in clusters and time?
                  Code:
                  qui gen cluster = _n
                  Right there. Just after that line.

                  Comment


                  • #10
                    I tried that previously, but what happens is that all of the clusters in the dataset end up being randomized to the same sequence.

                    set seed 12345
                    clear
                    set obs `num_clus'
                    qui gen cluster = _n
                    isid cluster, sort
                    generate double randu = runiform()
                    isid randu, sort
                    generate int trt_seq = ceil(_n /`num_clus')

                    Comment


                    • #11
                      Originally posted by Jack Chau View Post
                      all of the clusters in the dataset end up being randomized to the same sequence.
                      . . .
                      Code:
                      generate int trt_seq = ceil(_n /`num_clus')
                      Well, yeah—the denominator is supposed to be the number of randomization groups, not the number of clusters.

                      Look more closely at my code.

                      Comment


                      • #12
                        Originally posted by Joseph Coveney View Post
                        Well, yeah—the denominator is supposed to be the number of randomization groups, not the number of clusters.

                        Look more closely at my code.
                        Yes, but what about the case where the number of steps/randomization groups equals the number of clusters...that's what I plugged in and all of the clusters were randomized to the same group.

                        Comment


                        • #13
                          Originally posted by Jack Chau View Post
                          but what about the case where the number of steps/randomization groups equals the number of clusters
                          See this code.

                          By the way, what was this
                          Originally posted by Jack Chau View Post
                          I concur with this. In the stepped-wedge, groups of clusters are being randomized to one of X sequences
                          all about?

                          Comment


                          • #14

                            Hi Joseph - So when I run the above code for n = 6 clusters and n = 3 steps,
                            Code:
                            version 16.0  
                            clear *  
                            set seed `=strreverse("1521199")'
                            quietly set obs 6  generate str cluster_id = string(_n, "%02.0f")  
                            * * Begin here * isid cluster_id, sort
                            generate double randu = runiform() isid randu,
                            sort generate int trt_seq = ceil(_n / 3)
                            exit
                            I get the following data:

                            Code:
                            * Example generated by -dataex-. To install: ssc install dataex
                            clear
                            input str2 cluster_id double randu int trt_seq
                            "06" .05315049509335801 1
                            "03"  .3247938388055295 1
                            "04"  .3482941174172366 1
                            "01"  .3802000117365204 2
                            "05"  .6646930943385815 2
                            "02"  .7216011150100311 2
                            end
                            Ideally, there should be 3 steps with an equal number of clusters randomized to each step (e.g. 3 clusters = 1 cluster per step, 6 clusters = 2 per step, etc.). How can I adjust the code to do that?
                            Last edited by CEdward; 19 Nov 2019, 21:41.

                            Comment


                            • #15
                              Sorry, that's number of clusters per randomization group.

                              So, ceiling of {cluster (sequence) number divided by number of clusters per randomization group} gives randomization group (sequence) number.

                              .ÿ
                              .ÿsetÿseedÿ`=strreverse("1521199")'

                              .ÿ
                              .ÿquietlyÿsetÿobsÿ6ÿÿ

                              .ÿgenerateÿstrÿcluster_idÿ=ÿstring(_n,ÿ"%02.0f")ÿÿ

                              .ÿ
                              .ÿgenerateÿdoubleÿranduÿ=ÿruniform()ÿ

                              .ÿsortÿrandu

                              .ÿgenerateÿintÿtrt_seqÿ=ÿceil(_nÿ/ÿ2)

                              .ÿ
                              .ÿlistÿcluster_idÿtrt_seq,ÿnoobsÿsepby(trt_seq)ÿabbreviate(20)

                              ÿÿ+----------------------+
                              ÿÿ|ÿcluster_idÿÿÿtrt_seqÿ|
                              ÿÿ|----------------------|
                              ÿÿ|ÿÿÿÿÿÿÿÿÿ06ÿÿÿÿÿÿÿÿÿ1ÿ|
                              ÿÿ|ÿÿÿÿÿÿÿÿÿ03ÿÿÿÿÿÿÿÿÿ1ÿ|
                              ÿÿ|----------------------|
                              ÿÿ|ÿÿÿÿÿÿÿÿÿ04ÿÿÿÿÿÿÿÿÿ2ÿ|
                              ÿÿ|ÿÿÿÿÿÿÿÿÿ01ÿÿÿÿÿÿÿÿÿ2ÿ|
                              ÿÿ|----------------------|
                              ÿÿ|ÿÿÿÿÿÿÿÿÿ05ÿÿÿÿÿÿÿÿÿ3ÿ|
                              ÿÿ|ÿÿÿÿÿÿÿÿÿ02ÿÿÿÿÿÿÿÿÿ3ÿ|
                              ÿÿ+----------------------+

                              .ÿ
                              .ÿexit

                              endÿofÿdo-file


                              .

                              Comment

                              Working...
                              X