Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trtAssign converts all columns to integer #172

Closed
hebaalhosainyTU opened this issue Sep 28, 2022 · 7 comments
Closed

trtAssign converts all columns to integer #172

hebaalhosainyTU opened this issue Sep 28, 2022 · 7 comments
Labels

Comments

@hebaalhosainyTU
Copy link

image

@hebaalhosainyTU
Copy link
Author

After applying the trtAssign function, the values in randomEffect column changed and not anymore normally distributed.

@assignUser
Copy link
Collaborator

Hello @hebaalhosainyTU thanks for the report. Next time please consider using reprex (see below) as it makes it easier to reproduce issues.

@kgoldfeld Reprex below is rendered with cran version of simstudy and indeed looks problematic. I haven't had time to look deeoer into it though.

library(simstudy)
ydef <- defData(varname = "randomEffect", dist = "normal", formula = 0, variance = sqrt(3))

indData <- genData(24, ydef)
head(indData)
#>    id randomEffect
#> 1:  1    2.9851502
#> 2:  2    0.9825252
#> 3:  3   -0.3632496
#> 4:  4   -0.3291816
#> 5:  5    0.4210097
#> 6:  6    1.5862488
indData <- trtAssign(indData, nTrt = 2, balanced = TRUE, grpName = "T")
head(indData)
#>    id randomEffect T
#> 1:  1            2 1
#> 2:  2            0 1
#> 3:  3            0 1
#> 4:  4            0 1
#> 5:  5            0 1
#> 6:  6            1 0

Created on 2022-09-28 with reprex v2.0.2

@assignUser
Copy link
Collaborator

Running the code a few times shows that the randomEffect col is rounded to 0 decimal places...

@assignUser
Copy link
Collaborator

https://github.com/kgoldfeld/simstudy/blob/main/R/group_data.R#L401-L403
Converts ALL columns to integer ⚠️

@assignUser assignUser added the bug label Sep 28, 2022
@assignUser assignUser changed the title trtAssign output is wrong trtAssign converts all columns to integer Sep 28, 2022
@kgoldfeld
Copy link
Owner

Yes - that is indeed a bug. If you want a quick workaround while that is fixed, you can do this:


ydef <- defData(varname = "randomEffect", 
                dist = "normal", formula = 0, variance = sqrt(10))
ydef <- defData(ydef, varname = "T", 
                dist = "trtAssign", formula = "1;1")

genData(6, ydef)
#>    id randomEffect T
#> 1:  1    2.6744327 0
#> 2:  2    0.3138995 1
#> 3:  3   -0.9968553 0
#> 4:  4    0.2780552 1
#> 5:  5   -1.3009989 1
#> 6:  6    1.5663468 0

But great catch, I will certainly fix that bug.

@kgoldfeld
Copy link
Owner

@assignUser It is really strange how those lines of code got in there - must have been added to facilitate testing. And yet, testing did not pick that up. It is particularly odd since the output from trtAssign (really trtObserve) is already integer. Not sure why it would have seemed like a good idea to convert even the treament variable to integer. I will remove the offending code.

@kgoldfeld
Copy link
Owner

@hebaalhosainyTU This has been fixed in the current development version. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants