-
Notifications
You must be signed in to change notification settings - Fork 0
/
SensitivityAnalysis_BB_Case3.R
320 lines (240 loc) · 21.3 KB
/
SensitivityAnalysis_BB_Case3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# Take the data generated in HeatExchangeODE_Variability_flying.m or
# HeatExchangeODE_Variability_resting.m and do the regression as described in
# Saltelli2006
setwd("~/SUSPOLL/Code")
# install.packages("dismo")
# install.packages("gbm")
# library(dismo)
# library(gbm)
interaction_level = 2 #level of interactions to consider in the BRT fitting (tree complexity)
n_params_resting = 24 #24 because only using one i0 param and not v
n_params_shivering = 24 #24 because only using one i0 param and not v
n_params_flying = 25 #25 because only using one i0 param
### Read in the data for parameter samples and hear flux ###
Parameter_Values = read.csv(file="ParameterSample_BB_10000_lowi0.csv")
Parameter_Values_resting = Parameter_Values[,c(-1,-4,-25)] #remove the flying i0 and v
Parameter_Values_shivering = Parameter_Values[,c(-1,-3,-25)] #remove the resting i0 and v
Parameter_Values_flying = Parameter_Values[,c(-1,-3)] #remove the resting i0
colnames(Parameter_Values_resting) = c('delta_T_h','i0','M_b','E','M_th',
'c','r','T_mK','alpha_si','epsilon_a','A_th','A_h',
'alpha_s0','alpha_th','a','P','T_gC','T_aC','epsilon_e',
'f_s','c_l','n','l_th','T_0')
colnames(Parameter_Values_shivering) = c('delta_T_h','i0','M_b','E','M_th',
'c','r','T_mK','alpha_si','epsilon_a','A_th','A_h',
'alpha_s0','alpha_th','a','P','T_gC','T_aC','epsilon_e',
'f_s','c_l','n','l_th','T_0')
colnames(Parameter_Values_flying) = c('delta_T_h','i0','M_b','E','M_th',
'c','r','T_mK','alpha_si','epsilon_a','A_th','A_h',
'alpha_s0','alpha_th','a','P','T_gC','T_aC','epsilon_e',
'f_s','c_l','n','l_th','v','T_0')
Equilibria_resting = read.csv(file="BB_Thorax_Equilibria_Variability_resting_case3_10000.csv",header=FALSE)
Equilibria_shivering = read.csv(file="BB_Thorax_Equilibria_Variability_shivering_case3_10000.csv",header=FALSE)
Equilibria_flying = read.csv(file="BB_Thorax_Equilibria_Variability_flying_case3_10000.csv",header=FALSE)
reg_data_equilibria_resting = cbind(Equilibria_resting,Parameter_Values_resting)
reg_data_equilibria_shivering = cbind(Equilibria_resting,Parameter_Values_shivering)
reg_data_equilibria_flying = cbind(Equilibria_flying,Parameter_Values_flying)
colnames(reg_data_equilibria_resting) = c('equilibria','delta_T_h','i0','M_b','E','M_th',
'c','r','T_mK','alpha_si','epsilon_a','A_th','A_h',
'alpha_s0','alpha_th','a','P','T_gC','T_aC','epsilon_e',
'f_s','c_l','n','l_th','T_0')
colnames(reg_data_equilibria_shivering) = c('equilibria','delta_T_h','i0','M_b','E','M_th',
'c','r','T_mK','alpha_si','epsilon_a','A_th','A_h',
'alpha_s0','alpha_th','a','P','T_gC','T_aC','epsilon_e',
'f_s','c_l','n','l_th','T_0')
colnames(reg_data_equilibria_flying) = c('equilibria','delta_T_h','i0','M_b','E','M_th',
'c','r','T_mK','alpha_si','epsilon_a','A_th','A_h',
'alpha_s0','alpha_th','a','P','T_gC','T_aC','epsilon_e',
'f_s','c_l','n','l_th','v','T_0')
reg_data_equilibria_resting_edited = na.omit(reg_data_equilibria_resting)
reg_data_equilibria_shivering_edited = na.omit(reg_data_equilibria_shivering)
reg_data_equilibria_flying_edited = na.omit(reg_data_equilibria_flying)
# par(mfrow=c(3,1))
# hist(reg_data_equilibria_resting_edited[ ,1], main='equilibrium thorax temps while resting',xlab='temperature')
# hist(reg_data_equilibria_shivering_edited[ ,1], main='equilibrium thorax temps while shivering',xlab='temperature')
# hist(reg_data_equilibria_flying_edited[ ,1], main='equilibrium thorax temps while flying',xlab='temperature')
maxouts_resting=which(reg_data_equilibria_resting_edited[ ,1]==100)
maxouts_shivering=which(reg_data_equilibria_shivering_edited[ ,1]==100)
maxouts_flying=which(reg_data_equilibria_flying_edited[ ,1]==100)
if(length(maxouts_resting)>0){
reg_data_equilibria_resting_edited = reg_data_equilibria_resting_edited[-maxouts_resting, ] #remove the rows with temp 100
}
if(length(maxouts_shivering)>0){
reg_data_equilibria_shivering_edited = reg_data_equilibria_shivering_edited[-maxouts_shivering, ] #remove the rows with temp 100
}
if(length(maxouts_flying)>0){
reg_data_equilibria_flying_edited = reg_data_equilibria_flying_edited[-maxouts_flying, ] #remove the rows with temp 100
}
par(mfrow=c(3,1))
hist(reg_data_equilibria_resting_edited[ ,1], main='equilibrium thorax temps while resting',xlab='temperature')
hist(reg_data_equilibria_shivering_edited[ ,1], main='equilibrium thorax temps while shivering',xlab='temperature')
hist(reg_data_equilibria_flying_edited[ ,1], main='equilibrium thorax temps while flying',xlab='temperature')
######################## Fitting #################################
BRT_equilibria_resting = gbm.step(data=reg_data_equilibria_resting_edited,gbm.x=2:(n_params_resting+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
#par(mfrow=c(4,4))
#gbm.plot(BRT_equilibria_flying,n.plots=16,write.title=FALSE) #plots
resting_contributions = BRT_equilibria_resting$contributions #the influence of each parameter
resting_R2 = BRT_equilibria_resting$cv.statistics$correlation.mean^2 #might be the R^2 value...
BRT_equilibria_shivering = gbm.step(data=reg_data_equilibria_shivering_edited,gbm.x=2:(n_params_shivering+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
#par(mfrow=c(4,4))
#gbm.plot(BRT_equilibria_flying,n.plots=16,write.title=FALSE) #plots
shivering_contributions = BRT_equilibria_shivering$contributions #the influence of each parameter
shivering_R2 = BRT_equilibria_shivering$cv.statistics$correlation.mean^2 #might be the R^2 value...
BRT_equilibria_flying = gbm.step(data=reg_data_equilibria_flying_edited,gbm.x=2:(n_params_flying+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
# par(mfrow=c(4,4))
# gbm.plot(BRT_equilibria_flying,n.plots=16,write.title=FALSE) #plots
flying_contributions = BRT_equilibria_flying$contributions #the influence of each parameter
flying_R2 = BRT_equilibria_flying$cv.statistics$correlation.mean^2 #might be the R^2 value...
resting_contributions
shivering_contributions
flying_contributions
write.csv(resting_contributions,file="case3_contributions_resting.csv")
write.csv(shivering_contributions,file="case3_contributions_shivering.csv")
write.csv(flying_contributions,file="case3_contributions_flying.csv")
resting_R2
shivering_R2
flying_R2
write.csv(c(resting_R2,shivering_R2,flying_R2),file="case3_R2_values.csv")
# Interactions_equilibria_resting = gbm.interactions(BRT_equilibria_resting)
# interactions_resting = Interactions_equilibria_resting$interactions
# InteractionsRank_resting = Interactions_equilibria_resting$rank.list
#
# Interactions_equilibria_shivering = gbm.interactions(BRT_equilibria_shivering)
# Interactions_shivering = Interactions_equilibria_shivering$interactions
# InteractionsRank_shivering = Interactions_equilibria_shivering$rank.list
#
# Interactions_equilibria_flying = gbm.interactions(BRT_equilibria_flying)
# Interactions_flying = Interactions_equilibria_flying$interactions
# InteractionsRank_flying = Interactions_equilibria_flying$rank.list
######################################################################################################
########### Check for sufficient sample size ###################################
### Check the sampling efficiency
resting_length = dim(reg_data_equilibria_resting_edited)[1]
shivering_length = dim(reg_data_equilibria_shivering_edited)[1]
flying_length = dim(reg_data_equilibria_flying_edited)[1]
sample_1000_resting = sample(1:resting_length,size=1000,replace=FALSE)
sample_1000_shivering = sample(1:shivering_length,size=1000,replace=FALSE)
sample_1000_flying = sample(1:flying_length,size=1000,replace=FALSE)
sample_2500_resting = sample(1:resting_length,size=2500,replace=FALSE)
sample_2500_shivering = sample(1:shivering_length,size=2500,replace=FALSE)
sample_2500_flying = sample(1:flying_length,size=2500,replace=FALSE)
sample_5000_resting = sample(1:resting_length,size=5000,replace=FALSE)
sample_5000_shivering = sample(1:shivering_length,size=5000,replace=FALSE)
sample_4000_flying = sample(1:flying_length,size=4000,replace=FALSE)
sample_7500_resting = sample(1:resting_length,size=7500,replace=FALSE)
sample_7500_shivering = sample(1:shivering_length,size=7500,replace=FALSE)
sample_5000_flying = sample(1:flying_length,size=5000,replace=FALSE)
reg_data_equilibria_resting_edited_1000 = reg_data_equilibria_resting_edited[sample_1000_resting,]
BRT_resting_1000 = gbm.step(data=reg_data_equilibria_resting_edited_1000,gbm.x=2:(n_params_resting+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
Influences_resting_1000 = BRT_resting_1000$contributions[,2] #the influence of each parameter
reg_data_equilibria_shivering_edited_1000 = reg_data_equilibria_shivering_edited[sample_1000_shivering,]
BRT_shivering_1000 = gbm.step(data=reg_data_equilibria_shivering_edited_1000,gbm.x=2:(n_params_shivering+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
Influences_shivering_1000 = BRT_shivering_1000$contributions[,2] #the influence of each parameter
reg_data_equilibria_flying_edited_1000 = reg_data_equilibria_flying_edited[sample_1000_flying,]
BRT_flying_1000 = gbm.step(data=reg_data_equilibria_flying_edited_1000,gbm.x=2:(n_params_flying+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
Influences_flying_1000 = BRT_flying_1000$contributions[,2] #the influence of each parameter
write.csv(Influences_resting_1000,file="case3_Influences_resting_1000.csv")
write.csv(Influences_shivering_1000,file="case3_Influences_shivering_1000.csv")
write.csv(Influences_flying_1000,file="case3_Influences_flying_1000.csv")
reg_data_equilibria_resting_edited_2500 = reg_data_equilibria_resting_edited[sample_2500_resting,]
BRT_resting_2500 = gbm.step(data=reg_data_equilibria_resting_edited_2500,gbm.x=2:(n_params_resting+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
Influences_resting_2500 = BRT_resting_2500$contributions[,2] #the influence of each parameter
reg_data_equilibria_shivering_edited_2500 = reg_data_equilibria_shivering_edited[sample_2500_shivering,]
BRT_shivering_2500 = gbm.step(data=reg_data_equilibria_shivering_edited_2500,gbm.x=2:(n_params_shivering+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
Influences_shivering_2500 = BRT_shivering_2500$contributions[,2] #the influence of each parameter
reg_data_equilibria_flying_edited_2500 = reg_data_equilibria_flying_edited[sample_2500_flying,]
BRT_flying_2500 = gbm.step(data=reg_data_equilibria_flying_edited_2500,gbm.x=2:(n_params_flying+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
Influences_flying_2500 = BRT_flying_2500$contributions[,2] #the influence of each parameter
write.csv(Influences_resting_2500,file="case3_Influences_resting_2500.csv")
write.csv(Influences_shivering_2500,file="case3_Influences_shivering_2500.csv")
write.csv(Influences_flying_2500,file="case3_Influences_flying_2500.csv")
reg_data_equilibria_resting_edited_5000 = reg_data_equilibria_resting_edited[sample_5000_resting,]
BRT_resting_5000 = gbm.step(data=reg_data_equilibria_resting_edited_5000,gbm.x=2:(n_params_resting+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
Influences_resting_5000 = BRT_resting_5000$contributions[,2] #the influence of each parameter
reg_data_equilibria_shivering_edited_5000 = reg_data_equilibria_shivering_edited[sample_5000_shivering,]
BRT_shivering_5000 = gbm.step(data=reg_data_equilibria_shivering_edited_5000,gbm.x=2:(n_params_shivering+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
Influences_shivering_5000 = BRT_shivering_5000$contributions[,2] #the influence of each parameter
reg_data_equilibria_flying_edited_4000 = reg_data_equilibria_flying_edited[sample_4000_flying,]
BRT_flying_4000 = gbm.step(data=reg_data_equilibria_flying_edited_4000,gbm.x=2:(n_params_flying+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
Influences_flying_4000 = BRT_flying_4000$contributions[,2] #the influence of each parameter
write.csv(Influences_resting_5000,file="case3_Influences_resting_5000.csv")
write.csv(Influences_shivering_5000,file="case3_Influences_shivering_5000.csv")
write.csv(Influences_flying_4000,file="case3_Influences_flying_4000.csv")
reg_data_equilibria_resting_edited_7500 = reg_data_equilibria_resting_edited[sample_7500_resting,]
BRT_resting_7500 = gbm.step(data=reg_data_equilibria_resting_edited_7500,gbm.x=2:(n_params_resting+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
Influences_resting_7500 = BRT_resting_7500$contributions[,2] #the influence of each parameter
reg_data_equilibria_shivering_edited_7500 = reg_data_equilibria_shivering_edited[sample_7500_shivering,]
BRT_shivering_7500 = gbm.step(data=reg_data_equilibria_shivering_edited_7500,gbm.x=2:(n_params_shivering+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
Influences_shivering_7500 = BRT_shivering_7500$contributions[,2] #the influence of each parameter
reg_data_equilibria_flying_edited_5000 = reg_data_equilibria_flying_edited[sample_5000_flying,]
BRT_flying_5000 = gbm.step(data=reg_data_equilibria_flying_edited_5000,gbm.x=2:(n_params_flying+1),gbm.y=1,learning.rate=0.01, bag.fraction=0.75, tree.complexity = interaction_level, n.folds=10, family="gaussian")
Influences_flying_5000 = BRT_flying_5000$contributions[,2] #the influence of each parameter
write.csv(Influences_resting_7500,file="case3_Influences_resting_7500.csv")
write.csv(Influences_shivering_7500,file="case3_Influences_shivering_7500.csv")
write.csv(Influences_flying_5000,file="case3_Influences_flying_5000.csv")
Influences_resting_10000 = BRT_equilibria_resting$contributions[,2]
Influences_shivering_10000 = BRT_equilibria_shivering$contributions[,2]
Influences_flying_6592 = BRT_equilibria_flying$contributions[,2]
write.csv(Influences_resting_10000,file="case3_Influences_resting_10000.csv")
write.csv(Influences_shivering_10000,file="case3_Influences_shivering_10000.csv")
write.csv(Influences_flying_6592,file="case3_Influences_flying_6592.csv")
# For 100-250
Average_Influences_resting_1000_2500 = apply(cbind(Influences_resting_1000,Influences_resting_2500),1,mean)
Inner_sum_1000 = sum(Influences_resting_1000*log(Influences_resting_1000)/2,na.rm=TRUE)
Inner_sum_2500 = sum(Influences_resting_2500*log(Influences_resting_2500)/2,na.rm=TRUE)
D_resting_1000_2500 = Inner_sum_1000+Inner_sum_2500 - sum(Average_Influences_resting_1000_2500*log(Average_Influences_resting_1000_2500),na.rm=TRUE)
Average_Influences_shivering_1000_2500 = apply(cbind(Influences_shivering_1000,Influences_shivering_2500),1,mean)
Inner_sum_1000 = sum(Influences_shivering_1000*log(Influences_shivering_1000)/2,na.rm=TRUE)
Inner_sum_2500 = sum(Influences_shivering_2500*log(Influences_shivering_2500)/2,na.rm=TRUE)
D_shivering_1000_2500 = Inner_sum_1000+Inner_sum_2500 - sum(Average_Influences_shivering_1000_2500*log(Average_Influences_shivering_1000_2500),na.rm=TRUE)
Average_Influences_flying_1000_2500 = apply(cbind(Influences_flying_1000,Influences_flying_2500),1,mean)
Inner_sum_1000 = sum(Influences_flying_1000*log(Influences_flying_1000)/2,na.rm=TRUE)
Inner_sum_2500 = sum(Influences_flying_2500*log(Influences_flying_2500)/2,na.rm=TRUE)
D_flying_1000_2500 = Inner_sum_1000+Inner_sum_2500 - sum(Average_Influences_flying_1000_2500*log(Average_Influences_flying_1000_2500),na.rm=TRUE)
# For 250-500
Average_Influences_resting_2500_5000 = apply(cbind(Influences_resting_2500,Influences_resting_5000),1,mean)
Inner_sum_2500 = sum(Influences_resting_2500*log(Influences_resting_2500)/2,na.rm=TRUE)
Inner_sum_5000 = sum(Influences_resting_5000*log(Influences_resting_5000)/2,na.rm=TRUE)
D_resting_2500_5000 = Inner_sum_2500+Inner_sum_5000 - sum(Average_Influences_resting_2500_5000*log(Average_Influences_resting_2500_5000),na.rm=TRUE)
Average_Influences_shivering_2500_5000 = apply(cbind(Influences_shivering_2500,Influences_shivering_5000),1,mean)
Inner_sum_2500 = sum(Influences_shivering_2500*log(Influences_shivering_2500)/2,na.rm=TRUE)
Inner_sum_5000 = sum(Influences_shivering_5000*log(Influences_shivering_5000)/2,na.rm=TRUE)
D_shivering_2500_5000 = Inner_sum_2500+Inner_sum_5000 - sum(Average_Influences_shivering_2500_5000*log(Average_Influences_shivering_2500_5000),na.rm=TRUE)
Average_Influences_flying_2500_4000 = apply(cbind(Influences_flying_2500,Influences_flying_4000),1,mean)
Inner_sum_2500 = sum(Influences_flying_2500*log(Influences_flying_2500)/2,na.rm=TRUE)
Inner_sum_4000 = sum(Influences_flying_4000*log(Influences_flying_4000)/2,na.rm=TRUE)
D_flying_2500_4000 = Inner_sum_2500+Inner_sum_4000 - sum(Average_Influences_flying_2500_4000*log(Average_Influences_flying_2500_4000),na.rm=TRUE)
# For 500-750
Average_Influences_resting_5000_7500 = apply(cbind(Influences_resting_5000,Influences_resting_7500),1,mean)
Inner_sum_5000 = sum(Influences_resting_5000*log(Influences_resting_5000)/2,na.rm=TRUE)
Inner_sum_7500 = sum(Influences_resting_7500*log(Influences_resting_7500)/2,na.rm=TRUE)
D_resting_5000_7500 = Inner_sum_5000+Inner_sum_7500 - sum(Average_Influences_resting_5000_7500*log(Average_Influences_resting_5000_7500),na.rm=TRUE)
Average_Influences_shivering_5000_7500 = apply(cbind(Influences_shivering_5000,Influences_shivering_7500),1,mean)
Inner_sum_5000 = sum(Influences_shivering_5000*log(Influences_shivering_5000)/2,na.rm=TRUE)
Inner_sum_7500 = sum(Influences_shivering_7500*log(Influences_shivering_7500)/2,na.rm=TRUE)
D_shivering_5000_7500 = Inner_sum_5000+Inner_sum_7500 - sum(Average_Influences_shivering_5000_7500*log(Average_Influences_shivering_5000_7500),na.rm=TRUE)
Average_Influences_flying_4000_5000 = apply(cbind(Influences_flying_4000,Influences_flying_5000),1,mean)
Inner_sum_4000 = sum(Influences_flying_4000*log(Influences_flying_4000)/2,na.rm=TRUE)
Inner_sum_5000 = sum(Influences_flying_5000*log(Influences_flying_5000)/2,na.rm=TRUE)
D_flying_4000_5000 = Inner_sum_4000+Inner_sum_5000 - sum(Average_Influences_flying_4000_5000*log(Average_Influences_flying_4000_5000),na.rm=TRUE)
# For 750-6592
Average_Influences_resting_7500_10000 = apply(cbind(Influences_resting_7500,Influences_resting_10000),1,mean)
Inner_sum_7500 = sum(Influences_resting_7500*log(Influences_resting_7500)/2,na.rm=TRUE)
Inner_sum_10000 = sum(Influences_resting_10000*log(Influences_resting_10000)/2,na.rm=TRUE)
D_resting_7500_10000 = Inner_sum_7500+Inner_sum_10000 - sum(Average_Influences_resting_7500_10000*log(Average_Influences_resting_7500_10000),na.rm=TRUE)
Average_Influences_shivering_7500_10000 = apply(cbind(Influences_shivering_7500,Influences_shivering_10000),1,mean)
Inner_sum_7500 = sum(Influences_shivering_7500*log(Influences_shivering_7500)/2,na.rm=TRUE)
Inner_sum_10000 = sum(Influences_shivering_10000*log(Influences_shivering_10000)/2,na.rm=TRUE)
D_shivering_7500_10000 = Inner_sum_7500+Inner_sum_10000 - sum(Average_Influences_shivering_7500_10000*log(Average_Influences_shivering_7500_10000),na.rm=TRUE)
Average_Influences_flying_5000_6592 = apply(cbind(Influences_flying_5000,Influences_flying_6592),1,mean)
Inner_sum_5000 = sum(Influences_flying_5000*log(Influences_flying_5000)/2,na.rm=TRUE)
Inner_sum_6592 = sum(Influences_flying_6592*log(Influences_flying_6592)/2,na.rm=TRUE)
D_flying_5000_6592 = Inner_sum_5000+Inner_sum_6592 - sum(Average_Influences_flying_5000_6592*log(Average_Influences_flying_5000_6592),na.rm=TRUE)
## All together
D_resting = exp(c(D_resting_1000_2500,D_resting_2500_5000,D_resting_5000_7500,D_resting_7500_10000))
D_shivering = exp(c(D_shivering_1000_2500,D_shivering_2500_5000,D_shivering_5000_7500,D_shivering_7500_10000))
D_flying = exp(c(D_flying_1000_2500,D_flying_2500_4000,D_flying_4000_5000,D_flying_5000_6592))
par(mfrow=c(3,1))
plot(D_resting,main="Resting Bee Case 3",type='b')
plot(D_shivering, main="Shivering Bee Case 3",type='b')
plot(D_flying, main="Flying Bee Case 3",type='b')
write.csv(cbind(D_resting,D_shivering,D_flying),file="case3_D_values.csv")