Skip to content

Commit

Permalink
Just running into some C++ errors..
Browse files Browse the repository at this point in the history
  • Loading branch information
athowes committed Nov 15, 2024
1 parent aa24b86 commit d6a7d19
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
31 changes: 13 additions & 18 deletions inst/marginal_model-scratch.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,12 @@ primarycensored_family <- brms::custom_family(
links = c(lognormal$link, lognormal$link_sigma),
type = "int",
loop = TRUE,
vars = c("vreal1[n]", "pwindow[n]")
vars = c("vreal1[n]")
)

data <- cohort_obs |>
select(d = delay, n = n) |>
mutate(
pwindow = 1,
q = pmax(d - pwindow, 0)
)
mutate(pwindow = 1)

pcd_stanvars_functions <- brms::stanvar(
block = "functions",
Expand All @@ -72,30 +69,28 @@ pcd_stanvars_functions <- brms::stanvar(

stanvars_functions <- brms::stanvar(
block = "functions",
scode = .stan_chunk("cohort_model/functions.stan")
scode = .stan_chunk(file.path("marginal_model", "functions.stan"))
)

pwindow <- data$pwindow
# pwindow <- data$pwindow
#
# stanvars_data <- brms::stanvar(
# x = pwindow,
# block = "data",
# scode = .stan_chunk("marginal_model/data.stan")
# )

stanvars_data <- brms::stanvar(
x = pwindow,
block = "data",
scode = .stan_chunk("cohort_model/data.stan")
)

stanvars_all <- pcd_stanvars_functions + stanvars_functions + stanvars_data
stanvars_all <- pcd_stanvars_functions + stanvars_functions

stancode <- brms::make_stancode(
formula = d | weights(n) + vreal(q) ~ 1,
formula = d | weights(n) + vreal(pwindow) ~ 1,
family = primarycensored_family,
data = data,
stanvars = stanvars_all,
)

model <- rstan::stan_model(model_code = stancode)

fit_pcd <- brms::brm(
formula = d | weights(n) + vreal(q) ~ 1,
formula = d | weights(n) + vreal(pwindow) ~ 1,
family = primarycensored_family,
data = data,
stanvars = stanvars_all,
Expand Down
1 change: 1 addition & 0 deletions inst/stan/marginal_model/data.stan
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
vector[N] pwindow;
pwindow = vreal2;
2 changes: 1 addition & 1 deletion inst/stan/marginal_model/functions.stan
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
real primarycensored_wrapper_lpmf(data int d, real mu, real sigma, real q, data real pwindow) {
real primarycensored_wrapper_lpmf(data int d, real mu, real sigma, data real pwindow) {
int dist_id = 1; // lognormal
array[2] real params = {mu, sigma};
int d_upper = d + 1;
Expand Down
1 change: 0 additions & 1 deletion inst/stan/marginal_model/tdata.stan

This file was deleted.

0 comments on commit d6a7d19

Please sign in to comment.