Skip to content

Commit 54d06dd

Browse files
author
Nicholas Clark
committed
nmixture X ordering issues
1 parent 678d003 commit 54d06dd

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

R/add_nmixture.R

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ add_nmixture = function(model_file,
1010
orig_trend_model <- orig_trend_model$trend_model
1111
}
1212

13+
model_data$ytimes_array <- as.vector(model_data$ytimes)
14+
1315
#### Perform necessary checks on 'cap' (positive integers, no missing values) ####
1416
if(!(exists('cap', where = data_train))) {
1517
stop('Max abundances must be supplied as a variable named "cap" for N-mixture models',
@@ -224,7 +226,8 @@ add_nmixture = function(model_file,
224226
# Update the data block
225227
model_file[grep('int<lower=0> n_nonmissing; // number of nonmissing observations', model_file, fixed = TRUE)] <-
226228
paste0("int<lower=0> n_nonmissing; // number of nonmissing observations\n",
227-
"int<lower=0> cap[total_obs]; // upper limits of latent abundances\n")
229+
"int<lower=0> cap[total_obs]; // upper limits of latent abundances\n",
230+
'array[total_obs] int ytimes_array; // sorted ytimes\n')
228231
model_file <- readLines(textConnection(model_file), n = -1)
229232

230233
# Update the transformed parameters block
@@ -235,7 +238,7 @@ add_nmixture = function(model_file,
235238

236239
model_file[grep('// latent process linear predictors',
237240
model_file, fixed = TRUE)] <- paste0('// detection probability\n',
238-
'p = X * b;\n\n',
241+
'p = X[ytimes_array,] * b;\n\n',
239242
'// latent process linear predictors')
240243
model_file <- readLines(textConnection(model_file), n = -1)
241244

src/mvgam.dll

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)