【问题标题】:Simulation with Kernel Density Estimate on R在 R 上使用核密度估计进行模拟
【发布时间】:2017-10-14 14:14:28
【问题描述】:

我试图基于 R 上的内核分布进行模拟。使用的数据集 - HSAUR2 包上的 CYG OB1。我使用数据集进行了分析以找到核密度估计值。我正在寻找使用这个核密度来模拟双变量值。目前使用的代码

> CYGOB1d <- bkde2D(CYGOB1, bandwidth = sapply(CYGOB1, dpik))
> plot(CYGOB1, xlab = "log surface temperature", ylab = "log light intensity")
> contour(x = CYGOB1d$x1, y=CYGOB1d$x2, z=CYGOB1d$fhat, add = TRUE)
> persp(x=CYGOB1d$x1, y=CYGOB1d$x2, z = CYGOB1d$fhat, xlab = "log surface 
  temperature", ylab = "log light intensity", zlab ="density")

如何根据内核密度进行模拟(1000 次运行)?

【问题讨论】:

    标签: r simulation kernel-density


    【解决方案1】:

    如果z 是你的随机变量,你可以使用

    d <- density(z,n=512) 
    #n is the number of points used for the curve, should be a power of two (512 is default) 
    
    sample(x = d$x,prob = d$y,size=1000,replace=TRUE) 
    #samples from the n values of x, according to prob y (the density)
    

    请参阅?density,了解它如何进行计算的各种其他选项。

    【讨论】:

      【解决方案2】:

      感谢您的回答。 我尝试使用上面的代码,得到的解决方案如下(附图片):

      simulation results

      虽然数据是二元数据如下:

            logst logli
      [1,]   4.37  5.23
      [2,]   4.56  5.74
      [3,]   4.26  4.93
      [4,]   4.56  5.74
      [5,]   4.30  5.19
      [6,]   4.46  5.46
      [7,]   3.84  4.65
      [8,]   4.57  5.27
      [9,]   4.26  5.57
      [10,]  4.37  5.12
      

      我希望模拟结果能给我一对相似的数字。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-02-03
        • 2021-01-25
        • 2018-01-23
        • 2021-01-21
        • 1970-01-01
        • 2021-05-01
        • 2019-02-13
        • 2013-11-07
        相关资源
        最近更新 更多