-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNonAdherenceBubble.m
70 lines (54 loc) · 1.94 KB
/
NonAdherenceBubble.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function B = NonAdherenceBubble(H, TypeorSize, Position, d)
%This function forms an adjacency matrix for Bubble connections. The
%bubbles are formed from households that either are of size 1, or contain a
%child of <10 years of age.
%Input:
% - H is the adjacency matrix for Household connections.
% - TypeorSize is a vector that contains either the type of house (e.g if
% it contains children or not) or the size of each house.
% - position is a vector that stores the position in the population of
% the first member of the household.
% d is the proportion of houses that fill the condition that we want to
% form into a bubble.
%Output
% - B is the adjacency matrix for bubble connections.
%Authors: Trystan Leng and Connor White
%Last update 12/06/2020.
%Find all houses that satisfy the type or size
temp = find(TypeorSize == 1);
%randomly choose the households that will form bubbles
r = randperm(length(temp), round(length(temp)*d));
%initialise Bubble adjacency matrix
B = sparse(zeros(length(H)));
%L is number of households
L = length(TypeorSize);
%LH is size of population
LH = length(H);
for i = 1:(length(r)/2)
j = 2*(i-1)+1;
%to deal with an odd number of entries
if j+1 > length(r)
break;
else
j2 = j+1;
end
%choose households to join up into a bubble
k = temp(r(j));
k2 = temp(r(j2));
%Vector of individuals from first household entering bubble
if k == L
House_to_Connect = Position(k):LH;
else
House_to_Connect = Position(k):(Position(k+1) - 1);
end
%Vector of individuals from second household entering bubble
if k2 == L
Newpartners = Position(k2):LH;
else
Newpartners = Position(k2):(Position(k2+1) - 1);
end
%Join households together into the bubble by setting their
%entries in B to equal 1
B(House_to_Connect, Newpartners) = 1;
B(Newpartners, House_to_Connect) = 1;
end