Julia presents various ways to carry out linear regressions. In this post I will present how to use the native function *linreg()* to run OLS on the following model

An alternative way to run a linear regression is to use the *lm()* function of the GLM package. In case you are interested in running a regression based on the GLM package, you can check out this post. It describes how to conduct a multiple regression in Julia and uses the *lm()* function provided by the GLM package.

In this example, our dependent variable will be my weekly average weight, the explanatory variable represents the sum of calories that I burned during the previous week. For a more detailed description of the data see here.

# load a couple of packages
using Distributions
using GLM
using DataFrames
using DataArrays
# load Taro - Pkg to read Excel Data
using Taro
Taro.init()
# get data
path = "https://economictheoryblog.files.wordpress.com/2016/08/data.xlsx"
data = Taro.readxl(download(path), "data", "A1:C357")
data = deleterows!(data,find(isna(data[:,1])|isna(data[:,2])))
y = convert(DataArrays.DataArray{Float64,1},data[:,1])
x = convert(DataArrays.DataArray{Float64,1},data[:,2])
linreg(y,x)

The function linreg() returns point estimates for and . Unfortunately, the function does not return standard error for the point estimates. The function also does not allow to conduct multiple regressions. That is, the function does not allow additional explanatory variables. In order to obtain standard errors for the estimated coefficients or to add additional explanatory variables, one can use the *lm()* function form the GLM package. The GLM package of Julia does provide a more flexible environment. You can find a working example of how to conduct multiple regression in Julia using the GLM package here.

### Like this:

Like Loading...

*Related*

I think it should be linreg(x,y) instead of linreg(y,x)

I was wrong it should be linreg(y,x)

Hi, thanks for your comment anyway. I double-checked and it should be linreg(y,x). That is, its dependent and then independet variable. Cheers, ad.