For log_fit, the equation is log y=a+b*log x, whose output coefficients are ‘a’ and ‘b’. Slope ‘b’ is applied in view of log x, so how can I plot the non-linear regression in a loglog plot on scale of x?
Another way is to use log x as the scale, but all other attributes of loglog plot need to be mannually set in this case, i.e. vertically asymmetric error bar and axis notation. It seems to be harder for me and clumsy.
scatter(x, y, yerror=se, scale=:log10)
Plots.abline!(coef,coef,line=:dash,scale=:log10)#made no difference
Plots.abline!(coef,coef,line=:dash,xaxis=:log10)#made no difference
You could just calculate that curve directly, with something like
xgrid = range(extrema(x)...; length = 100)
ygrid = exp.(coef .+ coef .* log.(xgrid)) # check the order, I did not test this
and then plot the
xgrid, ygrid curve.
Thank you, your method should work but the coefficients output from log_fit are weird (making the ygrid infinite). To make it repeatable, I attached the data in codes.
x=[ 10 100 1000 10000]
#mean time of an allele to extinction or fixation
y= [23.06 245.48 2437.8 31245.775510204083]
se=[2.068502366645087 26.886795788176432 264.41256106505153 2811.6173148600947] #of mean y
scatter(x, y, yerror=se, scale=:log10,legend=false)
ygrid = exp.(coef .+ coef .* log.(xgrid))
Check the docs of
log_fit, it is for y = a_1 + a_2 \log(x).
I get it. Thank you for your patience~