-
Notifications
You must be signed in to change notification settings - Fork 0
/
whpvapm.m
221 lines (185 loc) · 7.06 KB
/
whpvapm.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
% Orca population viability analysis using projection matrix
% Filename: whpvacc.m
% Author: Darren Kavanagh
% Date: 11.12.2008
clear all
load swhlfhs % load life history
startyr = 1992; % start year
endyr = 2001; % end year
range = (startyr:1:endyr); % time range
noyr = (endyr-startyr); % no years
lfhstbl = zeros(noyr,6); % life history table
morttbl = zeros(noyr,6); % mortality table
movouttbl = zeros(noyr,6); % individuals moving in table
movintbl = zeros(noyr,6); % individuals moving out table
% loop through time range
for i=1:(noyr)
curyr = range(i);
% loop through and place in age classes
% and identify where they are in the following year
for j=1:(length(swhlfhs))
birthyr = swhlfhs(j,3);
deathyr = swhlfhs(j,4);
% check to see if individual is alive at current year
if (birthyr <= curyr) && (deathyr > curyr)
whage = curyr-birthyr;
gender = swhlfhs(j,2);
% Calf
if whage == 0
lfhstbl(i,1) = lfhstbl(i,1)+1;
if deathyr == curyr+1
morttbl(i,1) = morttbl(i,1)+1;
else
movouttbl(i,1) = movouttbl(i,1)+1;
movintbl(i,2) = movintbl(i,2)+1;
end
% Juvenile
elseif (whage > 0) && (whage < 11)
lfhstbl(i,2) = lfhstbl(i,2)+1;
if deathyr == curyr+1
morttbl(i,2) = morttbl(i,2)+1;
elseif whage == 10
movouttbl(i,2) = movouttbl(i,2)+1;
if gender ==2
movintbl(i,3) = movintbl(i,3)+1;
else
movintbl(i,5) = movintbl(i,5)+1;
end
end
% Female reproductive
elseif (whage > 10) && (whage < 42) && (gender == 2)
lfhstbl(i,3) = lfhstbl(i,3)+1;
if deathyr == curyr+1
morttbl(i,3) = morttbl(i,3)+1;
elseif whage == 41
movouttbl(i,3) = movouttbl(i,3)+1;
movintbl(i,4) = movintbl(i,4)+1;
end
% Female post reproductive
elseif (whage > 41) && (gender == 2)
lfhstbl(i,4) = lfhstbl(i,4)+1;
if deathyr == curyr+1
morttbl(i,4) = morttbl(i,4)+1;
end
% Male young
elseif (whage > 10) && (whage < 22) && (gender ~= 2)
lfhstbl(i,5) = lfhstbl(i,5)+1;
if deathyr == curyr+1
morttbl(i,5) = morttbl(i,5)+1;
elseif whage == 21
movouttbl(i,5) = movouttbl(i,5)+1;
movintbl(i,6) = movintbl(i,6)+1;
end
% Male old
elseif (whage > 21) && (gender ~= 2)
lfhstbl(i,6) = lfhstbl(i,6)+1;
if deathyr == curyr+1
morttbl(i,6) = morttbl(i,6)+1;
end
end
end
end
end
projectcell = cell(noyr,1);
% create projection matrix from each year
for i=1:(noyr-1)
projmatx = zeros(6, 6);
% Calf to Juvenile
projmatx(2,1) = movintbl(i,2) / lfhstbl(i,1);
% Juvenile to Juvenile
projmatx(2,2) = (lfhstbl(i,2)-movouttbl(i,2)-morttbl(i,2)) / ...
lfhstbl(i,2);
% Junvenile to Reproductive Female
projmatx(3,2) = movintbl(i,3) / lfhstbl(i,2);
% Junvenile to Young Male
projmatx(5,2) = movintbl(i,5) / lfhstbl(i,2);
% Reproductive Female to Calf
projmatx(1,3) = lfhstbl(i+1,1) / lfhstbl(i,3);
% Reproductive Female to Reproductive Female
projmatx(3,3) = (lfhstbl(i,3)-movouttbl(i,3)-morttbl(i,3)) / ...
lfhstbl(i,3);
% Reproductive Female to Post-Reproductive Female
projmatx(4,3) = movintbl(i,4) / lfhstbl(i,3);
% Post-Reproductive Female to Post-Reproductive Female
projmatx(4,4) = (lfhstbl(i,4)-morttbl(i,4)) / lfhstbl(i,4);
% Young Male to Young Male
projmatx(5,5) = (lfhstbl(i,5)-movouttbl(i,5)-morttbl(i,5)) / ...
lfhstbl(i,5);
% Young Male to Old Male
projmatx(6,5) = movintbl(i,6) / lfhstbl(i,5);
% Old Male to Old Male
projmatx(6,6) = (lfhstbl(i,6)-morttbl(i,6)) / lfhstbl(i,6);
projmatx(isnan(projmatx)) = 0;
projectcell(i)= {projmatx};
end
% Population trajectory
% Multiple matrices approach
% --------------------------
tfutpop = zeros(50,100);
for i=1:100
futpop = zeros(50,6);
futpop(1,:) = lfhstbl(end,:);
tfutpop(1,i) = sum(futpop(1,:));
for j=1:49
rcellno = floor(((noyr-1)-1+1)*rand+1);
futpop(j+1,:) = (projectcell{rcellno,1} * (futpop(j,:))')';
tfutpop(j+1,i) = sum(futpop(j+1,:));
end
end
mtfutpop = mean(tfutpop,2);
stdpop = std(tfutpop,[],2)';
se= (stdpop')/ (sqrt(50));
utfutpop = (mtfutpop)+ 1.96 * se;
ltfutpop = (mtfutpop)- 1.96 * se;
figure (1)
plot(1:1:50,mtfutpop,1:1:50, utfutpop,1:1:50,ltfutpop )
xlabel('Years')
ylabel('Population Size')
box off
legend('Average','Upper 95% CL', 'Upper 95% CL', 'Location', 'SouthOutside', ...
'Orientation','horizontal');
legend('boxoff')
tstr = {'Multiple matrices approach: ',strcat(num2str(startyr), ' -',num2str(endyr))};
title(tstr)
% Population trajectory
% Variable entries approach
% --------------------------
tfutpop = zeros(50,100);
for i=1:1000
futpop = zeros(50,6);
futpop(1,:) = lfhstbl(end,:);
tfutpop(1,i) = sum(futpop(1,:));
varmatrix = zeros(6,6);
rcellno = floor(((noyr-1)-1+1)*rand+1);
varmatrix(2,1) = projectcell{floor(((noyr-1)-1+1)*rand+1),1}(2,1);
varmatrix(2,2) = projectcell{floor(((noyr-1)-1+1)*rand+1),1}(2,2);
varmatrix(1,3) = projectcell{floor(((noyr-1)-1+1)*rand+1),1}(1,3);
varmatrix(3,2) = projectcell{floor(((noyr-1)-1+1)*rand+1),1}(3,2);
varmatrix(5,2) = projectcell{floor(((noyr-1)-1+1)*rand+1),1}(5,2);
varmatrix(3,3) = projectcell{floor(((noyr-1)-1+1)*rand+1),1}(3,3);
varmatrix(4,3) = projectcell{floor(((noyr-1)-1+1)*rand+1),1}(4,3);
varmatrix(4,4) = projectcell{floor(((noyr-1)-1+1)*rand+1),1}(4,4);
varmatrix(5,5) = projectcell{floor(((noyr-1)-1+1)*rand+1),1}(5,5);
varmatrix(6,5) = projectcell{floor(((noyr-1)-1+1)*rand+1),1}(6,5);
varmatrix(6,6) = projectcell{floor(((noyr-1)-1+1)*rand+1),1}(6,6);
for j=1:49
futpop(j+1,:) = (varmatrix * (futpop(j,:))')';
tfutpop(j+1,i) = sum(futpop(j+1,:));
end
end
mtfutpop = mean(tfutpop,2);
stdpop = std(tfutpop,[],2)';
se= (stdpop')/ (sqrt(50));
utfutpop = (mean(tfutpop,2))+ 1.96 * se;
ltfutpop = (mean(tfutpop,2))- 1.96 * se;
figure (2)
plot(1:1:50,mean(tfutpop,2),1:1:50, utfutpop,1:1:50,ltfutpop )
xlabel('Years')
ylabel('Population Size')
box off
legend('Average','Upper 95% CL', 'Upper 95% CL', 'Location', 'SouthOutside', ...
'Orientation','horizontal');
legend('boxoff')
tstr = {'Variable entries approach: ',strcat(num2str(startyr), ' -',num2str(endyr))};
title(tstr)
axis ([0 50 0 1000])