JuliaNLSolvers / LsqFit.jl

Simple curve fitting in Julia
Other
317 stars 78 forks source link

curve_fit function for DataFrame #141

Open AndreasBahr opened 4 years ago

AndreasBahr commented 4 years ago

Hello,

I suggest to include a curve_fit function working with DataFrame objects. It could lead to more readable and less error prone model definitions.

Best regards Andreas

# curve fit using DataFrame
# ycol: column Symbol for y-values in df
# model uses df and p as parameters e.g. "@. modLd(x,p) = p[3] + p[1]*x.cons_gas + p[2]*x.cons_oil"
function curve_fit(model,df::DataFrames.DataFrame,ycol::Symbol,p0;kwargs...)
    # construct the cost function
    T = eltype(df[!,ycol])
    f = (p) -> model(df, p) - df[!,ycol]
    lmfit(f, p0, T[]; kwargs...)
end
pkofod commented 4 years ago

I think something went wrong with your formating, but yes that could be interesting to pursue.

XKainz commented 2 years ago

I too would find such a functionality quite useful.