## 25 Reputation

8 years, 319 days

## The goal is to generate bivariate random...

restart;
with(Statistics);
randomize();
N := 100;
x__01 := Vector[row](P, [1 \$ N]);
x__02 := Vector[row](P, [1 \$ N]);
x__11 := Sample(Binomial(N, 0.4), N);
x__12 := Sample(Binomial(N, 0.4), N);
x__21 := Sample(Normal(0, 1), N);
x__22 := Sample(Normal(0, 1), N);
z__01 := Vector[row](P, [1 \$ N]);
z__02 := Vector[row](P, [1 \$ N]);
z__11 := Sample(Binomial(N, 0.4), N);
z__12 := Sample(Binomial(N, 0.4), N);
z__21 := Sample(Normal(0, 1), N);
z__22 := Sample(Normal(0, 1), N);
t := 1, 2;
aux1 := 1 +~ exp~(-((`*`~(gamma__01, z__01) +~ `*`~(gamma__11, z__11)) +~ `*`~(gamma__21, z__21)));
aux2 := 1 +~ exp~(-((`*`~(gamma__02, z__02) +~ `*`~(gamma__12, z__12)) +~ `*`~(gamma__22, z__22)));
phi__1 := `/`~(1, aux1);
phi__2 := `/`~(1, aux2);
lambda__1 := exp~(`*`~(beta__01, x__01) + `*`~(beta__11, x__11) + `*`~(beta__21, x__21)) *~ (1 +~ exp~((`*`~(gamma__01, z__01) +~ `*`~(gamma__11, z__11)) +~ `*`~(gamma__21, z__21)));
lambda__2 := exp~((`*`~(beta__02, x__02) +~ `*`~(beta__12, x__12)) +~ `*`~(beta__22, x__22)) *~ (1 +~ exp~((`*`~(gamma__02, z__02) +~ `*`~(gamma__12, z__12)) +~ `*`~(gamma__22, z__22)));
B := y -> [[phi__t +~ (1 - phi__t) *~ exp~(-lambda[1] - lambda[2]) *~ (1 +~ `*`~(alpha, 1 - exp~(-`*`~(1 - exp~(-1), lambda[1]))) *~ (1 - exp~(-(1 - exp~(-1))*lambda[2])))], [(1 - phi__t) *~ exp~(-lambda[1] - lambda[2]) *~ `*`~(lambda[1]^y[1], lambda[2]^y[2])/y[1]! *~ y[2]! *~ `+`~(1, alpha) *~ (exp~(-y[1]) - exp(-`*`~(1 - exp(-1), lambda[1])))*(exp(-y[2]) - exp(-`*`~(1 - exp(-1), lambda[2])))]];
B1 := Statistics:-Distribution(Type = discrete, ProbabilityFunction = B, Support = 0 .. infinity, DiscreteValueMap = (n -> n));
beta__01, beta__11, beta__21, beta__02, beta__12, beta__22, gamma__01, gamma__11, gamma__21, gamma__02, gamma__12, gamma__22, alpha := 0.2, -2, 0.25, 0.15, -2.5, 0.2, 0.1, 2, -2.5, 0.3, 1.3, 2.5, -2;
M := Matrix(100, 25, datatype = float[8]);
S := Statistics:-Sample(B1, M, method = [discrete, range = 0 .. 100]);

## Generating Discrete Random Numbers from ...

I am aware of the robustness of the Maple in generating randoms for simulation study.

I really appreciate the example of the zero-inflated Poisson given; I think ours should follow the approach but, I don’t know I to  do it especially when it is bivariate.

Please, I need help in generating discrete random numbers form my newly developed zero-inflated distribution defined in B:

#`### Generating Random Numbers from MBZIPR`

restart:

with(Statistics):

randomize():

N    := 100;

x__0 := Vector[row](P, [1\$N]);

x__1 := Sample(Binomial(N, 0.4), N);

x__2 := Sample(Normal(0, 1), N);

z__0 := Vector[row](P, [1\$N]);

z__1 := Sample(Binomial(N, 0.4), N);

z__2 := Sample(Normal(0, 1), N) ;

t:= (1, 2);

phi__1:= (1)/((1+exp(-(gamma__01 *z__01 +gamma__11*z__11 + gamma__21*z__21)))):

phi__2:=(1)/((1+exp(-(gamma__02 *z__02 +gamma__12*z__12 + gamma__22*z__22)))):

lambda__1:=exp(beta__01 *x__01 +beta__11*x__11 + beta__21*x__21)*(1+exp(gamma__01 *z__01 + gamma__11*z__11 + gamma__21*z__21)):

lambda__2:=exp(beta__02 *x__02 +beta__12*x__12 + beta__22*x__22)*(1+exp(gamma__02 *z__02 + gamma__12*z__12 + gamma__22*z__22)):

B:= (y[1],  y[2])->([[phi__t +(1-phi__t)*(exp(-lambda[1]- lambda[2])*(1+ alpha*(1-exp(-(1-(e)^()xp(-1))*lambda[1]))*(1-exp(-(1-exp(-1))*lambda[2])))),],[(1-phi__t)*(exp(-lambda[1]- lambda[2])*((lambda[1])^(y[1]) *  (lambda[2])^(y[2]))/(y[1]!* y[2]!)*((1+ alpha)*(exp(-y[1])-exp(-(1-exp(-1))*lambda[1]))*(exp(-y[2])-exp(-(1-exp(-1))*lambda[2])))),]]):

B1:= Statistics:-Distribution(       Type= discrete,        ProbabilityFunction= B,        Support= 0..infinity,        DiscreteValueMap= (n-> n)  ):  (beta__01,beta__11,beta__21,beta__02,beta__12,beta__22,gamma__01,gamma__11,gamma__21,gamma__02,gamma__12,gamma__22,phi,alpha):= (0.2,  -2,  0.25,  0.15,  -2.5,  0.2, 0.1,  2,  -2.5,  0.3,  1.3,  2.5,  0.5, -2) :  M:= Matrix((100, 25), datatype= float[8]);  S:=Statistics:-Sample(B1, M, method= [discrete, range= 0..100]);

Many thanks for the support.

## Thanks...

Really appreciate.

## Error, (in unapply)...

Thank you Prof,

I am very grateful for the supports.

In trying to run the other part I ran in to error

How do I apply the b-values correctly ?

 >
 (1)
 >
 (2)
 >
 (3)
 >
 (4)
 >
 (5)
 >
 >
 >
 (6)
 >
 >
 >
 >
 >

 (7)
 >

## Thank You...

Hi Prof,

X__B:= (x, y, z)-> exp(add(beta[k]*[x,y,z][k+1], k = 0 .. 2));

This returns the expeceted results.

I will now try and implement it in the simulation study.

Please, also, how do I write it as vector?

For example:

 seq( X__B(X__0, SX__1[k], SX__2[k]), k=1..N);

I copied the comand and the results from your post but the results are not listed in vector form; I mean not contain block brackets [ ]

Thank you.

## SECOND SCENARIO...

Thank you Prof,

The second scenario discribes by interests:

1. I want to sample random numbers for X_1 and X_2. Afterwards, I will export the sampled vectors and keep

2. I want to use the vectors to evaluate X_B (Yes! " the function X_B does not define a new random variable") but results from substituting X_0, X_1, and X_2.

3. These I think the command attached will sove. However, my attempt to run the copied command produced  " Error, invalid arrow procedure"

4. Please, help me correct it.

My regards.

 >
 (1)
 >
 (2)
 >
 >

## Re: Wrong /Incorrect Estimates...

Please, help me out on that problem.

## Wrong Estimates...

I discovered that when subtituting the values of X_0,  X_1 and X_2 generated to exp(0.25+0.6*_R -0.2_R0)

the results are different to what the computer generated.

For example:

From the results below;

X_0 = 1

X_1 =

X_2 =

Consequently,

But, when subtituted manually, I get different results as we can see below

1.  exp(.25+.6*1-.2*0.203855402371112)  =  2.246175
2,  exp(.25+.6*1-.2*-0.988718240271234e-1) = 2.386372

3.  exp(.25+.6*0-.2*-0.826980970419822e-1) = 1.305439

4.  exp(.25+.6*0-.2*-.168119128121408) =  1.327933

5. exp(.25+.6*0-.2*0.162021299867933) = 1.243084

Please, how do I make () use the values of  X_0,  X_1, and X_2 generated and return exact answers instead of it generating another ones?

 >
 >
 >
 >
 (1)
 >
 (2)
 >
 >
 >
 (3)
 >
 (4)
 >
 (5)
 >
 (6)
 >
 (7)
 >
 (8)
 >

 >
 >
 >
 >
 (1)
 >
 (2)
 >
 >
 >
 (3)
 >
 (4)
 >
 (5)
 >
 (6)
 >
 (7)
 >
 (8)
 >

## Code posted...

 Hello please,   Here is the code. The code is taking very long time to run and some times it stops working, maybe because of large numbers involve. Is there a way of making it work faster?    My regards

## Re: Program running slow...

Or is there  anything to be added to make it work faster ?

## Program running slow...

@mmcdara

Please help me check the programe as it is taken very long time to complete a process and at time stops wlthout completing the task.

Anything to be added to make run fast?

## Export to csv...

Wow!

This idea appears to be easier but still not working. Please check it.

resarts;

N: =50:

X_1 := RandomVariable(Bernoulli(1/2));

X_2 := RandomVariable(Normal(0,1));

ExportVector( "C:/Users/jamiu.olumoh/Desktop/testvecX1.csv", X_1, target=csv);

ExportVector( "C:/Users/jamiu.olumoh/Desktop/testvecX2.csv", X_2, target=csv);

## Thank You...

Many thanks. It works...

## Exporting as csv...

Now you understand my question.

I wish to export it directly as csv. Like exporting the matrix, the command below works well but not for the vector

"ExportMatrix("C:/Users/jami.olu/Documents/X1.csv", X__1, target = csv)"

 1 2 3 4 Page 1 of 4
﻿