-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standard errors too small when performing weighted fit #103
Comments
Have you tried master? There's been a lot of fixes wrt these things, but there hasn't been a new release in some time. |
Yes I did |
This is what I get on the latest release
|
Please reopen if you disagree that this is fixed. |
If a vector of 1s is passed as weights, the errors do not match the unweigthed fit. I assume that this is because of the missing MSE scaling when estimating the covariance matrix in the Lines 195 to 204 in 89c5b20
|
I am not an expert however, and while adding the scaling makes the two cases match up, I am not sure if that is the correct thing to do. |
Would you mind posting a simple example? |
using LsqFit
seq_lengths = [1,2,3,4,6,9,13,18,26,38,55,78,113,162,234,336,483,695,1000];
mean_Pg = [0.9965055343611369,0.9936278616188986,0.991402684125329,0.988779893392475,0.9839052359078795,
0.97561643370953,0.967542364407281,0.9591518093474497,0.9158611491602895,0.9107968163163118,
0.8780392546173316,0.8034082322818229,0.7858116656065092,0.7211658805816595,0.6547494271420033,
0.5966066491668779,0.5391289873890097,0.5149058476594188,0.5032240784925216];
exp_decay = (m,p) -> p[2].*p[1].^m .+ p[3];
# no weights (i.e. equal weights)
fitres1 = curve_fit(exp_decay,seq_lengths,mean_Pg,[1,0.5,0.5]);
@show stderror(fitres1)
# equal weights
fitres2 = curve_fit(exp_decay,seq_lengths,mean_Pg,one.(mean_Pg),[1,0.5,0.5]);
@show stderror(fitres2) which gives
|
I never got around to this, but I think this is to be expected, and what is stated in the manual. When you're passing in your own weights, you're bypassing the mechanism as stated. Essentially, you're assuming variance one on all the residuals. |
I'm not sure that makes sense; shouldn't the case where you are not passing weights correspond to uniform weights? |
Hello,
I want to fit some data with this model :
@. model(z, p) = p[1] / cos(deg2rad(z)) + p[2]
.When
z = collect(0:5:50)
andp = [A, B]
(whereA = 1.408363211310102e-6
andB = 1.4034083334666746e-5
) I get my theoretical curve.The data I want to fit are
y
. I know also the standard deviation ofy
, let's call itdelta_y
.When I fit my data with:
model_fit = LsqFit.curve_fit(model, z, y, p0)
I obtain a reasonable standard error.When instead I weight my fit with the inverse of the variance:
model_fit = LsqFit.curve_fit(model, z, y, 1 ./delta_y.^2, p0)
I get an insane standard error that is about 13 orders of magnitude smaller than the previous case.How is it possible?
I have:
y = [1.54378e-5, 1.54341e-5, 1.55381e-5, 1.54877e-5, 1.55381e-5, 1.56225e-5, 1.56568e-5, 1.56822e-5, 1.58282e-5, 1.60016e-5, 1.62545e-5]
;delta_y = [1.0376e-7, 1.05538e-7, 1.82407e-7, 2.07246e-7, 1.65643e-7, 1.76996e-7, 1.75132e-7, 2.05185e-7, 1.28095e-7, 1.07386e-7, 1.9007e-7]
;p0 = [0., 0.]
;to compute the standard error I do:
LsqFit.standard_error(model_fit)
.Thanks
edit from @pkofod
The text was updated successfully, but these errors were encountered: