#include <oxstd.h>
#import <simula>

/*----------------- 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(const iRep, const cT, const mxT);
                                       // generate replication
    GetCoefficients();            // return coefficient values
    GetPvalues();                  // return p-values of tests
    GetTestStatistics();             // return test statistics
	IsTwoSided();
};
SimNormal::SimNormal()
{
    Simulation(<50>, 100, 1000, TRUE, -1,
        <0.2,0.1,0.05,0.01>,        // p-values to investigate
        <0,1>);                    // true coefs: mean=0, sd=1
    SetTestNames({"t-value"});
    SetCoefNames({"constant", "std.dev"});
}
SimNormal::IsTwoSided()
{
	return <1>;
}
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
}
