是否可以进行敏感性分析

时间:2019-06-25 09:10:26

标签: r

对数变换后,我从功率模型中获得了以下方程式。

 logy = 3.651 + 0.648*logind1 + 0.915*logind2

我想进行敏感性分析并创建图表 其中x轴是第一个自变量(ind1), y轴是y,我想绘制第二个独立值的不同曲率 喜欢下面的照片。

绘图上的值不应为对数刻度。

我不确定R是否可以用于此目的。

这是我的原始值数据:

df <- data.frame(y, ind1, Ind2)
dput(head(df))

 structure(list(y = c(17.5460928, 15.09292512, 404.6266803, 509.8268418, 
 22.29624608, 27.62826976), ind1 = c(0.003739281, 0.003473227, 
 0.096486361, 0.124097819, 0.005281017, 0.005089576), Ind2 = c(0.20708766, 
 0.216378894, 0.628712871, 0.505681818, 0.318622945, 0.245192308
 )), row.names = c(NA, 6L), class = "data.frame")

非常感谢您!

1 个答案:

答案 0 :(得分:0)

您有这样的想法吗?

# Vector of values over which to perform the analysis.
vec.pars <- c(0.1, 0.3, 0.6)

# The function for calculating Y.
calcY <- function(x, ind1) {
  3.651 + 0.648 * ind1 + 0.915 * x
}
# Vectorized version. This enables us to apply the above function
# to a vector of values at the same time.
calcY <- Vectorize(FUN = calcY, vectorize.args = "x", SIMPLIFY = FALSE)

# Construct the output
vec.y <- calcY(x = vec.pars, ind1 = df$ind1)
xy <- data.frame(y = do.call(c, vec.y))
xy$ind1 <- rep(df$ind1, times = length(vec.y))
xy$ind2 <- rep(vec.pars, each = nrow(df))

ggplot(xy, aes(x = ind1, y = y, color = as.factor(ind2))) +
  theme_bw() +
  geom_line()

enter image description here