# Normalization and Linear Model NaN error?

**URL:** <https://discourse.julialang.org/t/normalization-and-linear-model-nan-error/72150>\
**Category:** Statistics\
**Created:** [November 27, 2021, 3:24am UTC](https://discourse.julialang.org/t/normalization-and-linear-model-nan-error/72150 "2021-11-27T03:24:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Post date:** [November 27, 2021, 3:24am UTC](https://discourse.julialang.org/t/normalization-and-linear-model-nan-error/72150/1 "2021-11-27T03:24:04Z")

</div>

Good Day Julians:

I am attempting to pass an interpolated (imputed)  
and normalized DF into a GLM.jl function (lm(@formula …).

Under what circumstances would the Stats.Models TableRegression…  
return NaN such as:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/6/86e7e0ce4030c753acb0e74eb62350641f704e74.png)

Any suggestions?

Thank you,

---

<div class="post-metadata">

**Author:** ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Post date:** [November 27, 2021, 4:33am UTC](https://discourse.julialang.org/t/normalization-and-linear-model-nan-error/72150/2 "2021-11-27T04:33:05Z")

</div>

```julia
using LinearAlgebra
b = normalize(a)

```

---

<div class="post-metadata">

**Author:** ![Eric](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eric/32/25565_2.png) [@Eric](https://discourse.julialang.org/u/Eric)\
**Post date:** [November 29, 2021, 8:30pm UTC](https://discourse.julialang.org/t/normalization-and-linear-model-nan-error/72150/4 "2021-11-29T20:30:45Z")

</div>

There is not much to go with. Maybe you have already looked into it. But I would check that the design matrix is according to your expectations. You could do that with for instance:

```julia
using GLM, StatsModels, DataFrames
f = @formula( y ~ 1 + x2 + x3 ^2 ) # using your formula
f = apply_schema(f, schema(df)) # using your data
y, X = modelcols(f, df)
ydes = describe(y)
Xdes = describe(DataFrame(X, :auto))

```

maybe the problem will reveal itself then.  
If you are using categorical data, it may be worth looking into the numbers of observations per category, the package FreqTables ([https://github.com/nalimilan/FreqTables.jl](https://github.com/nalimilan/FreqTables.jl)) is handy for that purpose.

---

<div class="post-metadata">

**Author:** ![YummyPampers2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yummypampers2/32/27328_2.png) [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Post date:** [December 3, 2021, 12:11pm UTC](https://discourse.julialang.org/t/normalization-and-linear-model-nan-error/72150/5 "2021-12-03T12:11:52Z")

</div>

Hello Eric:

Thank you very much for this QA tips.

I believe part of the issue was also that  
I scaled/normalized the entire data  
frame values (all float64 eltypes), and  
some of the values were too small to  
render within the regression module.

Will test your instructions here and  
feed in if I encounter issues.

Thanks.
