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

class Ols : Modelbase
{
    decl m_mRes;
    decl m_dSigmaSqr;

    Ols();
    GetPackageName();
    GetPackageVersion();
    DoEstimation(vP);
};

Ols::Ols()
{
    Modelbase();
}
Ols::GetPackageName()
{
    return "Ols";
}
Ols::GetPackageVersion()
{
    return "1.0";
}
Ols::DoEstimation(vP)
{
    decl cp = columns(m_mX);
    SetParCount(cp);

    olsc(m_mY, m_mX, &vP, &m_mCovar);
    m_mRes = m_mY - m_mX * vP;
    m_dSigmaSqr = m_mRes'm_mRes / (rows(m_mY) - cp);
    m_mCovar *= m_dSigmaSqr;

    SetResult(MAX_CONV);
    
    return vP;
}

main()
{
    decl ols = new Ols();

    ols.Load("data/data.in7");
//  ols.Info();
    ols.Deterministic(FALSE);

    ols.Select(Y_VAR, {"CONS", 0, 2});
    ols.Select(X_VAR, {"Constant", 0, 0, "INC" , 0, 2});

    ols.Estimate();
}