zhuangwei的个人博客分享 http://blog.sciencenet.cn/u/zhuangwei

博文

R中multisensi和sensitivity 全局敏感性分析的运行代码示例

已有 7953 次阅读 2019-3-4 10:17 |个人分类:R|系统分类:科研笔记


全局敏感性分析(Global Sensitivity Analysis)的例子见:

https://cran.r-project.org/web/packages/multisensi/vignettes/multisensi-vignette.pdf


附上一个来自multisensi包的全局敏感性分析的例子:
使用的数据和模型函数是来自multisensi,使用的敏感性分析的fast99来自sensitivity.
以下为code:
# The analysis.sensitivity function runs a series of sensitivity analyses on the columns of a data.frame, # using a method implemented in the sensitivity package. 
library(multisensi)
library(sensitivity) # to use fast99

# Test case : the Winter Wheat Dynamic Models (WWDM)
# input factors design
data(biomasseX)
x_bio <- biomasseX[1,]
x_bio
#  Eb Eimax   K  Lmax      A      B  TI
#    1 0.9   0.9  0.6    3 0.0035 0.0011 700

# input climate variable
data(Climat)

# example of the sensitivity:fast99 function
# design
newplan <- fast99(model = NULL, factors = names(x_bio), n = 100, 
                  q = "qunif", q.arg = list(list(min = 0.9, max = 2.8),
                                            list(min = 0.9, max = 0.99),
                                            list(min = 0.6, max = 0.8),
                                            list(min = 3, max = 12),
                                            list(min = 0.0035, max = 0.01),
                                            list(min = 0.0011, max = 0.0025),
                                            list(min = 700, max = 1100)))
# simulations
wwdm.Y <- simulmodel(model=biomasse, plan=newplan$X, climdata=Climat)

# analysis
res <- analysis.sensitivity(data.frame(wwdm.Y), plan=newplan, nbcomp=4)
# res <- analysis.sensitivity(data.frame(wwdm.Y), plan=newplan, nbcomp=1) # will return one columes
res$mSI # data.frame of first-order sensitivity indices

               X1          X2          X3          X4

Eb    0.075290428 0.075579758 0.075645517 0.075703969

Eimax 0.001148371 0.001153867 0.001155115 0.001156226

K     0.009093113 0.009127925 0.009135830 0.009142854

Lmax  0.089429698 0.089718795 0.089784514 0.089842880

A     0.938351687 0.938005022 0.937925949 0.937855715

B     0.028646974 0.028464774 0.028423429 0.028386880

TI    0.737518813 0.740368544 0.741009499 0.741578687

res$tSI # data.frame of total sensitivity indices

               X1          X2          X3          X4

Eb    0.150753136 0.151013794 0.151073045 0.151125715

Eimax 0.003121204 0.003136433 0.003139897 0.003142966

K     0.016806218 0.016842989 0.016851346 0.016858759

Lmax  0.187725641 0.187828012 0.187851321 0.187871978

A     0.981490405 0.981359799 0.981330034 0.981303589

B     0.061834920 0.061455156 0.061368985 0.061292802

TI    0.782582899 0.785237186 0.785835776 0.786367488

### show the model
biomasse
# not run
function (input, climdata, annee = 3) 
{
  if (class(input) == "numeric") {
    input <- as.data.frame(as.list(input))
  }
  Eb <- input[1, 1]
  Eimax <- input[1, 2]
  K <- input[1, 3]
  Lmax <- input[1, 4]
  A <- input[1, 5]
  B <- input[1, 6]
  TI <- input[1, 7]
  if (is.null(annee)) {
    annee <- input[1, 8]
  }
  PAR <- 0.5 * 0.01 * climdata$RG[climdata$ANNEE == annee]
  Tmoy <- (climdata$Tmin[climdata$ANNEE == annee] + climdata$Tmax[climdata$ANNEE == 
                                                                    annee])/2
  Tmoy[Tmoy < 0] <- 0
  ST <- Tmoy
  for (i in (2:length(Tmoy))) {
    ST[i] <- ST[i - 1] + Tmoy[i]
  }
  Tr <- (1/B) * log(1 + exp(A * TI))
  LAI <- Lmax * ((1/(1 + exp(-A * (ST - TI)))) - exp(B * (ST - 
                                                            (Tr))))
  LAI[LAI < 0] <- 0
  U <- Eb * Eimax * (1 - exp(-K * LAI)) * PAR
  BIOMASSE <- sum(U)
  U <- cumsum(U)
  U
}




https://wap.sciencenet.cn/blog-526092-1165534.html

上一篇:黄土高原历史时期森林面积的变化
下一篇:[转载]如何在jupyterlab 中运行R (windows)效果可肩比RSTUDIO
收藏 IP: 14.157.173.*| 热度|

1 杨伟伟

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-19 11:49

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部