@@ -155,6 +155,91 @@ test_that("series levels must match unique entries in series", {
155
155
run_model = FALSE ))
156
156
})
157
157
158
+ test_that(" share_obs_params working" , {
159
+ # Standard beta
160
+ mod <- mvgam(y ~ s(season , by = series ),
161
+ trend_model = RW(cor = TRUE ),
162
+ family = betar(),
163
+ data = beta_data $ data_train ,
164
+ share_obs_params = TRUE ,
165
+ run_model = FALSE )
166
+ expect_true(inherits(mod , ' mvgam_prefit' ))
167
+ expect_true(any(grepl(' real<lower=0>phi;' ,
168
+ gsub(' ' , ' ' , mod $ model_file ), fixed = TRUE )))
169
+ expect_true(any(grepl(' phi_vec[1:n,s]=rep_vector(phi,n);' ,
170
+ gsub(' ' , ' ' , mod $ model_file ), fixed = TRUE )))
171
+
172
+ # State-space beta
173
+ mod <- mvgam(y ~ - 1 ,
174
+ trend_formula = ~ s(season , by = trend ),
175
+ trend_model = RW(cor = TRUE ),
176
+ family = betar(),
177
+ data = beta_data $ data_train ,
178
+ share_obs_params = TRUE ,
179
+ run_model = FALSE )
180
+ expect_true(inherits(mod , ' mvgam_prefit' ))
181
+ expect_true(any(grepl(' real<lower=0>phi;' ,
182
+ gsub(' ' , ' ' , mod $ model_file ), fixed = TRUE )))
183
+ expect_true(any(grepl(' phi_vec[1:n,s]=rep_vector(phi,n);' ,
184
+ gsub(' ' , ' ' , mod $ model_file ), fixed = TRUE )))
185
+
186
+ # Standard gaussian
187
+ mod <- mvgam(y ~ s(season , by = series ),
188
+ trend_model = RW(cor = TRUE ),
189
+ family = gaussian(),
190
+ data = gaus_data $ data_train ,
191
+ share_obs_params = TRUE ,
192
+ run_model = FALSE )
193
+ expect_true(inherits(mod , ' mvgam_prefit' ))
194
+ expect_true(any(grepl(' real<lower=0>sigma_obs;' ,
195
+ gsub(' ' , ' ' , mod $ model_file ), fixed = TRUE )))
196
+ expect_true(any(grepl(' sigma_obs_vec[1:n,s]=rep_vector(sigma_obs,n);' ,
197
+ gsub(' ' , ' ' , mod $ model_file ), fixed = TRUE )))
198
+
199
+ # State-space gaussian
200
+ mod <- mvgam(y ~ - 1 ,
201
+ trend_formula = ~ s(season , by = trend ),
202
+ trend_model = RW(cor = TRUE ),
203
+ family = gaussian(),
204
+ data = gaus_data $ data_train ,
205
+ share_obs_params = TRUE ,
206
+ run_model = FALSE )
207
+ expect_true(inherits(mod , ' mvgam_prefit' ))
208
+ expect_true(any(grepl(' real<lower=0>sigma_obs;' ,
209
+ gsub(' ' , ' ' , mod $ model_file ), fixed = TRUE )))
210
+ expect_true(any(grepl(' sigma_obs_vec[1:n,s]=rep_vector(sigma_obs,n);' ,
211
+ gsub(' ' , ' ' , mod $ model_file ), fixed = TRUE )))
212
+
213
+
214
+ # Standard Gamma
215
+ simdat <- sim_mvgam(family = Gamma())
216
+ mod <- mvgam(y ~ s(season , by = series ),
217
+ trend_model = RW(cor = TRUE ),
218
+ family = Gamma(),
219
+ data = simdat $ data_train ,
220
+ share_obs_params = TRUE ,
221
+ run_model = FALSE )
222
+ expect_true(inherits(mod , ' mvgam_prefit' ))
223
+ expect_true(any(grepl(' real<lower=0>shape;' ,
224
+ gsub(' ' , ' ' , mod $ model_file ), fixed = TRUE )))
225
+ expect_true(any(grepl(' shape_vec[1:n,s]=rep_vector(shape,n);' ,
226
+ gsub(' ' , ' ' , mod $ model_file ), fixed = TRUE )))
227
+
228
+ # State-space Gamma
229
+ mod <- mvgam(y ~ - 1 ,
230
+ trend_formula = ~ s(season , by = trend ),
231
+ trend_model = RW(cor = TRUE ),
232
+ family = Gamma(),
233
+ data = simdat $ data_train ,
234
+ share_obs_params = TRUE ,
235
+ run_model = FALSE )
236
+ expect_true(inherits(mod , ' mvgam_prefit' ))
237
+ expect_true(any(grepl(' real<lower=0>shape;' ,
238
+ gsub(' ' , ' ' , mod $ model_file ), fixed = TRUE )))
239
+ expect_true(any(grepl(' shape_vec[1:n,s]=rep_vector(shape,n);' ,
240
+ gsub(' ' , ' ' , mod $ model_file ), fixed = TRUE )))
241
+ })
242
+
158
243
test_that(" trend_map is behaving propoerly" , {
159
244
sim <- sim_mvgam(n_series = 3 )
160
245
mod_data <- sim $ data_train
0 commit comments