cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Raaed
Level IV

simulation experiment

I want to make a simulation experiment, generate 12 random variables, each variable contains 100 observations, so that the variables are subject to heterogeneity problem, and follow the normal distribution
The experiment is repeated 10,000 times.

 

# I don't know how to do this with JMPpro

 

Thanks

Řaëd ~✍
7 REPLIES 7
Craige_Hales
Super User

Re: simulation experiment

I don't know what the heterogeneity problem is, but the rest might look like this:

 

dt = As Table( J( 100 * 10000, 12, Random Normal( 0, 1 ) ) );
dt << New Column( "group", formula( Floor( (Row() - 1) / 100 ) + 1 ) );
dt << runformulas;
dt:group << deleteformula;
dt << Go To( group );
dt << Move Selected Columns( To first );

 

Do your analysis with the group variable.

 

12 million random normal numbers12 million random normal numbers

Craige
Craige_Hales
Super User

Re: simulation experiment

Summary might be a good start

dt = As Table( J( 100 * 10000, 12, Random Normal( 0, 1 ) ) );
dt << New Column( "group", formula( Floor( (Row() - 1) / 100 ) + 1 ) );
dt << runformulas;
dt:group << deleteformula;
dt << Go To( group );
dt << Move Selected Columns( To first );

dtsummary = dt << Summary(
    Group( :group ),
    Mean( :Col1 ),
    Min( :Col1 ),
    Max( :Col1 ),
    Std Dev( :Col1 ),
    Mean( :Col2 ),
    Min( :Col2 ),
    Max( :Col2 ),
    Std Dev( :Col2 ),
    Freq( "None" ),
    Weight( "None" )
);

dtsummary << Graph Builder(
    Size( 653, 452 ),
    Show Control Panel( 0 ),
    Variables(
        X( :group ),
        Y( :"Mean(Col1)"n ),
        Y( :"Min(Col1)"n, Position( 1 ) ),
        Y( :"Max(Col1)"n, Position( 1 ) ),
        Y( :"Std Dev(Col1)"n, Position( 1 ) ),
        Y( :"Mean(Col2)"n, Position( 1 ) ),
        Y( :"Min(Col2)"n, Position( 1 ) ),
        Y( :"Max(Col2)"n, Position( 1 ) ),
        Y( :"Std Dev(Col2)"n, Position( 1 ) )
    ),
    Elements(
        Points(
            X,
            Y( 1 ),
            Y( 2 ),
            Y( 3 ),
            Y( 4 ),
            Y( 5 ),
            Y( 6 ),
            Y( 7 ),
            Y( 8 ),
            Legend( 7 )
        )
    )
);

Color!Color!

Craige
Raaed
Level IV

Re: simulation experiment

Dear Sir Craige_Hales

 

Thank you very much for helping me,

 

I wanted to do a simulation experiment:
Number of random variables = 12
The number of observations in each variable = 100
And that resulting variables are suffering from Heteroscedasticity problem

# With possibility of repeating the experiment 10,000 times

Řaëd ~✍
Raaed
Level IV

Re: simulation experiment

Craige_Hales
Super User

Re: simulation experiment

check out a search like this https://www.google.com/search?q=site%3Ajmp.com+Heteroscedasticity  to find previous questions that might have good answers in the community. In the google search GUI you can do that with site:jmp.com to limit the results:

 

site:jmp.com Heteroscedasticitysite:jmp.com Heteroscedasticity

 

I'm not a statistician. The data above is random. The source you point at suggests the data should have some sort of repeat across seasons...not completely random. If 1..12 represents months of the year, it might not make sense to have a January column, a February column, ...   It might make a lot more sense to have a date column and a value column.

date value
2020/01 7
2020/02 6
2020/03 8

 

I looked up Heteroscedasticity and suspect you'll need a different approach to generating your random numbers so they actually exhibit that trait. Otherwise it is just random with nothing interesting but the mu and sigma passed to random normal, as seen in the graph above.

 

Just guessing, and way out on a limb...I think you'd have to generate a random mu (normal? uniform?), and a sigma based on that mu, and then use RandomNormal(mu,sigma). Or I might be completely wrong.

Craige
Raaed
Level IV

Re: simulation experiment

Dear Sir

First, thank you very much for helping.

In fact, your script above, comes close to what I want,
but I don't know how to make the variables heterogeneous in variance.
I don't know how to modify your script, such that:

Number of random variables = 12
The number of observations in each variable = 100
And that resulting variables are suffering from Heteroscedasticity problem

With possibility of repeating the experiment 10,000 times

 

Regards

Řaëd ~✍
Craige_Hales
Super User

Re: simulation experiment

"how to make the variables heterogeneous in variance" - does that mean each column needs a different sigma? Do you need 12 randomly chosen sigma values?

 

"Heteroscedasticity problem" - does that mean you have a function in mind for changing the sigma based on mu? And a function for choosing mu, probably randomly? (I don't have any expertise here, just guessing after a 30 second read.)

 

I think you'll want to do this using nested for loops. My original suggestion is too simple. You could also use column formulas, but a JSL script will be easier to manage. Nested loops would look something like this

m = J( 100 * 10000, 12, 0 );

for(row=1, row<=nrows(m), row+=1,
   for(col=1, col<=ncols(m), col+=1,
        m[row,col] = HSD(row,col);
    );
);

dt = astable(m)

...

You have to write the "HSD" user written function with what you actually want.

 

You might also want to change the 10000 repeats to 2 or 3 repeats until you decide what the analysis should do. I used summary because it packs all 10K analyses into a data table. You might want to run a platform 10K times, grabbing some results, then closing the platform. You don't want 10K platforms open at once because JMP will run out of memory.

 

Craige