@@ -272,7 +272,10 @@ List inf_hist_prop_prior_v2_and_v4(
272
272
int start_index_in_data;
273
273
int end_index_in_data;
274
274
275
- int popn_group_id; // Vector of group IDs for each individual
275
+ // Vector of group IDs for each individual
276
+ int popn_group_id;
277
+ int popn_group_id_loc1; // For timevarying population groups
278
+ int popn_group_id_loc2;
276
279
277
280
IntegerVector new_infection_history (number_possible_exposures); // New proposed infection history
278
281
IntegerVector infection_history (number_possible_exposures); // Old infection history
@@ -423,7 +426,9 @@ List inf_hist_prop_prior_v2_and_v4(
423
426
group = indiv_group_indices[indiv];
424
427
}
425
428
426
- popn_group_id = popn_group_id_vec (indiv);
429
+ if (!timevarying_groups){
430
+ popn_group_id = popn_group_id_loc1 = popn_group_id_loc2 = popn_group_id_vec (indiv);
431
+ }
427
432
old_prob = likelihoods_pre_proposal (indiv);
428
433
429
434
// Time sampling control
@@ -496,9 +501,16 @@ List inf_hist_prop_prior_v2_and_v4(
496
501
lik_changed = true ;
497
502
proposal_swap (indiv) += 1 ;
498
503
if (!prior_on_total){
504
+
505
+ // Might be moving groups, so need to shift group IDs
506
+ if (timevarying_groups){
507
+ popn_group_id_loc1 = popn_group_id_vec ((number_possible_exposures)*(indiv) + loc1);
508
+ popn_group_id_loc2 = popn_group_id_vec ((number_possible_exposures)*(indiv) + loc2);
509
+ }
510
+
499
511
// Number of infections in that group in that time
500
- m_1_old = n_infections (popn_group_id ,loc1);
501
- m_2_old = n_infections (popn_group_id ,loc2);
512
+ m_1_old = n_infections (popn_group_id_loc1 ,loc1);
513
+ m_2_old = n_infections (popn_group_id_loc2 ,loc2);
502
514
503
515
// Swap contents
504
516
new_infection_history (loc1) = new_infection_history (loc2);
@@ -512,12 +524,12 @@ List inf_hist_prop_prior_v2_and_v4(
512
524
m_1_new = m_1_old - loc1_val_old + loc2_val_old;
513
525
m_2_new = m_2_old - loc2_val_old + loc1_val_old;
514
526
515
- prior_1_old = prior_lookup (m_1_old, loc1, popn_group_id );
516
- prior_2_old = prior_lookup (m_2_old, loc2, popn_group_id );
527
+ prior_1_old = prior_lookup (m_1_old, loc1, popn_group_id_loc1 );
528
+ prior_2_old = prior_lookup (m_2_old, loc2, popn_group_id_loc2 );
517
529
prior_old = prior_1_old + prior_2_old;
518
530
519
- prior_1_new = prior_lookup (m_1_new, loc1, popn_group_id );
520
- prior_2_new = prior_lookup (m_2_new, loc2, popn_group_id );
531
+ prior_1_new = prior_lookup (m_1_new, loc1, popn_group_id_loc1 );
532
+ prior_2_new = prior_lookup (m_2_new, loc2, popn_group_id_loc2 );
521
533
prior_new = prior_1_new + prior_2_new;
522
534
523
535
} else {
@@ -541,6 +553,11 @@ List inf_hist_prop_prior_v2_and_v4(
541
553
// Get number of individuals that were alive and/or infected in that year,
542
554
// less the current individual
543
555
// Number of infections in this year, less infection status of this individual in this year
556
+ // Might be moving groups, so need to shift group IDs
557
+ if (timevarying_groups){
558
+ popn_group_id = popn_group_id_vec ((number_possible_exposures)*(indiv) + year);
559
+ }
560
+
544
561
m = n_infections (popn_group_id, year) - old_entry;
545
562
n = n_alive (popn_group_id, year) - 1 ;
546
563
} else {
@@ -761,6 +778,8 @@ List inf_hist_prop_prior_v2_and_v4(
761
778
// Update the entry in the new matrix Z1
762
779
old_prob = new_prob;
763
780
likelihoods_pre_proposal_tmp (indiv) = new_prob;
781
+
782
+
764
783
765
784
// Carry out the swap
766
785
if (swap_step_option){
@@ -771,8 +790,8 @@ List inf_hist_prop_prior_v2_and_v4(
771
790
772
791
// Update number of infections in the two swapped times
773
792
if (!prior_on_total){
774
- n_infections (popn_group_id , loc1) = m_1_new;
775
- n_infections (popn_group_id , loc2) = m_2_new;
793
+ n_infections (popn_group_id_loc1 , loc1) = m_1_new;
794
+ n_infections (popn_group_id_loc2 , loc2) = m_2_new;
776
795
777
796
}
778
797
// Don't need to update group infections if prior_on_total, as infections
0 commit comments