#include <oxstd.h>
#import <simula>      // import simulation header and code

/*--------------- SimNormal : Simulation ---------------*/
class SimNormal : Simulation    // inherit from simulation
{
    decl m_mCoef;                           // coefficient
    decl m_mTest;                        // test statistic
    decl m_mPval;                     // p-value of t-test

    SimNormal();                            // constructor
      // Generate() replaces the virtual function with the
   // same name of the base class to generate replications
    Generate(const iRep, const cT, const mxT);
                   //these also replace virtual functions:
    GetCoefficients();        // return coefficient values
    GetPvalues();              // return p-values of tests
    GetTestStatistics();         // return test statistics
};
SimNormal::SimNormal()               // define constructor
{
    Simulation(<50>, 50, 1000, TRUE, ranseed(-1),
        <0.2,0.1,0.05,0.01>,    // p-values to investigate
        <0,1>);                // true coefs: mean=0, sd=1
    SetTestNames({"t-value"});          // set names
    SetCoefNames({"constant", "std.dev"});
}
SimNormal::Generate(const iRep, const cT, const mxT)
{
    decl my, sdevy, meany;

    my = rann(cT, 1);                     // generate data

    meany = meanc(my);                        // mean of y
    sdevy = sqrt(cT * varc(my) / (cT-1));  // std.dev of y

    m_mCoef = meany | sdevy;             // mean,sdev of y
    m_mTest = meany / (sdevy / sqrt(cT));//t-value on mean
    m_mPval = tailt(m_mTest, cT-1);  // t(T-1) distributed

return 1;
}
SimNormal::GetCoefficients()
{
    return m_mCoef;
}
SimNormal::GetPvalues()
{
    return m_mPval;
}
SimNormal::GetTestStatistics()
{
    return m_mTest;
}
/*------------ END SimNormal : Simulation --------------*/

main()
{
    decl experiment = new SimNormal();    // create object

    experiment.Simulate();               // do simulations

    delete experiment;                    // remove object
}
