0
使用以下data.frames
R:轉換試驗和錯誤校正自動化
#df is data.frame to be used to get the simulated values
df <- read.csv(url("https://www.dropbox.com/s/j1jyrxlinyql0d8/df_simu2.csv?raw=1"))
head(df)
# ID loss area param1 param2
#1 well5 8.62 0.3430550 High High
#2 well5 8.62 0.1643353 High High
#3 well5 8.62 4.2321602 High High
#4 well5 8.62 0.0349235 Medium High
#5 well5 8.62 0.0648697 Medium High
#6 well5 8.62 0.0444421 Medium High
#df_measured is the data.frame that have the measured values to be compared with the simulated values later
df_measured <- read.csv(url("https://www.dropbox.com/s/77v6ysdi1ziqq6i/df_measured.csv?raw=1"))
head(df_measured)
# ID measured
#1 well1 29.7513
#2 well2 21.7710
#3 well3 191.6334
#4 well4 260.2431
#5 well5 532.3491
這個代碼來獲取模擬值,並將其與實測值
library(dplyr)
df_simulated <- df %>%
dplyr::mutate(loss1 = loss/1e3, #convert the units
param1_no = ifelse(param1 == "High", 0.7, #convert param1 values to numbers
ifelse(param1 == "Medium", 0.5,
ifelse(param1 == "Low", 0.3, NA))),
param2_no = ifelse(param2 == "High", 0.9, #convert param2 values to numbers
ifelse(param2 == "Medium", 0.5,
ifelse(param2 == "Low", 0.3, NA)))) %>%
dplyr::group_by(ID) %>%
dplyr::summarise(simulated = sum(loss1 * area * (1- param1_no) * (1 - param2_no), na.rm =T)) %>%
#merge it with df_measured to comapre simulated with measured
dplyr::full_join(., df_measured, by = "ID") %>%
dplyr::select(ID, simulated, measured)
我得到這個結果比較
#df_simulated
# A tibble: 5 × 3
# ID simulated measured
# <fctr> <dbl> <dbl>
#1 well1 115.90577 29.7513
#2 well2 31.68084 21.7710
#3 well3 299.77588 191.6334
#4 well4 387.15474 260.2431
#5 well5 519.88316 532.3491
該simulated
值不接近除well5
以外的值爲。 爲了儘可能接近得到simulated
值到measured
,我需要改變值的param1_no
水平和param2_no
對於這兩種param1_no
和「param2_no」
high
可以從改變0.67〜0.99medium
可以從0.34變化到0.66low
可以變化從0.01到0.33
在校準過程中,我可以不斷更改這些值「試錯」,直到我的simulated
值儘可能接近measured
。
但是,手動執行此操作需要時間。 我會高度讚賞,如果您可以建議任何更快的方法來獲得param1_no
和param2_no
(high
,medium
和low
)的最佳值,使模擬值更接近測量值。
感謝您的時間和幫助。我還沒有檢查過它。 – aelwan
任何改善標題的建議? – aelwan