You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current simulation code essentially performs a rough integration by manually calculating the trapeziums with a user defined spacing between each rectangle. Whilst this works its not that performant and is confusing to explain to end users as they have to define the step size which is something they shouldn't have to worry about. Would be ideal to replace this with using R's numeric integration functions instead. A rough working example of this can be seen below which implements a random sampler for the Weibull distribution:
hazard_fun<-function(t) {
lambda<-1/200gamma<-0.95lambda*gamma*t^(gamma-1)
}
loss_fun<-function(x, u) {
survival_prob<- exp(-integrate(hazard_fun, lower=0, upper=x)$value)
abs(u-survival_prob)
}
rwei<-function(n) {
vapply(
runif(6000),
\(u) optimise(loss_fun, c(0, 10000), u=u)$minimum,
numeric(1)
)
}
## Compare against flexsurv to show that its workingflexsurv::rweibullPH(6000, scale=1/200, shape=0.95) |>
density() |>
plot(col="red")
rwei(6000) |>
density() |>
lines(col="black")
The text was updated successfully, but these errors were encountered:
The current simulation code essentially performs a rough integration by manually calculating the trapeziums with a user defined spacing between each rectangle. Whilst this works its not that performant and is confusing to explain to end users as they have to define the step size which is something they shouldn't have to worry about. Would be ideal to replace this with using R's numeric integration functions instead. A rough working example of this can be seen below which implements a random sampler for the Weibull distribution:
The text was updated successfully, but these errors were encountered: