Random, curved distribution of data points

Background

Provide an example of programming R.

Problem

Create a value distribution that, when simulated, creates a curve that resembles:

BEFXK.png

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 a set of data points around 0.5:

Fbamx.png

Question

How would you create such a distribution?

Thank!

+3
source share
3 answers
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()
+3
source

Hmmm ... I'm not sure if you need any specific statistical property for your distribution, but something like this eliminates lumps

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

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

Source: https://habr.com/ru/post/1781153/


All Articles