annotate insect_phenology_model.R @ 3:24fa0d35a8bf draft

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