Program for Errors-in-Variables Regression

Below is the R Program for Errors-In-Variables (EIV) Regression as described in the following article:

Culpepper, S. A., & Aguinis, H. (2011). Using Analysis of Covariance (ANCOVA) with fallible covariates. Psychological Methods, 16, 166–178. [copyright notice: You may download this article for one-time personal use only; please obtain publisher permission for any further distribution, publication, or commercial use.][ pdf version]

The following R code defines a function called ‘eiv’:

eiv<-function(formula,reliability,data){
mfx<-model.matrix(formula,data=data)
p<-length(mfx[1,])-1;n<-length(mfx[,1])
mf <- match.call(expand.dots = FALSE)
m <- match(c("formula", "data", "subset", "weights", "na.action",
    "offset"), names(mf), 0L)
mf <- mf[c(1L, m)]
mf$drop.unused.levels <- TRUE
mf[[1L]] <- as.name("model.frame")
mf <- eval(mf, parent.frame())
mf<-data.frame(mf)
MXX<-var(mfx[,c(2:(p+1))]);MXY<-var(mfx[,c(2:(p+1))],mf[,1])
Suu<-matrix(0,p,p)
if(p==1) Suu=(1-reliability)*MXX else
if(p>1) diag(Suu)<-(1-reliability)*diag(MXX)
Mxx<-MXX-(1-p/n)*Suu;Btilde<-solve(Mxx)%*%MXY
vY=var(mf[,1])
MSEtilde<-as.numeric(n*(vY-2*t(Btilde)%*%MXY+t(Btilde)%*%MXX%*%Btilde)/(n-p-1))
Rhat<-matrix(0,p,p);diag(Rhat)<-(t(Btilde)%*%Suu)^2
VCtilde<-MSEtilde*(1/n)*solve(Mxx)+(1/n)*solve(Mxx)%*%(Suu*MSEtilde+Suu%*%Btilde%*%t(Btilde)%*%Suu+2*Rhat)%*%solve(Mxx)
ttilde<-Btilde/sqrt(diag(VCtilde))
output<-cbind(reliability,Btilde,sqrt(diag(VCtilde)),ttilde,2*(1-pt(abs(ttilde),n-p)))
colnames(output)<-c('Reliability','Est.','S.E.','t','Prob.(>|t|)')
output
}
                                    

Users can implement the eiv function by first submitting the aforementioned code to R. Once the eiv function is entered into R, users need to specify a statistical model, a vector of reliability coefficients for the predictors, and the name of the dataset. For example, the following code would compute an EIV analysis with a dependent variable (y), two covariates (x1 and x2), and a dichotomously coded treatment effect (treat):

                eiv(y~x1+x2+treat,reliability=c(.8,.9,1),data=eivdata)

Also, note that the option ‘reliability=’ allows users to specify the reliability of the three predictors (in this case, the reliability coefficients for x1, x2, and treat are .8, .9, and 1.0, respectively). Finally, the option denoted by ‘data=’ specifies the name of the dataset containing the dependent and independent variables (the name of the dataset in this example is ‘eivdata’). Submitting the eiv command will produce a table of regression output with disattenuated estimates, parameter standard errors based upon Equation 2, t-values, and p-values.