The first I was create RNG with Additive then using the column 2 for the next get Bernoulli probability with "Xi" Value to Runif it.
#Create RNG with Additive
Additive_RNG<-function(a,z0,c,m,n,p) {
{
a = readline("Masukkan Nilai a: ")
z0 = readline("Masukkan Nilai z0: ")
c = readline("Masukkan Nilai c: ")
m = readline("Masukkan Nilai m: ")
n = readline("Masukkan Nilai n: ")
p = readline("Masukkan Nilai p: ")
}
{
a = as.integer(a)
z0 = as.integer(z0)
c = as.integer(c)
m = as.integer(m)
n = as.integer(n)
p = as.integer(p)
}
xi<-matrix(NA,n,3)
colnames(xi)<-c("aZ(i-1)+c","Xi","Ui")
for (i in 1:n)
{
xi[i,1]<-(a*z0+c) #membuat nilai pada kolom petama (Zi = aZ0+c)
xi[i,2]<-xi[i,1]%%m #mmembuat nilai kolom kedua Zi*mod
xi[i,3]<-xi[i,2]/m #membuat nilai uniform pada kolom ketiga
z0<-xi[i,2] #z0 akan ke replace sampai perulangan berikutnya
}
#Generate probability of Bernoulli
{
p<-p
tes<-matrix(NA,n,2)
colnames(tes)<-c("X","Y")
for (k in 1:n)
{
tes[k,1]<- runif(xi[i,2])
tes[k,2]<- (X<=p)+0
(tabel<-table(tes[k,2])/length(tes[k,2]))
}
}
}
Additive_RNG(a,z0,c,m,n,p)
So I want the ouput have a probability 0 and 1 from data "Xi" to Uniform like the pictures.
Aucun commentaire:
Enregistrer un commentaire