0

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.

    Additive_RNG<-function(a,z0,c,m,n,p)
  {
    {
      a = readline("Input Value a: ")
      z0 = readline("Input Value z0: ")
      c = readline("Input Value c: ")
      m = readline("Input Value m: ")
      n = readline("Input Value n: ")
      p = readline("Input Value 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)  #create value in 1st column (Zi = aZ0+c)
    xi[i,2]<-xi[i,1]%%m #create value in 2nd kedua Zi*mod
    xi[i,3]<-xi[i,2]/m #ceate uniform value in 3th column
    z0<-xi[i,2] #z0 would be replace until looping
  }
  hist(xi[,3])
  {
    p<-p
    X<-matrix()
      for (i in 1:nrow(xi))
      {
      X[[i]]<- runif(xi[i,2])
      }
    Y<-(X<=p)+0
    (tabel<-table(Y)/length(Y))
  }
}
Additive_RNG(a,z0,c,m,n,p)

The error I get when run the script:

Error in X[[i]] <- runif(xi[i, 2]) : 
  more elements supplied than there are to replace

So I want the output with 2 formula on 1 function syntax, to get probability 0 and 1 and count it from data "Xi" to Uniform like the pictures.

example expected output: example expected output

  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 15 '23 at 22:07

0 Answers0