【问题标题】:Generating bivariate data where x variable is uniformly distributed between 0 and 1 and Y is normally distributed with mean 1/x with some noise生成双变量数据,其中 x 变量均匀分布在 0 和 1 之间,Y 正态分布,均值为 1/x,带有一些噪声
【发布时间】:2021-07-24 18:39:03
【问题描述】:

我使用 x

任何帮助将不胜感激。

【问题讨论】:

    标签: r statistics simulation


    【解决方案1】:

    如果你想要矩阵中的数据,那么你可以这样做

    x <- runif(100, 0, 1)
    y <- sapply(x, function(m) rnorm(10, 1/m, 1))
    

    这使用sapply 为每个x 值生成10 个正常值。

    如果你想要一个两列的矩阵,那么也许

    points <- do.call("rbind", lapply(x, function(m) cbind(x=m, y=rnorm(10, 1/m, 1))))
    

    是你想要的。你可以用

    plot(y~x, points)
    

    【讨论】:

      猜你喜欢
      • 2013-03-25
      • 2020-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多