This isn't an issue with GLM directly, but with the underlying @formula
macro from StatsModels.jl - as far as I know, there's currently no syntax for generating polynomials up to a prespecified order.
You can however apply Julia functions columnwise within the formula macro, so up to a limited order it's probably easiest to just type it out like
using GLM, DataFrames
y = [0.1*x^2 - 0.5*x for x ∈ 1:100]
x = collect(1:100)
df = (y = y, x = x)
fit(LinearModel, @formula(y ~ x + x^2), df)
Note that this doesn't require having x squared as a column in the dataframe - the @formula
can generate the required regressors on the fly in the model matrix.
You can also generate formulas programmatically, as described in the docs here - the problem is that this doesn't yet work for passing Julia functions as shown above in the @formula
macro. I believe work is ongoing on this, so stay tuned.