-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathLifeCycleModel29_SemiExoStateFn.m
126 lines (119 loc) · 3.32 KB
/
LifeCycleModel29_SemiExoStateFn.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
function prob=LifeCycleModel29_SemiExoStateFn(n1,n2,n1prime,n2prime,f,probofbirth,probofchild,probofadult)
prob=-1; % Just a placeholder (one that will cause errors if not overwritten)
probn1=-1;
probn2=Inf;
% First, the probabilities for n2prime, which depend on n1 and n2 but not on f
% Call these probn2
if n1==0
if n2==0
if n2prime==0
probn2=1;
elseif n2prime==1
probn2=0;
elseif n2prime==2
probn2=0;
elseif n2prime==3
probn2=0;
end
elseif n2==1
if n2prime==0
probn2=probofadult;
elseif n2prime==1
probn2=1-probofadult;
elseif n2prime==2
probn2=0;
elseif n2prime==3
probn2=0;
end
elseif n2==2
if n2prime==0
probn2=0;
elseif n2prime==1
probn2=probofadult;
elseif n2prime==2
probn2=1-probofadult;
elseif n2prime==3
probn2=0;
end
elseif n2==3
if n2prime==0
probn2=0;
elseif n2prime==1
probn2=0;
elseif n2prime==2
probn2=probofadult;
elseif n2prime==3
probn2=1-probofadult;
end
end
elseif n1==1
if n2==0
if n2prime==0
probn2=1-probofchild;
elseif n2prime==1
probn2=probofchild;
elseif n2prime==2
probn2=0;
elseif n2prime==3
probn2=0;
end
elseif n2==1
if n2prime==0
probn2=probofadult*(1-probofchild);
elseif n2prime==1
probn2=(1-probofadult)*(1-probofchild)+probofchild*probofadult;
elseif n2prime==2
probn2=(1-probofadult)*probofchild;
elseif n2prime==3
probn2=0;
end
elseif n2==2
if n2prime==0
probn2=0;
elseif n2prime==1
probn2=probofadult*(1-probofchild);
elseif n2prime==2
probn2=(1-probofadult)*(1-probofchild)+probofchild*probofadult;
elseif n2prime==3
probn2=(1-probofadult)*probofchild;
end
elseif n2==3
if n2prime==0
probn2=0;
elseif n2prime==1
probn2=0;
elseif n2prime==2
probn2=probofadult*(1-probofchild);
elseif n2prime==3
probn2=(1-probofadult)*(1-probofchild)+probofchild; % Note: It is just assumed that if n2=3 and n1=1, and the infant becomes a child, then one of the children is forced to become an adult
end
end
end
% Second, the probabilities for n1prime, which depend on n1 and f
% Call these probn1
if n1==0
if f==0
if n1prime==0
probn1=1; % If dont have infant and f=0 then definitely no infant;
elseif n1prime==1
probn1=0;
end
elseif f==1
if n1==0
if n1prime==0
probn1=1-probofbirth;
elseif n1prime==1
probn1=probofbirth;
end
end
end
end
if n1==1 % Note, this is effectively independent of f [Note that if model is annual, then it is not possible to have infants in consecutive years]
if n1prime==0
probn1=probofchild; % If dont have infant and f=0 then definitely no infant;
elseif n1prime==1
probn1=1-probofchild;
end
end
prob=probn1*probn2;
end