logo

How to Perform Regression Analysis in Julia 📂Julia

How to Perform Regression Analysis in Julia

Overview

This brief introduction presents the GLM.jl package for conducting regression analysis in Julia, emphasizing its similarity to the interface in R and thus, skipping detailed explanations1.

Code

Julia

using GLM, RDatasets

faithful = dataset("datasets", "faithful")

out1 = lm(@formula(Waiting ~ Eruptions), faithful)

The result of running the above code is as follows:

julia> out1 = lm(@formula(Waiting ~ Eruptions), faithful)
StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.CholeskyPivoted{Float64, Matrix{Float64}}}}, Matrix{Float64}}

Waiting ~ 1 + Eruptions

Coefficients:
───────────────────────────────────────────────────────────────────────
               Coef.  Std. Error      t  Pr(>|t|)  Lower 95%  Upper 95%
───────────────────────────────────────────────────────────────────────
(Intercept)  33.4744    1.15487   28.99    <1e-84    31.2007    35.7481
Eruptions    10.7296    0.314753  34.09    <1e-99    10.11      11.3493
───────────────────────────────────────────────────────────────────────

Compare this with the results from regression analysis in R.

Comparison with R

out1<-lm(waiting~eruptions,data=faithful); summary(out1)
out1 = lm(@formula(Waiting ~ Eruptions), faithful)

The above is the code in R, and below is the code in Julia. The @formula macro was used to input variables, almost perfectly replicating the convention in R.

Environment

  • OS: Windows
  • julia: v1.7.0
  • GLM v1.8.0

See Also