Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

polynomial regression in julia - glm

Is it possible to do polynomial regression in the GLM-package within Julia? Considering the similarity with R syntax, I had hoped that

 fit(LinearModel, @formula(y ~ poly(x,5)), dataset)

would work (for fitting a degree 5 polynomial). It does not.

like image 920
user3548590 Avatar asked Mar 04 '23 08:03

user3548590


2 Answers

Although you are explicitly asking for a GLM.jl solution, let me nonetheless point out the straightforward solution using Polynomials.jl:

using Polynomials
polyfit(x, 5)

See polyfit for more information.

like image 183
carstenbauer Avatar answered Mar 28 '23 14:03

carstenbauer


StatsModels.jl does not provide a poly() function, but their documentation does provide a complete example that shows how you can add your own poly() function that will work inside the @formula macro.

like image 41
Cameron Bieganek Avatar answered Mar 28 '23 13:03

Cameron Bieganek