Skip to content

Commit a3fa6d1

Browse files
author
nguyenta
committed
add option extract output that was not used for calibration, by assigning all observed data of that variable as NA
1 parent cf3db50 commit a3fa6d1

File tree

4 files changed

+71
-37
lines changed

4 files changed

+71
-37
lines changed

R/displayOutput.R

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -214,24 +214,43 @@ printVariableNameObservedFiles <- function(outputExtraction){
214214
plotSimulated <- function(inputDataFrame){
215215
inputDataFrame$date <- as.Date(inputDataFrame$date, "%Y-%m-%d")
216216

217-
myplot <- ggplot(inputDataFrame) +
218-
#95 PPU
219-
geom_ribbon(aes(x = date, ymin = lower, ymax = upper, color = "95PPU"),
220-
size = 0.0, fill = "red", alpha = 0.3) +
221-
# Best simulation
222-
geom_line(aes(x = date, y = best, color = "Best simulation"), alpha = 0.6) +
223-
# Observed data
224-
geom_line(aes(x = date, y = median, color = "Median"), alpha = 0.6) +
225-
# Observed data
226-
geom_line(aes(x = date, y = observed, color = "Observed"), alpha = 0.6) +
227-
scale_colour_manual(name= '', values=c("95PPU" = "red",
228-
"Best simulation" = "red",
229-
"Median" = "green",
230-
"Observed" = "darkblue")) +
231-
# Axis name
232-
labs(x =" ", y = " ") +
233-
scale_x_date(date_labels = "%m-%Y") +
234-
theme_bw()
217+
if(length(which(is.na(inputDataFrame$observed))) == nrow(inputDataFrame)){
218+
myplot <- ggplot(inputDataFrame) +
219+
#95 PPU
220+
geom_ribbon(aes(x = date, ymin = lower, ymax = upper, color = "95PPU"),
221+
size = 0.0, fill = "red", alpha = 0.3) +
222+
# Best simulation
223+
geom_line(aes(x = date, y = best, color = "Best simulation"), alpha = 0.6) +
224+
# Observed data
225+
geom_line(aes(x = date, y = median, color = "Median"), alpha = 0.6) +
226+
scale_colour_manual(name= '', values=c("95PPU" = "red",
227+
"Best simulation" = "red",
228+
"Median" = "green")) +
229+
# Axis name
230+
labs(x =" ", y = " ") +
231+
scale_x_date(date_labels = "%m-%Y") +
232+
theme_bw()
233+
} else {
234+
myplot <- ggplot(inputDataFrame) +
235+
#95 PPU
236+
geom_ribbon(aes(x = date, ymin = lower, ymax = upper, color = "95PPU"),
237+
size = 0.0, fill = "red", alpha = 0.3) +
238+
# Best simulation
239+
geom_line(aes(x = date, y = best, color = "Best simulation"), alpha = 0.6) +
240+
# Observed data
241+
geom_line(aes(x = date, y = median, color = "Median"), alpha = 0.6) +
242+
# Observed data
243+
geom_line(aes(x = date, y = observed, color = "Observed"), alpha = 0.6) +
244+
scale_colour_manual(name= '', values=c("95PPU" = "red",
245+
"Best simulation" = "red",
246+
"Median" = "green",
247+
"Observed" = "darkblue")) +
248+
# Axis name
249+
labs(x =" ", y = " ") +
250+
scale_x_date(date_labels = "%m-%Y") +
251+
theme_bw()
252+
}
253+
235254
return(myplot)
236255
}
237256

R/postProcessing.R

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ behaSimulation <- function(objValue, simData, parameterValue, behThreshold,
3232
ppuSimData <- matrix(rep(NA, 4*nrow), ncol = 4)
3333

3434
if (samplingApproach == 'Cali_(Generalized_Likelihood_Uncertainty_Estimation)'){
35-
# If GLUE then use different approach
36-
# Normalized the likelikhood
35+
36+
# If GLUE then use different approach, normalized the likelikhood
3737
normalizedLik <- which(objValue >= behThreshold)
3838
normalizedLik <- normalizedLik/sum(normalizedLik)
3939
for (i in 1:nrow){
@@ -104,30 +104,38 @@ behaSimulation <- function(objValue, simData, parameterValue, behThreshold,
104104
prFactor <- function(obs, low, up){
105105

106106
naIndex <- which(is.na(obs))
107+
107108
if (length(naIndex) > 0){
108109
obs <- obs[-c(naIndex)]
109110
low <- low[-c(naIndex)]
110111
up <- up[-c(naIndex)]
111112
}
112113

113-
pfactor <- 0
114-
count <- 0
115-
count_all <- 0
116-
rfactor <- 0
117-
118-
for (i in 1:length(obs)){
119-
count_all <- count_all + 1
120-
rfactor <- rfactor + up[i] - low[i]
121-
if(obs[i] >= low[i]){
122-
if(obs[i] <= up[i]){
123-
count <- count + 1
114+
#If all no single value in the observed data
115+
if (length(obs) == 0){
116+
pfactor <- NA
117+
rfactor <- NA
118+
119+
} else {
120+
pfactor <- 0
121+
count <- 0
122+
count_all <- 0
123+
rfactor <- 0
124+
125+
for (i in 1:length(obs)){
126+
count_all <- count_all + 1
127+
rfactor <- rfactor + up[i] - low[i]
128+
if(obs[i] >= low[i]){
129+
if(obs[i] <= up[i]){
130+
count <- count + 1
131+
}
124132
}
125133
}
134+
135+
pfactor <- count/count_all
136+
rfactor <- rfactor/(count_all * sd(obs))
126137
}
127138

128-
pfactor = count/count_all
129-
rfactor <- rfactor/(count_all * sd(obs))
130-
131139
return(c(pfactor, rfactor))
132140
}
133141

@@ -233,7 +241,11 @@ calObjFunction <- function(parameterValue, ncores,
233241
simData[[j]][[counter[j]]] <- tempSimData[(sIndex + 1):eIndex, 1]
234242
output$simData[[j]][[counter[j]]] <- simData[[j]][[counter[j]]]
235243

236-
if (index != 'userObjFunction'){
244+
# check if observed variables has no data, all are missing
245+
missingValue <- which(is.na(observedData[[j]][,2]))
246+
247+
if ((index != 'userObjFunction') &
248+
(length(missingValue) != length(observedData[[j]][,2]))){
237249

238250
output$perCriteria[[j]][[counter[j]]] <- perCriteria(observedData[[j]][,2],
239251
simData[[j]][[counter[j]]])

data/parameter_range.csv

-166 Bytes
Binary file not shown.

server.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,11 +1228,14 @@ print(sensCaliObject)[]")
12281228

12291229
} else {
12301230

1231-
if (is.numeric(temp$V2)){
1231+
if (is.numeric(temp$V2) |
1232+
length(which(is.na(temp$V2))) == length(temp$V2)){
1233+
12321234
globalVariable$observedData[[i]] <<- temp
12331235
colnames(globalVariable$observedData[[i]]) <<- c("Date", "Value")
12341236

12351237
} else {
1238+
12361239
checkGetObservedDataFileMessage <- paste("Error: Data in the second column are not numeric values: ",
12371240
globalVariable$observedDataFile[i],
12381241
sep = "")
@@ -1596,7 +1599,7 @@ print(sensCaliObject)[]")
15961599
# Give column names for the 95PPU table
15971600
colnames(tempVar) <- c("date", "lower", "median", "upper", "best", "observed")
15981601
globalVariable$PlotVariableNumber <<- plotSimulated(tempVar)
1599-
1602+
16001603
# Plot the 95PPU
16011604
output$PlotVariableNumber <- renderPlotly(
16021605
ggplotly(globalVariable$PlotVariableNumber +

0 commit comments

Comments
 (0)