Skip to content

deal with zeroes in estimate_truncation #301

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

Merged
merged 4 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion R/estimate_truncation.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ estimate_truncation <- function(obs, max_truncation = 10,
data <- list(
logmean = array(rnorm(1, 0, 1)),
logsd = array(abs(rnorm(1, 0, 1))),
phi = abs(rnorm(1, 0, 1)))
phi = abs(rnorm(1, 0, 1)),
sigma = abs(rnorm(1, 0, 1 ))
)
return(data)
}
Expand Down
4 changes: 3 additions & 1 deletion inst/stan/estimate_truncation.stan
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ parameters {
real logmean[1];
real<lower=0> logsd[1];
real<lower=0> phi;
real<lower=0> sigma;
}
transformed parameters{
matrix[trunc_max[1], obs_sets - 1] trunc_obs;
Expand All @@ -35,11 +36,12 @@ model {
logmean ~ normal(0, 1);
logsd[1] ~ normal(0, 1) T[0,];
phi ~ normal(0, 1) T[0,];
sigma ~ normal(0, 1) T[0,];
// log density of truncated latest data vs that observed
for (i in 1:(obs_sets - 1)) {
int start_t = t - obs_dist[i] - trunc_max[1];
for (j in 1:trunc_max[1]) {
obs[start_t + j, i] ~ neg_binomial_2(trunc_obs[j, i], sqrt_phi);
obs[start_t + j, i] ~ neg_binomial_2(trunc_obs[j, i] + sigma, sqrt_phi);
Copy link
Contributor

@seabbs seabbs Jul 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is initialised to a temporary variable it will be faster vs being done in the likelihood.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems mad but can just add it to trunc_obs

}
}
}
Expand Down