DeclareDesign / randomizr

randomizr: Easy-to-Use Tools for Common Forms of Random Assignment and Sampling
https://declaredesign.org/r/randomizr
Other
36 stars 9 forks source link

odd behavior for stata format block variables #92

Closed acoppock closed 2 years ago

acoppock commented 3 years ago

blocks <- structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 
                      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
                      1, 1, 1, 1, 1, 1, 1), label = "0 = texas; 1 = arkansas", format.stata = "%8.0g")

declaration <- declare_ra(
  N = 66,
  # bug??
  blocks = blocks,
  block_m = c(15, 18)
)

# thinks it's complete
declaration

blocks2 <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 
             1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
             1, 1, 1, 1, 1, 1, 1)

declaration <- declare_ra(
  N = 66,
  blocks = blocks2,
  block_m = c(15, 18)
)
# gets it right
declaration
nfultz commented 3 years ago

I can take a look at this on Monday.

On Thu, Oct 7, 2021, 4:33 PM Alexander Coppock @.***> wrote:

blocks <- structure(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), label = "0 = texas; 1 = arkansas", format.stata = "%8.0g")

declaration <- declare_ra( N = 66,

bug??

blocks = blocks, block_m = c(15, 18) )

thinks it's complete

declaration

blocks2 <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)

declaration <- declare_ra( N = 66, blocks = blocks2, block_m = c(15, 18) )

gets it right

declaration

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/DeclareDesign/randomizr/issues/92, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADGGTTK7W2AUIUTY4AVYSLUFYU2FANCNFSM5FSMKKIQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

nfultz commented 3 years ago

The bad check is at:

https://github.com/DeclareDesign/randomizr/blob/1b1f713eebc12d7410373ca97bcb91aa42c3739e/R/declare_ra.R#L123

?is.vector tells us:

is.vector returns TRUE if x is a vector of the specified mode having no attributes other than names. It returns FALSE otherwise.

So the extra attributes on blocks cause the check to be false.

Perhaps you want to change from is.vector to !is.null(blocks) ?

graemeblair commented 2 years ago

Thank you @nfultz, this fixed the problem.