This note shows the R implementation of the CGA regressions using the artificial errors-in-variables dataset in Satman and Diyarbakirlioglu (2015).

We import the dataset from the GitHub repository using:

data <- read.csv(
          file.path(
            "http://raw.githubusercontent.com/",
            "erkind/data-hdr/main/",
            "jscs-2015-artificial.csv"),
          header = TRUE, sep = ";")
attach(data)

Packages

library(eive)

Regressions

  1. OLS regressions of Y on (true) W1 and (true) W2
fit_ols <- lm(formula = y ~ W1 + W2)
fit_ols_coef <- summary(fit_ols)$coefficients[,c(1,2)]
  1. OLS regressions of Y on (eiv) X1 and (true) W2
fit_eiv <- lm(formula = y ~ X1 + W2)
fit_eiv_coef <- summary(fit_eiv)$coefficients[,c(1,2)]
  1. CGA regression of Y on (cga) X1 and (true) W2
fit_cga <- eive.cga(dirtyx = X1, otherx = W2, y = y)$eive
fit_cga_coef <- summary(fit_cga)$coefficients[,c(1,2)]
rownames(fit_cga_coef) <- c("(Intercept)", "X1_CGA", "X2")

Reporting output

fit_ols_coef
##              Estimate Std. Error
## (Intercept) 23.691757  2.0756209
## W1           9.605439  0.1626764
## W2          10.036261  0.1187407
fit_eiv_coef
##              Estimate Std. Error
## (Intercept) 54.139990 12.9216467
## X1           6.067546  0.8751129
## W2          10.137024  0.8121728
fit_cga_coef
##              Estimate Std. Error
## (Intercept) 23.407180  4.4529877
## X1_CGA       9.458627  0.3450225
## X2           9.541746  0.2540051
Diyarbakirlioglu, Erkin, and M. Hakan Satman. 2015. “Reducing Errors-in-Variables Bias in Linear Regression Using Compact Genetic Algorithms.” Journal of Statistical Computation and Simulation 85 (16): 3216–35. https://doi.org/https://doi.org/10.1080/00949655.2014.961157.