Skip to content

Commit

Permalink
min_cap = 0 if no truth supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Clark committed Feb 15, 2024
1 parent 5a1a61e commit 0499ad3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
1 change: 1 addition & 0 deletions R/families.R
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ mvgam_predict = function(Xp,
}

} else if(type == 'latent_N'){
if(missing(min_cap)) min_cap <- 0
min_cap <- as.vector(min_cap)
if(missing(truth)){
out <- extraDistr::rtpois(n = length(lambdas),
Expand Down
45 changes: 24 additions & 21 deletions R/stan_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,30 @@ remove_likelihood = function(model_file){
stan_file, fixed = TRUE)]
stan_file <- stan_file[-grep('matrix[n_series, n_lv] lv_coefs;',
stan_file, fixed = TRUE)]

if(any(grepl('// derived latent states',
stan_file, fixed = TRUE))){
starts <- grep('// derived latent states',
stan_file, fixed = TRUE) + 1
ends <- starts + 4
stan_file <- stan_file[-c(starts:ends)]
stan_file[grep('// derived latent states',
stan_file, fixed = TRUE)] <-
paste0('// derived latent states\n',
"trend = LV * Z';")
} else {
starts <- grep('// derived latent trends',
stan_file, fixed = TRUE) + 1
ends <- starts + 4
stan_file <- stan_file[-c(starts:ends)]
stan_file[grep('// derived latent trends',
stan_file, fixed = TRUE)] <-
paste0('// derived latent trends\n',
"trend = LV * Z';")
}
stan_file[grep('trend[i, s] = dot_product(lv_coefs[s,], LV[i,]);',
stan_file, fixed = TRUE)] <-
'trend[i, s] = dot_product(Z[s,], LV[i,]);'

# if(any(grepl('// derived latent states',
# stan_file, fixed = TRUE))){
# starts <- grep('// derived latent states',
# stan_file, fixed = TRUE) + 1
# ends <- starts + 4
# stan_file <- stan_file[-c(starts:ends)]
# stan_file[grep('// derived latent states',
# stan_file, fixed = TRUE)] <-
# paste0('// derived latent states\n',
# "trend = LV * Z';")
# } else {
# starts <- grep('// derived latent trends',
# stan_file, fixed = TRUE) + 1
# ends <- starts + 4
# stan_file <- stan_file[-c(starts:ends)]
# stan_file[grep('// derived latent trends',
# stan_file, fixed = TRUE)] <-
# paste0('// derived latent trends\n',
# "trend = LV * Z';")
# }

stan_file[grep('// posterior predictions',
stan_file, fixed = TRUE)-1] <-
Expand Down
Binary file modified src/mvgam.dll
Binary file not shown.

0 comments on commit 0499ad3

Please sign in to comment.