pmlpp/mlpp/gauss_markov_checker/gauss_markov_checker.cpp

58 lines
1.6 KiB
C++
Raw Normal View History

//
// GaussMarkovChecker.cpp
//
// Created by Marc Melikyan on 11/13/20.
//
2023-01-24 18:12:23 +01:00
#include "gauss_markov_checker.h"
#include "../stat/stat.h"
#include <iostream>
2023-01-24 19:20:18 +01:00
2023-01-27 13:01:16 +01:00
void MLPPGaussMarkovChecker::checkGMConditions(std::vector<real_t> eps) {
2023-01-24 19:00:54 +01:00
bool condition1 = arithmeticMean(eps);
bool condition2 = homoscedasticity(eps);
bool condition3 = exogeneity(eps);
2023-01-24 19:00:54 +01:00
if (condition1 && condition2 && condition3) {
std::cout << "Gauss-Markov conditions were not violated. You may use OLS to obtain a BLUE estimator" << std::endl;
} else {
std::cout << "A test of the expected value of 0 of the error terms returned " << std::boolalpha << condition1 << ", a test of homoscedasticity has returned " << std::boolalpha << condition2 << ", and a test of exogenity has returned " << std::boolalpha << "." << std::endl;
}
}
2023-01-27 13:01:16 +01:00
bool MLPPGaussMarkovChecker::arithmeticMean(std::vector<real_t> eps) {
MLPPStat stat;
2023-01-24 19:00:54 +01:00
if (stat.mean(eps) == 0) {
return 1;
} else {
return 0;
}
}
2023-01-27 13:01:16 +01:00
bool MLPPGaussMarkovChecker::homoscedasticity(std::vector<real_t> eps) {
MLPPStat stat;
2023-01-27 13:01:16 +01:00
real_t currentVar = (eps[0] - stat.mean(eps)) * (eps[0] - stat.mean(eps)) / eps.size();
2023-01-24 19:00:54 +01:00
for (int i = 0; i < eps.size(); i++) {
if (currentVar != (eps[i] - stat.mean(eps)) * (eps[i] - stat.mean(eps)) / eps.size()) {
return 0;
}
}
return 1;
}
2023-01-27 13:01:16 +01:00
bool MLPPGaussMarkovChecker::exogeneity(std::vector<real_t> eps) {
MLPPStat stat;
2023-01-24 19:00:54 +01:00
for (int i = 0; i < eps.size(); i++) {
for (int j = 0; j < eps.size(); j++) {
if (i != j) {
if ((eps[i] - stat.mean(eps)) * (eps[j] - stat.mean(eps)) / eps.size() != 0) {
return 0;
}
}
}
}
return 1;
}
2023-01-24 19:20:18 +01:00