Skip to content

Commit

Permalink
few minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Clark committed Jan 16, 2024
1 parent 4683b40 commit 524c348
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion R/mvgam.R
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ mvgam = function(formula,
# If no smooth terms are included, jagam will fail; so add a fake one and remove
# it from the model and data structures later
data_train$fakery <- rnorm(length(data_train$y))
form_fake <- update.formula(formula, ~ . + s(fakery))
form_fake <- update.formula(formula, ~ . + s(fakery, k = 3))
fakery_names <- names(suppressWarnings(mgcv::gam(form_fake,
data = data_train,
family = family_to_mgcvfam(family),
Expand Down
21 changes: 14 additions & 7 deletions R/plot_mvgam_series.R
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,20 @@ plot_mvgam_series = function(object,
xaxt = 'n',
ylim = range(c(truth), na.rm = TRUE),
xlim = c(0, length(c(truth))))
axis(side = 1,
at = floor(seq(0, max(data_train$time) -
(min(data_train$time)-1),
length.out = 6)),
labels = floor(seq(min(data_train$time),
max(data_train$time),
length.out = 6)))
if(max(data_train$time < 6)){
axis(side = 1,
at = 0:(max(data_train$time) - 1),
labels = 1:max(data_train$time))
} else {
axis(side = 1,
at = floor(seq(0, max(data_train$time) -
(min(data_train$time)-1),
length.out = 6)),
labels = floor(seq(min(data_train$time),
max(data_train$time),
length.out = 6)))
}

title('Time series', line = 0)
title(ylab = ylab, line = 1.5)
title(xlab = "Time", line = 1.5)
Expand Down
11 changes: 9 additions & 2 deletions R/stan_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -2393,12 +2393,19 @@ if(trend_model != 'VAR1'){
"matrix[n_series, n_lv] Z; // matrix mapping series to latent trends")
model_file <- readLines(textConnection(model_file), n = -1)

# Z <- matrix(0, NCOL(ytimes), n_lv)
# for(i in 1:NROW(trend_map)){
# Z[as.numeric(data_train$series)[trend_map$series[i]],
# trend_map$trend[i]] <- 1
# }

Z <- matrix(0, NCOL(ytimes), n_lv)
for(i in 1:NROW(trend_map)){
Z[as.numeric(data_train$series)[trend_map$series[i]],
trend_map$trend[i]] <- 1
rowid <- which(levels(data_train$series) == trend_map$series[i])
Z[rowid, trend_map$trend[i]] <- 1
}


model_data$Z <- Z
return(list(model_file = model_file,
model_data = model_data))
Expand Down
Binary file modified src/mvgam.dll
Binary file not shown.

0 comments on commit 524c348

Please sign in to comment.