【问题标题】:Plotting influence of 2 variables on output绘制 2 个变量对输出的影响
【发布时间】:2016-03-22 17:59:42
【问题描述】:

各位善良聪明的网友们,

我一直在从各个角度玩弄R,但似乎进展甚微。这可能是基本的,但我的思想和经验更是如此......

我最终想在方程中绘制出不同的 m 和 n 对输出 (b) 的影响:

b=(0.15m+0.15n)/n。其中 m 和 n 的范围为 -1 到 1。

我设想了一个等高线图来可视化这一点,但我被困在通过相应的 m 和 n 输入获取 b 值的步骤。

最新的方法涉及对 m 和 n 进行引导估计以返回 b 值,但据我所知,没有办法获得相应的输入 m 和 n 值:

m<-seq(from=-1,1,length.out=100)  
n<-seq(from=-1,1,length.out=100)  
z<-rnorm(100)   
b<-((0.15*(sample(m,1,replace=T))+0.15*(sample(n,1,replace=T)))/(sample(n,1,replace=T))) 

library("boot")  
bfunc<-function(m,n){  
  (0.15*(sample(m,1,replace=T))+0.15*(sample(n,1,replace=T)))/(sample(n,1,replace=T))  
}  
bootb<-boot(data=z,statistic=(bfunc),R=1000)  
bootb$t 

我的问题:如何获得输出 (b) 和相应的输入 (m 和 n),以便绘制数据?上述修改或完全不同的方式都欢迎...我需要学习!

非常感谢任何帮助,谢谢。

【问题讨论】:

    标签: r function plot contour statistics-bootstrap


    【解决方案1】:

    我不明白你为什么需要引导程序

    dataset <- expand.grid(
      m = seq(-1, 1, length.out = 101),
      n = seq(-1, 1, length.out = 101)
    )
    dataset$b <- (0.15 * dataset$m + 0.15 * dataset$n) / dataset$n
    
    library(ggplot2)
    ggplot(dataset, aes(x = m, y = n, z = b)) + 
      geom_contour(aes(colour = ..level..)) + 
      scale_colour_gradient2()
    ggplot(dataset, aes(x = m, y = n, fill = b)) + 
      geom_tile() + 
      scale_fill_gradient2()
    

    【讨论】:

    • 非常感谢蒂埃里。这非常有效,也感谢您提供有关绘图的提示。
    猜你喜欢
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-30
    • 2016-12-21
    • 2022-07-08
    • 1970-01-01
    相关资源
    最近更新 更多