gpt4 book ai didi

r - 绘制随机性

转载 作者:行者123 更新时间:2023-12-04 06:24:32 25 4
gpt4 key购买 nike

我正在寻求帮助,以从 R 中的一系列 1 和 0 生成此图。我将其用作一系列测试之一,以调查序列是否是随机的(通过寻找噪声中的模式)。
注意:这不是作业!

例如。,

> y <- rnorm(3000, 1, 2)
> plot(y)
>plot(y~y)

我的数据是这种形式:
 >str(hv10k)
num [1:100000] 0 1 1 1 0 0 1 0 0 0 ...

rand1

更新:

遵循@Roman Luštrik 的建议,这是我目前所得到的:

大约 700 次抛硬币:

700 approx coin toss

100,000 次抛硬币:

100,000 coin toss

最佳答案

一种方法是

side <- 100
my.zero <- matrix(sample(c(0,1), side^2, replace = TRUE), side)
image(my.zero)

编辑

你可以玩 prob参数在 sample .
side <- 100
my.zero <- matrix(sample(c(0,1), side^2, replace = TRUE, prob = c(0.8, 2)), side)
image(my.zero)

编辑 2
y <- rnorm(10000, 1, 2)
y <- matrix(ifelse(y > 0, 1, 0), ncol = 100)
image(y, col = c("white", "black"))

enter image description here

关于r - 绘制随机性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6198157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com