# How to model seasonal data using GLM.jl

**URL:** <https://discourse.julialang.org/t/how-to-model-seasonal-data-using-glm-jl/46629>\
**Category:** Machine Learning\
**Tags:** question, glm\
**Created:** [September 15, 2020, 9:31am UTC](https://discourse.julialang.org/t/how-to-model-seasonal-data-using-glm-jl/46629 "2020-09-15T09:31:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Post date:** [September 15, 2020, 9:31am UTC](https://discourse.julialang.org/t/how-to-model-seasonal-data-using-glm-jl/46629/1 "2020-09-15T09:31:56Z")

</div>

I would like to model some data that exhibits strong hourly seasonality.  
Additionally the data depends on the ambient temperature and if it is a holiday or workday.

```julia
@formula(y ~ 1 + T_amb + T_amb^2 + hour_of_day(t))

```

One option would be to encode the hour of day in a set of dummy variables or to use a Fourier approach.  
Additionally I want to switch the hour of day model if it is a holiday or workday.

```julia
@formula(y ~ 1 + T_amb + T_amb^2 + hour_of_day_holiday(t) + hour_of_day_workday(t))

```

How would I do that?  
Is there an easier way to include such a switch?

---

<div class="post-metadata">

**Author:** ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Post date:** [September 23, 2021, 12:12pm UTC](https://discourse.julialang.org/t/how-to-model-seasonal-data-using-glm-jl/46629/2 "2021-09-23T12:12:09Z")

</div>

It should be something like this:

```julia
GLM.@formula(y ~ T_amb + hour + hour&holiday)

```

---

<div class="post-metadata">

**Author:** ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Post date:** [September 23, 2021, 12:13pm UTC](https://discourse.julialang.org/t/how-to-model-seasonal-data-using-glm-jl/46629/3 "2021-09-23T12:13:05Z")

</div>

The Fourier approach is described here: [https://github.com/JuliaStats/StatsModels.jl/issues/130](https://github.com/JuliaStats/StatsModels.jl/issues/130)
