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

Bug in generate_data() #28

Closed
4 tasks done
numbersman77 opened this issue Mar 25, 2024 · 0 comments · Fixed by #29
Closed
4 tasks done

Bug in generate_data() #28

numbersman77 opened this issue Mar 25, 2024 · 0 comments · Fixed by #29
Assignees
Labels
bug Something isn't working

Comments

@numbersman77
Copy link
Collaborator

numbersman77 commented Mar 25, 2024

To do:

  • Write a test that can show that there is this bug
  • Fix the problem (using suggested code below)
  • Ensure all tests pass
  • Add a NEWS entry

Tobias Mielke found a (likely) bug in our package:

I might have detected a small bug in your code, which I would like to raise to your awareness. The function currently has:

result$type_of_event <- 1L + stats::rbinom(n = n, size = 2,prob = haz/haz_all)

If you test this code, you’ll see that there will be some confusion within R on the length of your generated data (n), the probability statement (prob) and the size. An alternative to your implementation might be the one below.

typeOfEvent=runif(n,min=0,max=1)
probs=cumsum(haz/haz_all)
result$type_of_event=rep(3,n)
result$type_of_event[which(typeOfEvent<probs[1])]=1
result$type_of_event[which(typeOfEvent>probs[1]&typeOfEvent>probs[2])]=2

I think he has a point here, and Regina Stegherr agress as well. We propose to replace

result$type_of_event <- 1L + stats::rbinom(n = n, size = 2, prob = haz/haz_all)

through

result$type_of_event <- sample(1:3, size = n, prob = haz / haz_all, replace = TRUE).

Simple exploration like

haz <- c(0.2, 0.3, 0.5)
haz_all <- sum(haz)
table(sample(1:3, size = 10^6, prob = haz / haz_all, replace = TRUE))/10^6

seems to show that this does the right thing.

@danielinteractive danielinteractive changed the title Bug in generate_data Bug in generate_data() Mar 25, 2024
@danielinteractive danielinteractive added the bug Something isn't working label Mar 26, 2024
@kuenzelt kuenzelt linked a pull request May 17, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants