annotate insect_phenology_model.R @ 36:c2025ecec509 draft

Uploaded
author greg
date Thu, 09 Nov 2017 13:43:08 -0500
parents 21e8dc696db3
children b0126627ade6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
1 #!/usr/bin/env Rscript
f20a67192cfa Uploaded
greg
parents:
diff changeset
2
f20a67192cfa Uploaded
greg
parents:
diff changeset
3 suppressPackageStartupMessages(library("optparse"))
f20a67192cfa Uploaded
greg
parents:
diff changeset
4
f20a67192cfa Uploaded
greg
parents:
diff changeset
5 option_list <- list(
f20a67192cfa Uploaded
greg
parents:
diff changeset
6 make_option(c("-a", "--adult_mort"), action="store", dest="adult_mort", type="integer", help="Adjustment rate for adult mortality"),
f20a67192cfa Uploaded
greg
parents:
diff changeset
7 make_option(c("-b", "--adult_accum"), action="store", dest="adult_accum", type="integer", help="Adjustment of DD accumulation (old nymph->adult)"),
f20a67192cfa Uploaded
greg
parents:
diff changeset
8 make_option(c("-c", "--egg_mort"), action="store", dest="egg_mort", type="integer", help="Adjustment rate for egg mortality"),
f20a67192cfa Uploaded
greg
parents:
diff changeset
9 make_option(c("-e", "--location"), action="store", dest="location", help="Selected location"),
f20a67192cfa Uploaded
greg
parents:
diff changeset
10 make_option(c("-f", "--min_clutch_size"), action="store", dest="min_clutch_size", type="integer", help="Adjustment of minimum clutch size"),
f20a67192cfa Uploaded
greg
parents:
diff changeset
11 make_option(c("-i", "--max_clutch_size"), action="store", dest="max_clutch_size", type="integer", help="Adjustment of maximum clutch size"),
f20a67192cfa Uploaded
greg
parents:
diff changeset
12 make_option(c("-j", "--nymph_mort"), action="store", dest="nymph_mort", type="integer", help="Adjustment rate for nymph mortality"),
f20a67192cfa Uploaded
greg
parents:
diff changeset
13 make_option(c("-k", "--old_nymph_accum"), action="store", dest="old_nymph_accum", type="integer", help="Adjustment of DD accumulation (young nymph->old nymph)"),
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
14 make_option(c("-n", "--num_days"), action="store", dest="num_days", type="integer", help="Total number of days in the temperature dataset"),
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
15 make_option(c("-o", "--output"), action="store", dest="output", help="Output dataset"),
f20a67192cfa Uploaded
greg
parents:
diff changeset
16 make_option(c("-p", "--oviposition"), action="store", dest="oviposition", type="integer", help="Adjustment for oviposition rate"),
f20a67192cfa Uploaded
greg
parents:
diff changeset
17 make_option(c("-q", "--photoperiod"), action="store", dest="photoperiod", type="double", help="Critical photoperiod for diapause induction/termination"),
f20a67192cfa Uploaded
greg
parents:
diff changeset
18 make_option(c("-s", "--replications"), action="store", dest="replications", type="integer", help="Number of replications"),
f20a67192cfa Uploaded
greg
parents:
diff changeset
19 make_option(c("-t", "--se_plot"), action="store", dest="se_plot", help="Plot SE"),
22
cd4d17bf3b9e Uploaded
greg
parents: 13
diff changeset
20 make_option(c("-v", "--input"), action="store", dest="input", help="Temperature data for selected location"),
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
21 make_option(c("-y", "--young_nymph_accum"), action="store", dest="young_nymph_accum", type="integer", help="Adjustment of DD accumulation (egg->young nymph)")
f20a67192cfa Uploaded
greg
parents:
diff changeset
22 )
f20a67192cfa Uploaded
greg
parents:
diff changeset
23
f20a67192cfa Uploaded
greg
parents:
diff changeset
24 parser <- OptionParser(usage="%prog [options] file", option_list=option_list)
f20a67192cfa Uploaded
greg
parents:
diff changeset
25 args <- parse_args(parser, positional_arguments=TRUE)
f20a67192cfa Uploaded
greg
parents:
diff changeset
26 opt <- args$options
f20a67192cfa Uploaded
greg
parents:
diff changeset
27
32
5517d380c337 Uploaded
greg
parents: 31
diff changeset
28 convert_csv_to_rdata=function(temperature_data, data_matrix)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
29 {
31
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
30 # Integer day of the year.
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
31 data_matrix[,1] <- c(1:opt$num_days)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
32 # Minimum
31
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
33 data_matrix[,2] <- temperature_data[c(1:opt$num_days), 5]
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
34 # Maximum
31
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
35 data_matrix[,3] <- temperature_data[c(1:opt$num_days), 6]
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
36 namedat <- "tempdata.Rdat"
31
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
37 save(data_matrix, file=namedat)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
38 namedat
f20a67192cfa Uploaded
greg
parents:
diff changeset
39 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
40
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
41 daylength=function(latitude, num_days)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
42 {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
43 # From Forsythe 1995.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
44 p=0.8333
f20a67192cfa Uploaded
greg
parents:
diff changeset
45 dl <- NULL
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
46 for (i in 1:num_days) {
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
47 theta <- 0.2163108 + 2 * atan(0.9671396 * tan(0.00860 * (i - 186)))
f20a67192cfa Uploaded
greg
parents:
diff changeset
48 phi <- asin(0.39795 * cos(theta))
f20a67192cfa Uploaded
greg
parents:
diff changeset
49 dl[i] <- 24 - 24 / pi * acos((sin(p * pi / 180) + sin(latitude * pi / 180) * sin(phi)) / (cos(latitude * pi / 180) * cos(phi)))
f20a67192cfa Uploaded
greg
parents:
diff changeset
50 }
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
51 # Return a vector of daylength for the number of
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
52 # days specified in the input temperature data.
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
53 dl
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
54 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
55
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
56 hourtemp=function(latitude, date, temperature_file_path, num_days)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
57 {
f20a67192cfa Uploaded
greg
parents:
diff changeset
58 load(temperature_file_path)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
59 # Base development threshold for Brown Marmolated Stink Bug
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
60 # insect phenology model.
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
61 threshold <- 14.17
31
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
62 dnp <- data_matrix[date, 2] # daily minimum
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
63 dxp <- data_matrix[date, 3] # daily maximum
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
64 dmean <- 0.5 * (dnp + dxp)
f20a67192cfa Uploaded
greg
parents:
diff changeset
65 dd <- 0 # initialize degree day accumulation
f20a67192cfa Uploaded
greg
parents:
diff changeset
66
f20a67192cfa Uploaded
greg
parents:
diff changeset
67 if (dxp<threshold) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
68 dd <- 0
f20a67192cfa Uploaded
greg
parents:
diff changeset
69 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
70 else {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
71 # Extract daylength data for the number of
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
72 # days specified in the input temperature data.
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
73 dlprofile <- daylength(latitude, num_days)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
74 # Initialize hourly temperature.
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
75 T <- NULL
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
76 # Initialize degree hour vector.
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
77 dh <- NULL
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
78 # Calculate daylength in given date.
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
79 y <- dlprofile[date]
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
80 # Night length.
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
81 z <- 24 - y
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
82 # Lag coefficient.
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
83 a <- 1.86
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
84 # Night coefficient.
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
85 b <- 2.20
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
86 # Sunrise time.
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
87 risetime <- 12 - y / 2
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
88 # Sunset time.
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
89 settime <- 12 + y / 2
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
90 ts <- (dxp - dnp) * sin(pi * (settime - 5) / (y + 2 * a)) + dnp
f20a67192cfa Uploaded
greg
parents:
diff changeset
91 for (i in 1:24) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
92 if (i > risetime && i<settime) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
93 # Number of hours after Tmin until sunset.
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
94 m <- i - 5
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
95 T[i]=(dxp - dnp) * sin(pi * m / (y + 2 * a)) + dnp
f20a67192cfa Uploaded
greg
parents:
diff changeset
96 if (T[i]<8.4) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
97 dh[i] <- 0
f20a67192cfa Uploaded
greg
parents:
diff changeset
98 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
99 else {
f20a67192cfa Uploaded
greg
parents:
diff changeset
100 dh[i] <- T[i] - 8.4
f20a67192cfa Uploaded
greg
parents:
diff changeset
101 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
102 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
103 else if (i > settime) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
104 n <- i - settime
f20a67192cfa Uploaded
greg
parents:
diff changeset
105 T[i]=dnp + (ts - dnp) * exp( - b * n / z)
f20a67192cfa Uploaded
greg
parents:
diff changeset
106 if (T[i]<8.4) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
107 dh[i] <- 0
f20a67192cfa Uploaded
greg
parents:
diff changeset
108 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
109 else {
f20a67192cfa Uploaded
greg
parents:
diff changeset
110 dh[i] <- T[i] - 8.4
f20a67192cfa Uploaded
greg
parents:
diff changeset
111 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
112 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
113 else {
f20a67192cfa Uploaded
greg
parents:
diff changeset
114 n <- i + 24 - settime
f20a67192cfa Uploaded
greg
parents:
diff changeset
115 T[i]=dnp + (ts - dnp) * exp( - b * n / z)
f20a67192cfa Uploaded
greg
parents:
diff changeset
116 if (T[i]<8.4) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
117 dh[i] <- 0
f20a67192cfa Uploaded
greg
parents:
diff changeset
118 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
119 else {
f20a67192cfa Uploaded
greg
parents:
diff changeset
120 dh[i] <- T[i] - 8.4
f20a67192cfa Uploaded
greg
parents:
diff changeset
121 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
122 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
123 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
124 dd <- sum(dh) / 24
f20a67192cfa Uploaded
greg
parents:
diff changeset
125 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
126 return=c(dmean, dd)
f20a67192cfa Uploaded
greg
parents:
diff changeset
127 return
f20a67192cfa Uploaded
greg
parents:
diff changeset
128 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
129
f20a67192cfa Uploaded
greg
parents:
diff changeset
130 dev.egg = function(temperature)
f20a67192cfa Uploaded
greg
parents:
diff changeset
131 {
f20a67192cfa Uploaded
greg
parents:
diff changeset
132 dev.rate= -0.9843 * temperature + 33.438
f20a67192cfa Uploaded
greg
parents:
diff changeset
133 return = dev.rate
f20a67192cfa Uploaded
greg
parents:
diff changeset
134 return
f20a67192cfa Uploaded
greg
parents:
diff changeset
135 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
136
f20a67192cfa Uploaded
greg
parents:
diff changeset
137 dev.young = function(temperature)
f20a67192cfa Uploaded
greg
parents:
diff changeset
138 {
f20a67192cfa Uploaded
greg
parents:
diff changeset
139 n12 <- -0.3728 * temperature + 14.68
f20a67192cfa Uploaded
greg
parents:
diff changeset
140 n23 <- -0.6119 * temperature + 25.249
f20a67192cfa Uploaded
greg
parents:
diff changeset
141 dev.rate = mean(n12 + n23)
f20a67192cfa Uploaded
greg
parents:
diff changeset
142 return = dev.rate
f20a67192cfa Uploaded
greg
parents:
diff changeset
143 return
f20a67192cfa Uploaded
greg
parents:
diff changeset
144 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
145
f20a67192cfa Uploaded
greg
parents:
diff changeset
146 dev.old = function(temperature)
f20a67192cfa Uploaded
greg
parents:
diff changeset
147 {
f20a67192cfa Uploaded
greg
parents:
diff changeset
148 n34 <- -0.6119 * temperature + 17.602
f20a67192cfa Uploaded
greg
parents:
diff changeset
149 n45 <- -0.4408 * temperature + 19.036
f20a67192cfa Uploaded
greg
parents:
diff changeset
150 dev.rate = mean(n34 + n45)
f20a67192cfa Uploaded
greg
parents:
diff changeset
151 return = dev.rate
f20a67192cfa Uploaded
greg
parents:
diff changeset
152 return
f20a67192cfa Uploaded
greg
parents:
diff changeset
153 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
154
f20a67192cfa Uploaded
greg
parents:
diff changeset
155 dev.emerg = function(temperature)
f20a67192cfa Uploaded
greg
parents:
diff changeset
156 {
f20a67192cfa Uploaded
greg
parents:
diff changeset
157 emerg.rate <- -0.5332 * temperature + 24.147
f20a67192cfa Uploaded
greg
parents:
diff changeset
158 return = emerg.rate
f20a67192cfa Uploaded
greg
parents:
diff changeset
159 return
f20a67192cfa Uploaded
greg
parents:
diff changeset
160 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
161
f20a67192cfa Uploaded
greg
parents:
diff changeset
162 mortality.egg = function(temperature)
f20a67192cfa Uploaded
greg
parents:
diff changeset
163 {
f20a67192cfa Uploaded
greg
parents:
diff changeset
164 if (temperature < 12.7) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
165 mort.prob = 0.8
f20a67192cfa Uploaded
greg
parents:
diff changeset
166 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
167 else {
f20a67192cfa Uploaded
greg
parents:
diff changeset
168 mort.prob = 0.8 - temperature / 40.0
f20a67192cfa Uploaded
greg
parents:
diff changeset
169 if (mort.prob < 0) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
170 mort.prob = 0.01
f20a67192cfa Uploaded
greg
parents:
diff changeset
171 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
172 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
173 return = mort.prob
f20a67192cfa Uploaded
greg
parents:
diff changeset
174 return
f20a67192cfa Uploaded
greg
parents:
diff changeset
175 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
176
f20a67192cfa Uploaded
greg
parents:
diff changeset
177 mortality.nymph = function(temperature)
f20a67192cfa Uploaded
greg
parents:
diff changeset
178 {
f20a67192cfa Uploaded
greg
parents:
diff changeset
179 if (temperature < 12.7) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
180 mort.prob = 0.03
f20a67192cfa Uploaded
greg
parents:
diff changeset
181 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
182 else {
f20a67192cfa Uploaded
greg
parents:
diff changeset
183 mort.prob = temperature * 0.0008 + 0.03
f20a67192cfa Uploaded
greg
parents:
diff changeset
184 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
185 return = mort.prob
f20a67192cfa Uploaded
greg
parents:
diff changeset
186 return
f20a67192cfa Uploaded
greg
parents:
diff changeset
187 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
188
f20a67192cfa Uploaded
greg
parents:
diff changeset
189 mortality.adult = function(temperature)
f20a67192cfa Uploaded
greg
parents:
diff changeset
190 {
f20a67192cfa Uploaded
greg
parents:
diff changeset
191 if (temperature < 12.7) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
192 mort.prob = 0.002
f20a67192cfa Uploaded
greg
parents:
diff changeset
193 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
194 else {
f20a67192cfa Uploaded
greg
parents:
diff changeset
195 mort.prob = temperature * 0.0005 + 0.02
f20a67192cfa Uploaded
greg
parents:
diff changeset
196 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
197 return = mort.prob
f20a67192cfa Uploaded
greg
parents:
diff changeset
198 return
f20a67192cfa Uploaded
greg
parents:
diff changeset
199 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
200
22
cd4d17bf3b9e Uploaded
greg
parents: 13
diff changeset
201 # Read in the input temperature datafile into a Data Frame object.
24
5354a82ed295 Uploaded
greg
parents: 22
diff changeset
202 temperature_data <- read.csv(file=opt$input, header=T, sep=",")
34
17f9578b7391 Uploaded
greg
parents: 33
diff changeset
203 start_date <- temperature_data[c(1:1), 3]
36
c2025ecec509 Uploaded
greg
parents: 35
diff changeset
204 end_date <- temperature_data[c(opt$num_days:1), 3]
31
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
205 raw_data_matrix <- matrix(rep(0, opt$num_days * 6), nrow=opt$num_days)
33
a374a8fab830 Uploaded
greg
parents: 32
diff changeset
206 temperature_file_path <- convert_csv_to_rdata(temperature_data, raw_data_matrix)
22
cd4d17bf3b9e Uploaded
greg
parents: 13
diff changeset
207 latitude <- temperature_data[1, 1]
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
208
28
3ef94dce7454 Uploaded
greg
parents: 27
diff changeset
209 cat("Number of days: ", opt$num_days, "\n")
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
210 cat("Latitude: ", latitude, "\n")
29
4d38c1789ae0 Uploaded
greg
parents: 28
diff changeset
211 cat("Replications: ", opt$replications, "\n")
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
212
27
24949e72f7ec Uploaded
greg
parents: 26
diff changeset
213 # Initialize matrix for results from all replications.
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
214 S0.rep <- S1.rep <- S2.rep <- S3.rep <- S4.rep <- S5.rep <- matrix(rep(0, opt$num_days * opt$replications), ncol = opt$replications)
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
215 newborn.rep <- death.rep <- adult.rep <- pop.rep <- g0.rep <- g1.rep <- g2.rep <- g0a.rep <- g1a.rep <- g2a.rep <- matrix(rep(0, opt$num_days * opt$replications), ncol=opt$replications)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
216
f20a67192cfa Uploaded
greg
parents:
diff changeset
217 # loop through replications
f20a67192cfa Uploaded
greg
parents:
diff changeset
218 for (N.rep in 1:opt$replications) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
219 # During each replication start with 1000 individuals.
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
220 # TODO: user definable as well?
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
221 n <- 1000
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
222 # Generation, Stage, DD, T, Diapause.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
223 vec.ini <- c(0, 3, 0, 0, 0)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
224 # Overwintering, previttelogenic, DD=0, T=0, no-diapause.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
225 vec.mat <- rep(vec.ini, n)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
226 # Complete matrix for the population.
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
227 vec.mat <- base::t(matrix(vec.mat, nrow=5))
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
228 # Complete photoperiod profile in a year, requires daylength function.
22
cd4d17bf3b9e Uploaded
greg
parents: 13
diff changeset
229 ph.p <- daylength(latitude, opt$num_days)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
230
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
231 # Time series of population size.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
232 tot.pop <- NULL
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
233 gen0.pop <- rep(0, opt$num_days)
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
234 gen1.pop <- rep(0, opt$num_days)
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
235 gen2.pop <- rep(0, opt$num_days)
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
236 S0 <- S1 <- S2 <- S3 <- S4 <- S5 <- rep(0, opt$num_days)
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
237 g0.adult <- g1.adult <- g2.adult <- rep(0, opt$num_days)
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
238 N.newborn <- N.death <- N.adult <- rep(0, opt$num_days)
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
239 dd.day <- rep(0, opt$num_days)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
240
22
cd4d17bf3b9e Uploaded
greg
parents: 13
diff changeset
241 # All the days included in the input temperature dataset.
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
242 for (day in 1:opt$num_days) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
243 # Photoperiod in the day.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
244 photoperiod <- ph.p[day]
22
cd4d17bf3b9e Uploaded
greg
parents: 13
diff changeset
245 temp.profile <- hourtemp(latitude, day, temperature_file_path, opt$num_days)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
246 mean.temp <- temp.profile[1]
f20a67192cfa Uploaded
greg
parents:
diff changeset
247 dd.temp <- temp.profile[2]
f20a67192cfa Uploaded
greg
parents:
diff changeset
248 dd.day[day] <- dd.temp
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
249 # Trash bin for death.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
250 death.vec <- NULL
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
251 # Newborn.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
252 birth.vec <- NULL
f20a67192cfa Uploaded
greg
parents:
diff changeset
253
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
254 # All individuals.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
255 for (i in 1:n) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
256 # Find individual record.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
257 vec.ind <- vec.mat[i,]
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
258 # First of all, still alive?
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
259 # Adjustment for late season mortality rate.
22
cd4d17bf3b9e Uploaded
greg
parents: 13
diff changeset
260 if (latitude < 40.0) {
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
261 post.mort <- 1
f20a67192cfa Uploaded
greg
parents:
diff changeset
262 day.kill <- 300
f20a67192cfa Uploaded
greg
parents:
diff changeset
263 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
264 else {
f20a67192cfa Uploaded
greg
parents:
diff changeset
265 post.mort <- 2
f20a67192cfa Uploaded
greg
parents:
diff changeset
266 day.kill <- 250
f20a67192cfa Uploaded
greg
parents:
diff changeset
267 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
268 if (vec.ind[2] == 0) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
269 # Egg.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
270 death.prob = opt$egg_mort * mortality.egg(mean.temp)
f20a67192cfa Uploaded
greg
parents:
diff changeset
271 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
272 else if (vec.ind[2] == 1 | vec.ind[2] == 2) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
273 death.prob = opt$nymph_mort * mortality.nymph(mean.temp)
f20a67192cfa Uploaded
greg
parents:
diff changeset
274 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
275 else if (vec.ind[2] == 3 | vec.ind[2] == 4 | vec.ind[2] == 5) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
276 # For adult.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
277 if (day < day.kill) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
278 death.prob = opt$adult_mort * mortality.adult(mean.temp)
f20a67192cfa Uploaded
greg
parents:
diff changeset
279 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
280 else {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
281 # Increase adult mortality after fall equinox.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
282 death.prob = opt$adult_mort * post.mort * mortality.adult(mean.temp)
f20a67192cfa Uploaded
greg
parents:
diff changeset
283 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
284 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
285 # (or dependent on temperature and life stage?)
f20a67192cfa Uploaded
greg
parents:
diff changeset
286 u.d <- runif(1)
f20a67192cfa Uploaded
greg
parents:
diff changeset
287 if (u.d < death.prob) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
288 death.vec <- c(death.vec, i)
f20a67192cfa Uploaded
greg
parents:
diff changeset
289 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
290 else {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
291 # Aggregrate index of dead bug.
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
292 # Event 1 end of diapause.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
293 if (vec.ind[1] == 0 && vec.ind[2] == 3) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
294 # Overwintering adult (previttelogenic).
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
295 if (photoperiod > opt$photoperiod && vec.ind[3] > 68 && day < 180) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
296 # Add 68C to become fully reproductively matured.
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
297 # Transfer to vittelogenic.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
298 vec.ind <- c(0, 4, 0, 0, 0)
f20a67192cfa Uploaded
greg
parents:
diff changeset
299 vec.mat[i,] <- vec.ind
f20a67192cfa Uploaded
greg
parents:
diff changeset
300 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
301 else {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
302 # Add to dd.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
303 vec.ind[3] <- vec.ind[3] + dd.temp
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
304 # Add 1 day in current stage.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
305 vec.ind[4] <- vec.ind[4] + 1
f20a67192cfa Uploaded
greg
parents:
diff changeset
306 vec.mat[i,] <- vec.ind
f20a67192cfa Uploaded
greg
parents:
diff changeset
307 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
308 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
309 if (vec.ind[1] != 0 && vec.ind[2] == 3) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
310 # Not overwintering adult (previttelogenic).
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
311 current.gen <- vec.ind[1]
f20a67192cfa Uploaded
greg
parents:
diff changeset
312 if (vec.ind[3] > 68) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
313 # Add 68C to become fully reproductively matured.
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
314 # Transfer to vittelogenic.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
315 vec.ind <- c(current.gen, 4, 0, 0, 0)
f20a67192cfa Uploaded
greg
parents:
diff changeset
316 vec.mat[i,] <- vec.ind
f20a67192cfa Uploaded
greg
parents:
diff changeset
317 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
318 else {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
319 # Add to dd.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
320 vec.ind[3] <- vec.ind[3] + dd.temp
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
321 # Add 1 day in current stage.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
322 vec.ind[4] <- vec.ind[4] + 1
f20a67192cfa Uploaded
greg
parents:
diff changeset
323 vec.mat[i,] <- vec.ind
f20a67192cfa Uploaded
greg
parents:
diff changeset
324 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
325 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
326
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
327 # Event 2 oviposition -- where population dynamics comes from.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
328 if (vec.ind[2] == 4 && vec.ind[1] == 0 && mean.temp > 10) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
329 # Vittelogenic stage, overwintering generation.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
330 if (vec.ind[4] == 0) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
331 # Just turned in vittelogenic stage.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
332 n.birth=round(runif(1, 2 + opt$min_clutch_size, 8 + opt$max_clutch_size))
f20a67192cfa Uploaded
greg
parents:
diff changeset
333 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
334 else {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
335 # Daily probability of birth.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
336 p.birth = opt$oviposition * 0.01
f20a67192cfa Uploaded
greg
parents:
diff changeset
337 u1 <- runif(1)
f20a67192cfa Uploaded
greg
parents:
diff changeset
338 if (u1 < p.birth) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
339 n.birth=round(runif(1, 2, 8))
f20a67192cfa Uploaded
greg
parents:
diff changeset
340 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
341 }
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
342 # Add to dd.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
343 vec.ind[3] <- vec.ind[3] + dd.temp
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
344 # Add 1 day in current stage.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
345 vec.ind[4] <- vec.ind[4] + 1
f20a67192cfa Uploaded
greg
parents:
diff changeset
346 vec.mat[i,] <- vec.ind
f20a67192cfa Uploaded
greg
parents:
diff changeset
347 if (n.birth > 0) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
348 # Add new birth -- might be in different generations.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
349 new.gen <- vec.ind[1] + 1
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
350 # Egg profile.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
351 new.ind <- c(new.gen, 0, 0, 0, 0)
f20a67192cfa Uploaded
greg
parents:
diff changeset
352 new.vec <- rep(new.ind, n.birth)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
353 # Update batch of egg profile.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
354 new.vec <- t(matrix(new.vec, nrow=5))
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
355 # Group with total eggs laid in that day.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
356 birth.vec <- rbind(birth.vec, new.vec)
f20a67192cfa Uploaded
greg
parents:
diff changeset
357 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
358 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
359
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
360 # Event 2 oviposition -- for gen 1.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
361 if (vec.ind[2] == 4 && vec.ind[1] == 1 && mean.temp > 12.5 && day < 222) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
362 # Vittelogenic stage, 1st generation
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
363 if (vec.ind[4] == 0) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
364 # Just turned in vittelogenic stage.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
365 n.birth=round(runif(1, 2 + opt$min_clutch_size, 8 + opt$max_clutch_size))
f20a67192cfa Uploaded
greg
parents:
diff changeset
366 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
367 else {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
368 # Daily probability of birth.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
369 p.birth = opt$oviposition * 0.01
f20a67192cfa Uploaded
greg
parents:
diff changeset
370 u1 <- runif(1)
f20a67192cfa Uploaded
greg
parents:
diff changeset
371 if (u1 < p.birth) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
372 n.birth = round(runif(1, 2, 8))
f20a67192cfa Uploaded
greg
parents:
diff changeset
373 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
374 }
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
375 # Add to dd.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
376 vec.ind[3] <- vec.ind[3] + dd.temp
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
377 # Add 1 day in current stage.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
378 vec.ind[4] <- vec.ind[4] + 1
f20a67192cfa Uploaded
greg
parents:
diff changeset
379 vec.mat[i,] <- vec.ind
f20a67192cfa Uploaded
greg
parents:
diff changeset
380 if (n.birth > 0) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
381 # Add new birth -- might be in different generations.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
382 new.gen <- vec.ind[1] + 1
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
383 # Egg profile.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
384 new.ind <- c(new.gen, 0, 0, 0, 0)
f20a67192cfa Uploaded
greg
parents:
diff changeset
385 new.vec <- rep(new.ind, n.birth)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
386 # Update batch of egg profile.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
387 new.vec <- t(matrix(new.vec, nrow=5))
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
388 # Group with total eggs laid in that day.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
389 birth.vec <- rbind(birth.vec, new.vec)
f20a67192cfa Uploaded
greg
parents:
diff changeset
390 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
391 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
392
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
393 # Event 3 development (with diapause determination).
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
394 # Event 3.1 egg development to young nymph (vec.ind[2]=0 -> egg).
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
395 if (vec.ind[2] == 0) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
396 # Egg stage.
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
397 # Add to dd.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
398 vec.ind[3] <- vec.ind[3] + dd.temp
f20a67192cfa Uploaded
greg
parents:
diff changeset
399 if (vec.ind[3] >= (68 + opt$young_nymph_accum)) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
400 # From egg to young nymph, DD requirement met.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
401 current.gen <- vec.ind[1]
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
402 # Transfer to young nymph stage.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
403 vec.ind <- c(current.gen, 1, 0, 0, 0)
f20a67192cfa Uploaded
greg
parents:
diff changeset
404 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
405 else {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
406 # Add 1 day in current stage.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
407 vec.ind[4] <- vec.ind[4] + 1
f20a67192cfa Uploaded
greg
parents:
diff changeset
408 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
409 vec.mat[i,] <- vec.ind
f20a67192cfa Uploaded
greg
parents:
diff changeset
410 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
411
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
412 # Event 3.2 young nymph to old nymph (vec.ind[2]=1 -> young nymph: determines diapause).
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
413 if (vec.ind[2] == 1) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
414 # young nymph stage.
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
415 # add to dd.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
416 vec.ind[3] <- vec.ind[3] + dd.temp
f20a67192cfa Uploaded
greg
parents:
diff changeset
417 if (vec.ind[3] >= (250 + opt$old_nymph_accum)) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
418 # From young to old nymph, dd requirement met.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
419 current.gen <- vec.ind[1]
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
420 # Transfer to old nym stage.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
421 vec.ind <- c(current.gen, 2, 0, 0, 0)
f20a67192cfa Uploaded
greg
parents:
diff changeset
422 if (photoperiod < opt$photoperiod && day > 180) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
423 vec.ind[5] <- 1
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
424 } # Prepare for diapausing.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
425 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
426 else {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
427 # Add 1 day in current stage.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
428 vec.ind[4] <- vec.ind[4] + 1
f20a67192cfa Uploaded
greg
parents:
diff changeset
429 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
430 vec.mat[i,] <- vec.ind
f20a67192cfa Uploaded
greg
parents:
diff changeset
431 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
432
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
433 # Event 3.3 old nymph to adult: previttelogenic or diapausing?
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
434 if (vec.ind[2] == 2) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
435 # Old nymph stage.
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
436 # add to dd.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
437 vec.ind[3] <- vec.ind[3] + dd.temp
f20a67192cfa Uploaded
greg
parents:
diff changeset
438 if (vec.ind[3] >= (200 + opt$adult_accum)) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
439 # From old to adult, dd requirement met.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
440 current.gen <- vec.ind[1]
f20a67192cfa Uploaded
greg
parents:
diff changeset
441 if (vec.ind[5] == 0) {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
442 # Non-diapausing adult -- previttelogenic.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
443 vec.ind <- c(current.gen, 3, 0, 0, 0)
f20a67192cfa Uploaded
greg
parents:
diff changeset
444 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
445 else {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
446 # Diapausing.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
447 vec.ind <- c(current.gen, 5, 0, 0, 1)
f20a67192cfa Uploaded
greg
parents:
diff changeset
448 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
449 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
450 else {
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
451 # Add 1 day in current stage.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
452 vec.ind[4] <- vec.ind[4] + 1
f20a67192cfa Uploaded
greg
parents:
diff changeset
453 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
454 vec.mat[i,] <- vec.ind
f20a67192cfa Uploaded
greg
parents:
diff changeset
455 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
456
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
457 # Event 4 growing of diapausing adult (unimportant, but still necessary).
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
458 if (vec.ind[2] == 5) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
459 vec.ind[3] <- vec.ind[3] + dd.temp
f20a67192cfa Uploaded
greg
parents:
diff changeset
460 vec.ind[4] <- vec.ind[4] + 1
f20a67192cfa Uploaded
greg
parents:
diff changeset
461 vec.mat[i,] <- vec.ind
f20a67192cfa Uploaded
greg
parents:
diff changeset
462 }
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
463 } # Else if it is still alive.
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
464 } # End of the individual bug loop.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
465
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
466 # Find how many died.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
467 n.death <- length(death.vec)
f20a67192cfa Uploaded
greg
parents:
diff changeset
468 if (n.death > 0) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
469 vec.mat <- vec.mat[-death.vec, ]
f20a67192cfa Uploaded
greg
parents:
diff changeset
470 }
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
471 # Remove record of dead.
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
472 # Find how many new born.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
473 n.newborn <- length(birth.vec[,1])
f20a67192cfa Uploaded
greg
parents:
diff changeset
474 vec.mat <- rbind(vec.mat, birth.vec)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
475 # Update population size for the next day.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
476 n <- n - n.death + n.newborn
f20a67192cfa Uploaded
greg
parents:
diff changeset
477
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
478 # Aggregate results by day.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
479 tot.pop <- c(tot.pop, n)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
480 # Egg.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
481 s0 <- sum(vec.mat[,2] == 0)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
482 # Young nymph.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
483 s1 <- sum(vec.mat[,2] == 1)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
484 # Old nymph.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
485 s2 <- sum(vec.mat[,2] == 2)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
486 # Previtellogenic.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
487 s3 <- sum(vec.mat[,2] == 3)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
488 # Vitellogenic.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
489 s4 <- sum(vec.mat[,2] == 4)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
490 # Diapausing.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
491 s5 <- sum(vec.mat[,2] == 5)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
492 # Overwintering adult.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
493 gen0 <- sum(vec.mat[,1] == 0)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
494 # First generation.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
495 gen1 <- sum(vec.mat[,1] == 1)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
496 # Second generation.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
497 gen2 <- sum(vec.mat[,1] == 2)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
498 # Sum of all adults.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
499 n.adult <- sum(vec.mat[,2] == 3) + sum(vec.mat[,2] == 4) + sum(vec.mat[,2] == 5)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
500 # Gen eration 0 pop size.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
501 gen0.pop[day] <- gen0
f20a67192cfa Uploaded
greg
parents:
diff changeset
502 gen1.pop[day] <- gen1
f20a67192cfa Uploaded
greg
parents:
diff changeset
503 gen2.pop[day] <- gen2
f20a67192cfa Uploaded
greg
parents:
diff changeset
504 S0[day] <- s0
f20a67192cfa Uploaded
greg
parents:
diff changeset
505 S1[day] <- s1
f20a67192cfa Uploaded
greg
parents:
diff changeset
506 S2[day] <- s2
f20a67192cfa Uploaded
greg
parents:
diff changeset
507 S3[day] <- s3
f20a67192cfa Uploaded
greg
parents:
diff changeset
508 S4[day] <- s4
f20a67192cfa Uploaded
greg
parents:
diff changeset
509 S5[day] <- s5
f20a67192cfa Uploaded
greg
parents:
diff changeset
510 g0.adult[day] <- sum(vec.mat[,1] == 0)
f20a67192cfa Uploaded
greg
parents:
diff changeset
511 g1.adult[day] <- sum((vec.mat[,1] == 1 & vec.mat[,2] == 3) | (vec.mat[,1] == 1 & vec.mat[,2] == 4) | (vec.mat[,1] == 1 & vec.mat[,2] == 5))
f20a67192cfa Uploaded
greg
parents:
diff changeset
512 g2.adult[day] <- sum((vec.mat[,1]== 2 & vec.mat[,2] == 3) | (vec.mat[,1] == 2 & vec.mat[,2] == 4) | (vec.mat[,1] == 2 & vec.mat[,2] == 5))
f20a67192cfa Uploaded
greg
parents:
diff changeset
513
f20a67192cfa Uploaded
greg
parents:
diff changeset
514 N.newborn[day] <- n.newborn
f20a67192cfa Uploaded
greg
parents:
diff changeset
515 N.death[day] <- n.death
f20a67192cfa Uploaded
greg
parents:
diff changeset
516 N.adult[day] <- n.adult
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
517 } # end of days specified in the input temperature data
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
518
f20a67192cfa Uploaded
greg
parents:
diff changeset
519 dd.cum <- cumsum(dd.day)
26
3c06cab3db2c Uploaded
greg
parents: 24
diff changeset
520 # Collect all the outputs.
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
521 S0.rep[,N.rep] <- S0
f20a67192cfa Uploaded
greg
parents:
diff changeset
522 S1.rep[,N.rep] <- S1
f20a67192cfa Uploaded
greg
parents:
diff changeset
523 S2.rep[,N.rep] <- S2
f20a67192cfa Uploaded
greg
parents:
diff changeset
524 S3.rep[,N.rep] <- S3
f20a67192cfa Uploaded
greg
parents:
diff changeset
525 S4.rep[,N.rep] <- S4
f20a67192cfa Uploaded
greg
parents:
diff changeset
526 S5.rep[,N.rep] <- S5
f20a67192cfa Uploaded
greg
parents:
diff changeset
527 newborn.rep[,N.rep] <- N.newborn
f20a67192cfa Uploaded
greg
parents:
diff changeset
528 death.rep[,N.rep] <- N.death
f20a67192cfa Uploaded
greg
parents:
diff changeset
529 adult.rep[,N.rep] <- N.adult
f20a67192cfa Uploaded
greg
parents:
diff changeset
530 pop.rep[,N.rep] <- tot.pop
f20a67192cfa Uploaded
greg
parents:
diff changeset
531 g0.rep[,N.rep] <- gen0.pop
f20a67192cfa Uploaded
greg
parents:
diff changeset
532 g1.rep[,N.rep] <- gen1.pop
f20a67192cfa Uploaded
greg
parents:
diff changeset
533 g2.rep[,N.rep] <- gen2.pop
f20a67192cfa Uploaded
greg
parents:
diff changeset
534 g0a.rep[,N.rep] <- g0.adult
f20a67192cfa Uploaded
greg
parents:
diff changeset
535 g1a.rep[,N.rep] <- g1.adult
f20a67192cfa Uploaded
greg
parents:
diff changeset
536 g2a.rep[,N.rep] <- g2.adult
f20a67192cfa Uploaded
greg
parents:
diff changeset
537 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
538
f20a67192cfa Uploaded
greg
parents:
diff changeset
539 # Data analysis and visualization
f20a67192cfa Uploaded
greg
parents:
diff changeset
540 # default: plot 1 year of result
f20a67192cfa Uploaded
greg
parents:
diff changeset
541 # but can be expanded to accommodate multiple years
f20a67192cfa Uploaded
greg
parents:
diff changeset
542 n.yr <- 1
13
80d38a26b2e8 Uploaded
greg
parents: 4
diff changeset
543 day.all <- c(1:opt$num_days * n.yr)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
544
f20a67192cfa Uploaded
greg
parents:
diff changeset
545 # mean value for adults
f20a67192cfa Uploaded
greg
parents:
diff changeset
546 sa <- apply((S3.rep + S4.rep + S5.rep), 1, mean)
f20a67192cfa Uploaded
greg
parents:
diff changeset
547 # mean value for nymphs
f20a67192cfa Uploaded
greg
parents:
diff changeset
548 sn <- apply((S1.rep + S2.rep), 1,mean)
f20a67192cfa Uploaded
greg
parents:
diff changeset
549 # mean value for eggs
f20a67192cfa Uploaded
greg
parents:
diff changeset
550 se <- apply(S0.rep, 1, mean)
f20a67192cfa Uploaded
greg
parents:
diff changeset
551 # mean value for P
f20a67192cfa Uploaded
greg
parents:
diff changeset
552 g0 <- apply(g0.rep, 1, mean)
f20a67192cfa Uploaded
greg
parents:
diff changeset
553 # mean value for F1
f20a67192cfa Uploaded
greg
parents:
diff changeset
554 g1 <- apply(g1.rep, 1, mean)
f20a67192cfa Uploaded
greg
parents:
diff changeset
555 # mean value for F2
f20a67192cfa Uploaded
greg
parents:
diff changeset
556 g2 <- apply(g2.rep, 1, mean)
f20a67192cfa Uploaded
greg
parents:
diff changeset
557 # mean value for P adult
f20a67192cfa Uploaded
greg
parents:
diff changeset
558 g0a <- apply(g0a.rep, 1, mean)
f20a67192cfa Uploaded
greg
parents:
diff changeset
559 # mean value for F1 adult
f20a67192cfa Uploaded
greg
parents:
diff changeset
560 g1a <- apply(g1a.rep, 1, mean)
f20a67192cfa Uploaded
greg
parents:
diff changeset
561 # mean value for F2 adult
f20a67192cfa Uploaded
greg
parents:
diff changeset
562 g2a <- apply(g2a.rep, 1, mean)
f20a67192cfa Uploaded
greg
parents:
diff changeset
563
f20a67192cfa Uploaded
greg
parents:
diff changeset
564 # SE for adults
f20a67192cfa Uploaded
greg
parents:
diff changeset
565 sa.se <- apply((S3.rep + S4.rep + S5.rep), 1, sd) / sqrt(opt$replications)
f20a67192cfa Uploaded
greg
parents:
diff changeset
566 # SE for nymphs
f20a67192cfa Uploaded
greg
parents:
diff changeset
567 sn.se <- apply((S1.rep + S2.rep) / sqrt(opt$replications), 1, sd)
f20a67192cfa Uploaded
greg
parents:
diff changeset
568 # SE for eggs
f20a67192cfa Uploaded
greg
parents:
diff changeset
569 se.se <- apply(S0.rep, 1, sd) / sqrt(opt$replications)
f20a67192cfa Uploaded
greg
parents:
diff changeset
570 # SE value for P
f20a67192cfa Uploaded
greg
parents:
diff changeset
571 g0.se <- apply(g0.rep, 1, sd) / sqrt(opt$replications)
f20a67192cfa Uploaded
greg
parents:
diff changeset
572 # SE for F1
f20a67192cfa Uploaded
greg
parents:
diff changeset
573 g1.se <- apply(g1.rep, 1, sd) / sqrt(opt$replications)
f20a67192cfa Uploaded
greg
parents:
diff changeset
574 # SE for F2
f20a67192cfa Uploaded
greg
parents:
diff changeset
575 g2.se <- apply(g2.rep, 1, sd) / sqrt(opt$replications)
f20a67192cfa Uploaded
greg
parents:
diff changeset
576 # SE for P adult
f20a67192cfa Uploaded
greg
parents:
diff changeset
577 g0a.se <- apply(g0a.rep, 1, sd) / sqrt(opt$replications)
f20a67192cfa Uploaded
greg
parents:
diff changeset
578 # SE for F1 adult
f20a67192cfa Uploaded
greg
parents:
diff changeset
579 g1a.se <- apply(g1a.rep, 1, sd) / sqrt(opt$replications)
f20a67192cfa Uploaded
greg
parents:
diff changeset
580 # SE for F2 adult
f20a67192cfa Uploaded
greg
parents:
diff changeset
581 g2a.se <- apply(g2a.rep, 1, sd) / sqrt(opt$replications)
f20a67192cfa Uploaded
greg
parents:
diff changeset
582
f20a67192cfa Uploaded
greg
parents:
diff changeset
583 dev.new(width=20, height=20)
f20a67192cfa Uploaded
greg
parents:
diff changeset
584
f20a67192cfa Uploaded
greg
parents:
diff changeset
585 # Start PDF device driver to save charts to output.
f20a67192cfa Uploaded
greg
parents:
diff changeset
586 pdf(file=opt$output, height=20, width=20, bg="white")
f20a67192cfa Uploaded
greg
parents:
diff changeset
587
f20a67192cfa Uploaded
greg
parents:
diff changeset
588 par(mar = c(5, 6, 4, 4), mfrow=c(3, 1))
f20a67192cfa Uploaded
greg
parents:
diff changeset
589
f20a67192cfa Uploaded
greg
parents:
diff changeset
590 # Subfigure 2: population size by life stage
35
21e8dc696db3 Uploaded
greg
parents: 34
diff changeset
591 title <- paste(opt$location, ",", start_date, "to", end_date, ": BSMB Total Population Size by Life Stage", sep=" ")
31
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
592 plot(day.all, sa, main=title, type="l", ylim=c(0, max(se + se.se, sn + sn.se, sa + sa.se)), axes=F, lwd=2, xlab="", ylab="Number", cex=2, cex.lab=2, cex.axis=2, cex.main=2)
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
593 # Young and old nymphs.
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
594 lines(day.all, sn, lwd=2, lty=1, col=2)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
595 # Eggs
31
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
596 lines(day.all, se, lwd=2, lty=1, col=4)
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
597 axis(1, at = c(1:12) * 30 - 15, cex.axis=2, labels=c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
598 axis(2, cex.axis = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
599 leg.text <- c("Egg", "Nymph", "Adult")
31
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
600 legend("topleft", leg.text, lty=c(1, 1, 1), col=c(4, 2, 1), cex=2)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
601 if (opt$se_plot == 1) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
602 # add SE lines to plot
f20a67192cfa Uploaded
greg
parents:
diff changeset
603 # SE for adults
31
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
604 lines (day.all, sa + sa.se, lty=2)
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
605 lines (day.all, sa - sa.se, lty=2)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
606 # SE for nymphs
31
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
607 lines (day.all, sn + sn.se, col=2, lty=2)
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
608 lines (day.all, sn - sn.se, col=2, lty=2)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
609 # SE for eggs
31
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
610 lines (day.all, se + se.se, col=4, lty=2)
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
611 lines (day.all, se - se.se, col=4, lty=2)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
612 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
613
f20a67192cfa Uploaded
greg
parents:
diff changeset
614 # Subfigure 3: population size by generation
35
21e8dc696db3 Uploaded
greg
parents: 34
diff changeset
615 title <- paste(opt$location, ",", start_date, "to", end_date, ": BSMB Total Population Size by Generation", sep=" ")
31
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
616 plot(day.all, g0, main=title, type="l", ylim=c(0, max(g2)), axes=F, lwd=2, xlab="", ylab="Number", cex=2, cex.lab=2, cex.axis=2, cex.main=2)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
617 lines(day.all, g1, lwd = 2, lty = 1, col = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
618 lines(day.all, g2, lwd = 2, lty = 1, col = 4)
f20a67192cfa Uploaded
greg
parents:
diff changeset
619 axis(1, at = c(1:12) * 30 - 15, cex.axis = 2, labels = c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
f20a67192cfa Uploaded
greg
parents:
diff changeset
620 axis(2, cex.axis = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
621 leg.text <- c("P", "F1", "F2")
f20a67192cfa Uploaded
greg
parents:
diff changeset
622 legend("topleft", leg.text, lty = c(1, 1, 1), col =c(1, 2, 4), cex = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
623 if (opt$se_plot == 1) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
624 # add SE lines to plot
f20a67192cfa Uploaded
greg
parents:
diff changeset
625 # SE for adults
f20a67192cfa Uploaded
greg
parents:
diff changeset
626 lines (day.all, g0 + g0.se, lty = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
627 lines (day.all, g0 - g0.se, lty = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
628 # SE for nymphs
f20a67192cfa Uploaded
greg
parents:
diff changeset
629 lines (day.all, g1 + g1.se, col = 2, lty = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
630 lines (day.all, g1 - g1.se, col = 2, lty = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
631 # SE for eggs
f20a67192cfa Uploaded
greg
parents:
diff changeset
632 lines (day.all, g2 + g2.se, col = 4, lty = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
633 lines (day.all, g2 - g2.se, col = 4, lty = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
634 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
635
f20a67192cfa Uploaded
greg
parents:
diff changeset
636 # Subfigure 4: adult population size by generation
35
21e8dc696db3 Uploaded
greg
parents: 34
diff changeset
637 title <- paste(opt$location, ",", start_date, "to", end_date, ": BSMB Adult Population Size by Generation", sep=" ")
31
e56529d02c3e Uploaded
greg
parents: 30
diff changeset
638 plot(day.all, g0a, ylim=c(0, max(g2a) + 100), main=title, type="l", axes=F, lwd=2, xlab="Year", ylab="Number", cex=2, cex.lab=2, cex.axis=2, cex.main=2)
0
f20a67192cfa Uploaded
greg
parents:
diff changeset
639 lines(day.all, g1a, lwd = 2, lty = 1, col = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
640 lines(day.all, g2a, lwd = 2, lty = 1, col = 4)
f20a67192cfa Uploaded
greg
parents:
diff changeset
641 axis(1, at = c(1:12) * 30 - 15, cex.axis = 2, labels = c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
f20a67192cfa Uploaded
greg
parents:
diff changeset
642 axis(2, cex.axis = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
643 leg.text <- c("P", "F1", "F2")
f20a67192cfa Uploaded
greg
parents:
diff changeset
644 legend("topleft", leg.text, lty = c(1, 1, 1), col = c(1, 2, 4), cex = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
645 if (opt$se_plot == 1) {
f20a67192cfa Uploaded
greg
parents:
diff changeset
646 # add SE lines to plot
f20a67192cfa Uploaded
greg
parents:
diff changeset
647 # SE for adults
f20a67192cfa Uploaded
greg
parents:
diff changeset
648 lines (day.all, g0a + g0a.se, lty = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
649 lines (day.all, g0a - g0a.se, lty = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
650 # SE for nymphs
f20a67192cfa Uploaded
greg
parents:
diff changeset
651 lines (day.all, g1a + g1a.se, col = 2, lty = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
652 lines (day.all, g1a - g1a.se, col = 2, lty = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
653 # SE for eggs
f20a67192cfa Uploaded
greg
parents:
diff changeset
654 lines (day.all, g2a + g2a.se, col = 4, lty = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
655 lines (day.all, g2a - g2a.se, col = 4, lty = 2)
f20a67192cfa Uploaded
greg
parents:
diff changeset
656 }
f20a67192cfa Uploaded
greg
parents:
diff changeset
657
f20a67192cfa Uploaded
greg
parents:
diff changeset
658 # Turn off device driver to flush output.
f20a67192cfa Uploaded
greg
parents:
diff changeset
659 dev.off()