Skip to content

Commit fd40561

Browse files
author
Nicholas Clark
committed
move M out of transformed data
1 parent 73ab608 commit fd40561

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

R/jsdgam.R

+10-14
Original file line numberDiff line numberDiff line change
@@ -277,20 +277,12 @@ jsdgam = function(formula,
277277
model_file <- model_file[-grep("matrix[n_series, n_lv] Z; // matrix mapping series to latent states",
278278
model_file, fixed = TRUE)]
279279

280-
# Update transformed data
281-
if(any(grepl('transformed data {', model_file, fixed = TRUE))){
282-
model_file[grep('transformed data {', model_file, fixed = TRUE)] <-
283-
paste0('transformed data {\n',
284-
'// Ensures identifiability of the model - no rotation of factors\n',
285-
'int<lower=1> M;\n',
286-
'M = n_lv * (n_series - n_lv) + n_lv * (n_lv - 1) / 2 + n_lv;')
287-
} else {
288-
model_file[grep('parameters {', model_file, fixed = TRUE)[1]] <-
289-
paste0('// Ensures identifiability of the model - no rotation of factors\n',
290-
'int<lower=1> M;\n',
291-
'M = n_lv * (n_series - n_lv) + n_lv * (n_lv - 1) / 2 + n_lv;',
292-
'}\nparameters {')
293-
}
280+
# Add M to data block
281+
model_file[grep('int<lower=0> n_lv; // number of dynamic factors',
282+
model_file, fixed = TRUE)] <- paste0(
283+
'int<lower=0> n_lv; // number of dynamic factors\n',
284+
'int<lower=0> M; // number of nonzero factor loadings'
285+
)
294286
model_file <- readLines(textConnection(model_file), n = -1)
295287

296288
# Update parameters
@@ -374,6 +366,10 @@ jsdgam = function(formula,
374366
model_data <- mod$model_data
375367
model_data$Z <- NULL
376368

369+
# Add M to model_data
370+
n_series <- NCOL(model_data$ytimes)
371+
model_data$M <- n_lv * (n_series - n_lv) + n_lv * (n_lv - 1) / 2 + n_lv
372+
377373
#### Autoformat the Stan code ####
378374
if(requireNamespace('cmdstanr', quietly = TRUE) & backend == 'cmdstanr'){
379375
if(requireNamespace('cmdstanr') &

src/RcppExports.o

-1.28 MB
Binary file not shown.

src/trend_funs.o

-1.54 MB
Binary file not shown.

0 commit comments

Comments
 (0)