用R进行灵敏度分析:我如何制作自己的情节

时间:2014-09-02 15:29:13

标签: r plot

您是否知道使用R?

进行自己的灵敏度分析结果图的方法

例如(使用fast99()和玩具模型):

> library(sensitivity)
> x <- fast99(model = ishigami.fun, factors = 3, n = 1000,
              q = "qunif", q.arg = list(min = -pi, max = pi))
> print(x)
> Call:
> fast99(model = ishigami.fun, factors = 3, n = 1000, q = "qunif",
         q.arg = list(min = -pi, max = pi))
> Model runs: 3000 
> Estimations of the indices:
>    first order     total order
> X1 3.076874e-01   0.5506015
> X2 4.419659e-01   0.4697538
> X3 3.431342e-29   0.2391275

我只想选择指数估算数据(X1X2X3),将它们放入矩阵中...... 有什么想法吗?

1 个答案:

答案 0 :(得分:2)

也许这样的事情可行。首先,帮助函数将fast99数据转换为data.frame

as.data.frame.fast99 <- function(x, ...) {
    if (!is.null(x$y)) {
        S <- data.frame(X=colnames(x$X), x$D1/x$V, 1 - x$Dt/x$V)
        colnames(S)[-1] <- c("first.order", "total.order")
        S
    }
}

现在我们绘制数据。 (这里我使用ggplot库,但您可以轻松使用其他库)

dd<-as.data.frame(x)
library(ggplot2)
ggplot(dd, aes(x=X)) + 
   geom_point(aes(y=first.order, color="first")) + 
   geom_point(aes(y=total.order, color="total")) + 
   scale_color_manual(values=c(first="red",total="blue"), name="order")

enter image description here