# Error in variables linear regression

**URL:** <https://discourse.julialang.org/t/error-in-variables-linear-regression/58109>\
**Category:** General Usage\
**Tags:** question, package, regression\
**Created:** [March 28, 2021, 4:17am UTC](https://discourse.julialang.org/t/error-in-variables-linear-regression/58109 "2021-03-28T04:17:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Okarin99](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/okarin99/32/21397_2.png) [@Okarin99](https://discourse.julialang.org/u/Okarin99)\
**Post date:** [March 28, 2021, 4:17am UTC](https://discourse.julialang.org/t/error-in-variables-linear-regression/58109/1 "2021-03-28T04:17:58Z")

</div>

Hi,  
how can I do an [error in variables regression](https://en.m.wikipedia.org/wiki/Errors-in-variables_models) in Julia? I didn‘t find anything online about this and I don‘t know what to do with the measurement uncertainties when I want to fit my model.

Have a nice day and thank you for all replies.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [March 28, 2021, 8:58am UTC](https://discourse.julialang.org/t/error-in-variables-linear-regression/58109/2 "2021-03-28T08:58:07Z")

</div>

You could use  
[https://github.com/baggepinnen/TotalLeastSquares.jl](https://github.com/baggepinnen/TotalLeastSquares.jl)  
but it’s a rather low-level interface

---

<div class="post-metadata">

**Author:** ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)\
**Post date:** [September 3, 2022, 7:03pm UTC](https://discourse.julialang.org/t/error-in-variables-linear-regression/58109/3 "2022-09-03T19:03:07Z")

</div>

I haven’t registered in the Julia package registry, but it is quite ready to use. It implements a specific estimator/algorithm (mainly compact genetic algorithm optimization based).

Here is the repository:

> **[GitHub - jbytecode/ErrorsInVariables.jl: Errors-in-variables estimation in...](https://github.com/jbytecode/ErrorsInVariables.jl)**
>
> Errors-in-variables estimation in linear regression using Compact Genetic Algorithms - GitHub - jbytecode/ErrorsInVariables.jl: Errors-in-variables estimation in linear regression using Compact Gen...

And will be registered soon. README.md file is a good start while we are generating a more comprehensive documentary. You can install it by typing

```julia
julia> ]
add https://github.com/jbytecode/ErrorsInVariables.jl

```

Edit:

```julia
julia> ]
add ErrorsInVariables

```

now works!

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [October 6, 2022, 7:14pm UTC](https://discourse.julialang.org/t/error-in-variables-linear-regression/58109/4 "2022-10-06T19:14:25Z")

</div>

Sorry for asking, but is this an instrumental variable (or 2SLS) approach?

---

<div class="post-metadata">

**Author:** ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)\
**Post date:** [October 7, 2022, 2:09pm UTC](https://discourse.julialang.org/t/error-in-variables-linear-regression/58109/5 "2022-10-07T14:09:34Z")

</div>

Thanks for the question, no worries.

The package simply implements the algorithm (estimator) defined in the paper

```nohighlight
@article{satman2015reducing,
  title={Reducing errors-in-variables bias in linear regression using compact genetic algorithms},
  author={Satman, M Hakan and Diyarbakirlioglu, Erkin},
  journal={Journal of Statistical Computation and Simulation},
  volume={85},
  number={16},
  pages={3216--3235},
  year={2015},
  publisher={Taylor \& Francis}
}

```

It is similar to 2SLS but the exploratory variables are automatically generated to reduce mean square error of regression estimators by reducing the bias with a smaller increase on the variance. Results are compared with the OLS counterparts by simulations.

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [October 7, 2022, 7:14pm UTC](https://discourse.julialang.org/t/error-in-variables-linear-regression/58109/6 "2022-10-07T19:14:50Z")

</div>

Thanks. This means that I have to read up, but probably after my teaching period. My initial _guess_ would be that IV/2SLS/the new stuff could all fit in such a package. Just to give the users some options. But, as I said, I really should read up before saying too much…

---

<div class="post-metadata">

**Author:** ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)\
**Post date:** [October 8, 2022, 6:31pm UTC](https://discourse.julialang.org/t/error-in-variables-linear-regression/58109/7 "2022-10-08T18:31:51Z")

</div>

You’re totally right. Mainly, the R package eive ([CRAN - Package eive](https://cran.rstudio.com/web/packages/eive/index.html)) was the reference implementation for this estimator. But Julia package naming conventions didn’t allow me to select Eive.jl as the name. So I finally ended up with `ErrorsInVariable.jl`.

Your contributions are welcome.
