@@ -206,3 +206,41 @@ test_that("fitting function works for gamma-hurdle model", {
206
206
pars <- rstan :: extract(fit $ fitted_model , " lambda" )
207
207
expect_equal(apply(pars $ lambda , 2 , mean )[1 ], 5.02 , tol = 0.1 )
208
208
})
209
+
210
+
211
+
212
+ test_that(" fitting function works for time varying poisson hurdle model" , {
213
+ set.seed(123 )
214
+
215
+ d <- data.frame (
216
+ " Year" = 2002 : 2014 ,
217
+ " Takes" = c(0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 3 , 0 , 0 , 0 ),
218
+ " expansionRate" = c(24 , 22 , 14 , 32 , 28 , 25 , 30 , 7 , 26 , 21 , 22 , 23 , 27 ),
219
+ " Sets" = c(391 , 340 , 330 , 660 , 470 , 500 , 330 , 287 , 756 , 673 , 532 , 351 , 486 )
220
+ )
221
+ fit <- fit_bycatch(Takes ~ 1 ,
222
+ data = d , time = " Year" ,
223
+ effort = " Sets" ,
224
+ family = " poisson" ,
225
+ expansion_rate = " expansionRate" ,
226
+ time_varying = FALSE
227
+ )
228
+ expanded <- get_expanded(fit )
229
+ expect_equal(dim(expanded )[1 ], 1500 )
230
+ expect_equal(dim(expanded )[2 ], 13 )
231
+
232
+ fitted <- get_fitted(fit )
233
+ expect_equal(names(fitted ), c(" time" ," mean" ," low" ," high" ," obs" ))
234
+
235
+ expanded <- get_total(fit )
236
+ expect_equal(dim(expanded )[1 ], 1500 )
237
+ expect_equal(dim(expanded )[2 ], 13 )
238
+
239
+ p <- plot_expanded(fit )
240
+ expect_equal(names(p )[1 : 5 ], c(" data" ," layers" ," scales" ," guides" ," mapping" ))
241
+
242
+ p <- plot_fitted(fit )
243
+ expect_equal(names(p )[1 : 5 ], c(" data" ," layers" ," scales" ," guides" ," mapping" ))
244
+ })
245
+
246
+
0 commit comments