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

Design not reproducible despite setting seed #55

Closed
LucFrancisENX opened this issue Dec 6, 2024 · 4 comments
Closed

Design not reproducible despite setting seed #55

LucFrancisENX opened this issue Dec 6, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@LucFrancisENX
Copy link

Thanks for the package. Despite setting seed, I am getting different results every time I run design.
Many thanks for your help!

@llrs
Copy link
Owner

llrs commented Dec 6, 2024

Hi thanks for using the package. Could you share some code showing this?
This would help me understand where the problem come from and to check if I have properly fixed it or not.

@llrs llrs added the bug Something isn't working label Dec 6, 2024
@LucFrancisENX
Copy link
Author

LucFrancisENX commented Dec 6, 2024

Hi IIrs thanks for your quick response.

Here is some example code

# Set seed 
set.seed(123)
## mock dataframe
df <- data.frame(
  Gender = sample(c("Male", "Female"), 50, replace = TRUE),
  Age = sample(18:60, 50, replace = TRUE),
  Column1 = sample(c(sample(1:100, 40, replace = TRUE), rep(NA, 10)), 50),
  Column2 = sample(c(runif(40, 0, 50), rep(NA, 10)), 50),
  Column3 = sample(c(sample(200:300, 40, replace = TRUE), rep(NA, 10)), 50),
  Column4 = sample(c(rnorm(40, mean = 50, sd = 10), rep(NA, 10)), 50),
  row.names = paste0("ID", 1:50)
)

index_1 <- experDesign::design(df, 13, iterations = 10000)
index_2 <- experDesign::design(df, 13, iterations = 10000)

setequal(index_1, index_2)

#[1] FALSE

@llrs
Copy link
Owner

llrs commented Dec 6, 2024

Of course, the seed must be set before any call that uses randomization.
Check this:

## mock dataframe
df <- data.frame(
    Gender = sample(c("Male", "Female"), 50, replace = TRUE),
    Age = sample(18:60, 50, replace = TRUE),
    Column1 = sample(c(sample(1:100, 40, replace = TRUE), rep(NA, 10)), 50),
    Column2 = sample(c(runif(40, 0, 50), rep(NA, 10)), 50),
    Column3 = sample(c(sample(200:300, 40, replace = TRUE), rep(NA, 10)), 50),
    Column4 = sample(c(rnorm(40, mean = 50, sd = 10), rep(NA, 10)), 50),
    row.names = paste0("ID", 1:50)
)
set.seed(123)
index_1 <- experDesign::design(df, 13, iterations = 10)
set.seed(123)
index_2 <- experDesign::design(df, 13, iterations = 10)

setequal(index_1, index_2)

Note, I reduced the randomization as we don't really need iterations that long

@LucFrancisENX
Copy link
Author

I see, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants