I’m quite surprised there are no posts about trendlines or lines of best fit on these forums. Maybe they are called something else? The only thing I’ve been able to find online is this:
using LinearAlgebra dates = 1:150 ticks = 1:12:150 ticks_labels = 0:12 my_values = rand(150).+dates*0.01 plot(dates, my_values, xticks = (ticks, ticks_labels), label="my series") bhat = [dates ones(150)]\my_values Plots.abline!(bhat..., label = "trendline")
I did a lot of plotting in Excel and am wondering how to or what the Julia version of a trendline/line of best fit is. In Excel, the options for trendlines are:
And are explained here as
- Linear: A straight line used to show a steady rate of increase or decrease in values.
- Exponential: This trendline visualizes an increase or decrease in values at an increasingly higher rate. The line is more curved than a linear trendline.
- Logarithmic: This type is best used when the data increases or decreases quickly, and then levels out.
- Moving Average: To smooth out the fluctuations in your data and show a trend more clearly, use this type of trendline. It uses a specified number of data points (two is the default), averages them, and then uses this value as a point in the trendline.
I tried making my own line of best fit, but it’s actually just the average of the points.
using DataFrame, StatsPlots asdf = DataFrame(bb = 10 .* rand(6), cc = 10 .* rand(6), dd = 10 .* rand(6), ee = 10 .* rand(6), ff = 10 .* rand(6), gg = 10 .* rand(6)) average_point = [mean(asdf[1,:]),mean(asdf[2,:]),mean(asdf[3,:]),mean(asdf[4,:]),mean(asdf[5,:]),mean(asdf[6,:])] plot(asdf[!,:bb]) plot!(asdf[!,:cc]) plot!(asdf[!,:dd]) plot!(asdf[!,:ee]) plot!(asdf[!,:ff]) plot!(asdf[!,:gg]) plot!(average_point, colour = :black, lw = 2.0, label = "average", leg = :outerright)
I am curious how other people view this, or any information I could have about the Julia equivalent.