Skip to content

Commit

Permalink
complete first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
seabbs committed Sep 4, 2024
1 parent c5251d7 commit 47f6fdc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Suggests:
rmarkdown,
spelling,
testthat (>= 3.1.9),
tidybayes,
usethis
Additional_repositories:
https://stan-dev.r-universe.dev
Expand Down
3 changes: 3 additions & 0 deletions inst/stan/primary_censored_dist.stan
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ real primary_censored_integrand(real x, real xc, array[] real theta,

// Compute adjusted delay
real d_adj = d - x;
if (d_adj <= 0) {
return 0;
}

// Compute log probabilities
real log_cdf = dist_lcdf(d_adj | params, dist_id);
Expand Down
23 changes: 12 additions & 11 deletions vignettes/fitting-dists-with-stan.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Alongside the `primarycensoreddist` package we will use the `cmdstanr` package f
```{r setup, message = FALSE}
library(primarycensoreddist)
library(cmdstanr)
library(tidybayes)
library(ggplot2)
```

Expand Down Expand Up @@ -155,7 +154,7 @@ writeLines(
}
model {
// Priors
mu ~ normal(1, 2);
mu ~ normal(1, 1);
sigma ~ normal(0.5, 1);
// Likelihood
Expand Down Expand Up @@ -219,8 +218,8 @@ writeLines(
}
model {
// Priors
mu ~ normal(1, 2);
sigma ~ normal(0.5, 1);
mu ~ normal(1, 1);
sigma ~ normal(0.5, 0.5);
// Likelihood
for (i in 1:N) {
Expand Down Expand Up @@ -259,14 +258,16 @@ primarycensoreddist_fit <- primarycensoreddist_model$sample(
),
chains = 4,
parallel_chains = 4,
init = list(
list(mu = 1, sigma = 0.5),
list(mu = 1, sigma = 0.5),
list(mu = 1, sigma = 0.5),
list(mu = 1, sigma = 0.5)
)
init = list( # we use this to resolve initialisation issues
list(mu = 1.5, sigma = 0.6),
list(mu = 1.5, sigma = 0.4),
list(mu = 1.5, sigma = 0.3),
list(mu = 1.5, sigma = 0.55)
),
refresh = 0,
show_messages = FALSE
)
primarycensoreddist_fit
```

We see that the model has converged and the diagnostics look good. We also see that the posterior means are much closer to the true parameters.
We see that the model has converged and the diagnostics look good. We also see that the posterior means are very near the true parameters and the 90% credible intervals include the true parameters.

0 comments on commit 47f6fdc

Please sign in to comment.