数据点的随机、曲线分布

发布于 2024-10-08 01:44:57 字数 397 浏览 0 评论 0原文

背景

提供 R 编程示例。

问题

创建一个值的分布,在建模时产生一条类似于以下内容的曲线:

本质上,我想做类似的事情

x <- seq( 0, 2, by=0.01 )
y <- sin( 2 * pi * cos( x - 1/2 ) )
plot( x, y * runif( x ) )

: 0.5 左右的数据点簇:

问题

您将如何创建这样的分布?

谢谢你!

Background

Provide an example of R programming.

Problem

Create a distribution of values that, when modeled, produces a curve that resembles:

Essentially, I would like to do something like:

x <- seq( 0, 2, by=0.01 )
y <- sin( 2 * pi * cos( x - 1/2 ) )
plot( x, y * runif( x ) )

But without the clump of data points around 0.5:

Question

How would you create such a distribution?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我的奇迹 2024-10-15 01:44:57
slo<-0.5 #slope of underlying trend
sta<--0.5 #starting y value
amp<-0.2 #amplitude of sine wave
fre<-3 #frequency of sine wave
noi<-0.8 #amplitude of noise term
x<-seq(0,2,0.01)
y<-sta+(slo*x)+(amp*sin(fre*x)) #y no noise
ywnoise<-y+(noi*(runif(length(x))-0.5)) #y with noise

plot(x,ywnoise)
lines(x,y, col="orange")
grid()
slo<-0.5 #slope of underlying trend
sta<--0.5 #starting y value
amp<-0.2 #amplitude of sine wave
fre<-3 #frequency of sine wave
noi<-0.8 #amplitude of noise term
x<-seq(0,2,0.01)
y<-sta+(slo*x)+(amp*sin(fre*x)) #y no noise
ywnoise<-y+(noi*(runif(length(x))-0.5)) #y with noise

plot(x,ywnoise)
lines(x,y, col="orange")
grid()
暖风昔人 2024-10-15 01:44:57

嗯...我不确定您的分布是否需要任何特定的统计属性,但是这样的东西可以消除团块

plot(x,y+rnorm(length(x), 0, 0.2))

Hmmm... I'm not sure if you need any specific statistical property for your distribution, but something like this gets rid of the clump

plot(x,y+rnorm(length(x), 0, 0.2))
↙温凉少女 2024-10-15 01:44:57

由于 sin(2*pi*cos(x-0.5)) 在 0.5 处为零,因此您应该尝试添加 runif()

x <- seq( 0, 2, by=0.01 )
y <- sin( 2 * pi * cos( x - 1/2 ) ) +runif(201)
plot( x,y  )
lines(loess(y~x)$x, lowess(y~x)$y)

Since sin(2*pi*cos(x-0.5)) goes to zero at 0.5 you should try just adding runif()

x <- seq( 0, 2, by=0.01 )
y <- sin( 2 * pi * cos( x - 1/2 ) ) +runif(201)
plot( x,y  )
lines(loess(y~x)$x, lowess(y~x)$y)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文