开发者

Random, curvy distribution of data points

Background

Provide an example of R programming.

Problem

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

Random, curvy distribution of data points

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:

Random, curvy distribution of data points

Question

How would you create such a distribution?

T开发者_开发问答hank you!


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()


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))


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜