# GLM.jl DataFrame not defined error

**URL:** https://discourse.julialang.org/t/glm-jl-dataframe-not-defined-error/29454
**Category:** General Usage
**Tags:** regression, glm
**Created:** [October 3, 2019, 3:55pm UTC](https://discourse.julialang.org/t/glm-jl-dataframe-not-defined-error/29454 "2019-10-03T15:55:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)
#### Post date: [October 3, 2019, 3:55pm UTC](https://discourse.julialang.org/t/glm-jl-dataframe-not-defined-error/29454/1 "2019-10-03T15:55:10Z")

</div>

I’m getting a `DataFrame not defined` error when attempting to use the `interval` keyword argument in the `predict` function from GLM.jl.

MWE:

```julia
using DataFrames, GLM

data = DataFrame(X=[1,2,3], Y=[2,4,7])
ols = lm(@formula(Y ~ X), data)
new_data = DataFrame(X=[5])

# Without the interval kwarg

julia> predict(ols, new_data)
1-element Array{Union{Missing, Float64},1}:
 11.833333333333343

# With the interval kwarg

julia> predict(ols, new_data, interval=:prediction)
ERROR: UndefVarError: DataFrame not defined
Stacktrace:
 [1] _return_predictions(::NamedTuple{(:prediction, :lower, :upper),Tuple{Array{Float64,1},Array{Float64,2},Array{Float64,2}}}, ::BitArray{1}, ::Int64) at C:\Users\mthel\.julia\packages\StatsModels\Kz7By\src\statsmodel.jl:153
 [2] #predict#74(::Base.Iterators.Pairs{Symbol,Symbol,Tuple{Symbol},NamedTuple{(:interval,),Tuple{Symbol}}}, ::typeof(predict), ::StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Array{Float64,1}},GLM.DensePredChol{Float64,LinearAlgebra.Cholesky{Float64,Array{Float64,2}}}},Array{Float64,2}}, ::DataFrame) at C:\Users\mthel\.julia\packages\StatsModels\Kz7By\src\statsmodel.jl:166
 [3] (::getfield(StatsBase, Symbol("#kw##predict")))(::NamedTuple{(:interval,),Tuple{Symbol}}, ::typeof(predict), ::StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Array{Float64,1}},GLM.DensePredChol{Float64,LinearAlgebra.Cholesky{Float64,Array{Float64,2}}}},Array{Float64,2}}, ::DataFrame) at .\none:0
 [4] top-level scope at REPL[11]:1

```

Am I missing something or should I open an issue on GitHub?

---

<div class="post-metadata">

### Author: ![Paul\_Schrimpf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_schrimpf/32/10134_2.png) [@Paul\_Schrimpf](https://discourse.julialang.org/u/Paul_Schrimpf)
#### Post date: [October 3, 2019, 11:47pm UTC](https://discourse.julialang.org/t/glm-jl-dataframe-not-defined-error/29454/2 "2019-10-03T23:47:08Z")

</div>

Looks like a bug in StatsModels.jl to me. DataFrames is never imported by StatsModels. It’s listed in the Project.toml only as an extra testing dependency. A simple fix would be to add `using DataFrames` or `import DataFrames.DataFrame` to StatsModels.jl or statsmodel.jl and change the Project.toml accordingly. I don’t know enough about the intention behind the code to know whether that would be the best fix.

---

<div class="post-metadata">

### Author: ![dave.f.kleinschmidt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dave.f.kleinschmidt/32/55_2.png) [@dave.f.kleinschmidt](https://discourse.julialang.org/u/dave.f.kleinschmidt)
#### Post date: [November 11, 2019, 11:12pm UTC](https://discourse.julialang.org/t/glm-jl-dataframe-not-defined-error/29454/3 "2019-11-11T23:12:15Z")

</div>

Yes this was a bug, fixed by [https://github.com/JuliaStats/StatsModels.jl/pull/160](https://github.com/JuliaStats/StatsModels.jl/pull/160) (and released version 0.6.6)
