-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsensitivity analysis.R
90 lines (59 loc) · 1.98 KB
/
sensitivity analysis.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
###===========================###
#Try sensitivity analysis
###===========================###
library(Rpreles)
library(BayesianTools)
library(sensitivity)
##
#Load dqta
##
load("B:/modeling/project/06-PrelesData/EddyCovarianceDataBorealSites.rdata")
load("B:/modeling/project/06-PrelesData/parameterRanges.rdata")
##
#Run the model
##
PAR <- s1$PAR
Tair <- s1$TAir
D <- s1$VPD
Precip <- s1$Precip
co2 <- s1$CO2
fAPAR <- s1$fAPAR
o2 <- PRELES(PAR, Tair, D, Precip, co2, fAPAR,returncols=c("GPP", "ET", "SW", "fW", "fE"), LOGFLAG=0)
##
#Morris
##
refPars <- par
parSel <- c(1:30)
likelihood <- function(x, sum = TRUE){
x <- createMixWithDefaults(x, refPars$def, parSel)
predicted <- PRELES(PAR, Tair, D, Precip, co2, fAPAR,
returncols=c("GPP", "ET", "SW", "fW", "fE"), LOGFLAG = 0, p = x[1:30])
predicted[,1] = 1000 * predicted[,1]
diff <- c(predicted[,1:4] - obs[,1:4])
llValues <- dtriangle(diff, sd = x[12], log = T)
if (sum == FALSE) return(llValues)
else return(sum(llValues))
}
#prior
parSel = c(1:32)
prior <- createUniformPrior(lower = refPars$min[parSel], upper = refPars$max[parSel], best = refPars$def[parSel])
bayesianSetup <- createBayesianSetup(likelihood, prior, names = rownames(refPars)[parSel])
bayesianSetup$prior$density(refPars$def[parSel])
bayesianSetup$likelihood$density(refPars$def[parSel])
bayesianSetup$posterior$density(refPars$def[parSel])
par(mfrow=c(1,1))
morrisOut <- morris(model = bayesianSetup$posterior$density, factors = rownames(refPars[parSel, ]), r = 2000, design = list(type = "oat", levels = 5, grid.jump = 3), binf = refPars$min[parSel], bsup = refPars$max[parSel], scale = TRUE)
plot(morrisOut)
print(morrisOut)
#Task 2.
sensitivityTarget <- function(par){
refPars$best[par] <- parSel
predicted <- PRELES(refPars$def[1:11], PAR)
return(mean(predicted[,2]))
}
result.best<-numeric(nrow(refPars))
for (i in 1:nrow(refPars)){
parSel<-refPars$best[i]
result.best[i]<-sensitivityTarget(i)
}
result.best