Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to run a EIV regresison

I am trying to run an EIV regression but I am having troubles understanding the sigma error required
I have a data frame like this (example data):

y x x.sd
46.5 4.3 0.52
54.2 4.6 0.71
56.7 5.1 1.01
49.4 4.9 0.54
51.1 3.9 1.1

y=dependent variable

x=independent variable

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

x.sd= standard deviation of x

I tried:

library(eivtools)

eivreg(y~x, data, Sigma_error = x.sd)

But I get an error. Sigma must be a matrix
I am a bit confused now because I thought Sigma was the sd of the variable

Could someone please explain what us exactly the sigma value here?
Any help is highly appreciate it

>Solution :

You have to compute a named matrix Sigma_error of the regressors, in this case a 1×1 matrix.
Note that the lm and unadjusted eiv coefficients are equal.

data <- "y  x   x.sd
46.5    4.3     0.52
54.2    4.6     0.71
56.7    5.1     1.01
49.4    4.9     0.54
51.1    3.9     1.1"
data <- read.table(text = data, header = TRUE)

library(eivtools)
#> Loading required package: R2jags
#> Loading required package: rjags
#> Loading required package: coda
#> Linked to JAGS 4.3.1
#> Loaded modules: basemod,bugs
#> 
#> Attaching package: 'R2jags'
#> The following object is masked from 'package:coda':
#> 
#>     traceplot

# Sys.setenv(JAGS_HOME="C:/PROGRA~1/JAGS/JAGS-4.3.1")

S2 <- matrix(var(data$x.sd), dimnames = list("x", "x"))
fit_lm <- lm(y ~ x, data)
fit_eiv <- eivreg(y ~ x, data, Sigma_error = S2)

summary(fit_lm)
#> 
#> Call:
#> lm(formula = y ~ x, data = data)
#> 
#> Residuals:
#>      1      2      3      4      5 
#> -4.006  2.455  2.890 -3.584  2.245 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)
#> (Intercept)   32.750     19.247   1.702    0.187
#> x              4.129      4.202   0.983    0.398
#> 
#> Residual standard error: 4.013 on 3 degrees of freedom
#> Multiple R-squared:  0.2435, Adjusted R-squared:  -0.008679 
#> F-statistic: 0.9656 on 1 and 3 DF,  p-value: 0.3982
summary(fit_eiv)
#> 
#> Call:
#> eivreg(formula = y ~ x, data = data, Sigma_error = SE)
#> 
#> Error Covariance Matrix
#>         x
#> x 0.07133
#> 
#> Residuals:
#>      1      2      3      4      5 
#> -3.317  2.349  1.458 -4.486  3.996 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)
#> (Intercept)   20.657     25.663   0.805    0.480
#> x              6.781      5.545   1.223    0.309
#> Number of observations used: 5 
#> Latent residual standard deviation: 3.574 
#> Latent R-squared: 0.3999, (df-adjusted: -0.0002294)
#> 
#> EIV-Adjusted vs Unadjusted Coefficients:
#>             Adjusted Unadjusted
#> (Intercept)   20.657     32.750
#> x              6.781      4.129

Created on 2023-06-27 with reprex v2.0.2

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading