carrieholt / KF-funcs

Simulation of time-varying Ricker model
0 stars 0 forks source link

Add full likelihood to Kalman filters #4

Closed catarinawor closed 2 years ago

catarinawor commented 2 years ago

In order to compare the Kalman Filter functions with others using AIC (e.g. Recursive Bayes or regime shift models), we need the KF function to use the full likelihood (e.g. dnorm() isntead of just least squares). I Think this would be just a matter of replacing this line on the Kalman filter function by:

sig =sqrt(f(0)); ans+=-dnorm(y(0) , yhat(0),sig,true);

or something like that? -- help figuring this out would be appreciated =)

carrieholt commented 2 years ago

Yes, I think that would work. The absolute value of the AICs will differ from the original KF-R code, but the model ranks should be the same. Maybe good to check that the parameter estimates are the same.

catarinawor commented 2 years ago

Estimates are very similar see differences below. I'll add an option to the kfTMB() function to use full or simplified LL.

              Estimate    Std. Error

initmeana -2.220446e-16 9.259260e-14 b 4.440892e-16 -1.740830e-13 logsige 1.110223e-16 5.134781e-16 logsigw 6.661338e-16 -5.873080e-14 smoothemeana -2.220446e-16 1.382228e-14 smoothemeana -2.220446e-16 3.663736e-15 smoothemeana -2.220446e-16 -5.578871e-15 smoothemeana -2.220446e-16 -2.914335e-15 smoothemeana 0.000000e+00 5.134781e-15 smoothemeana 0.000000e+00 4.635181e-15 smoothemeana 0.000000e+00 -5.523360e-15 smoothemeana 0.000000e+00 -1.587619e-14 smoothemeana 0.000000e+00 -2.060851e-14 smoothemeana 0.000000e+00 -1.924849e-14 smoothemeana 0.000000e+00 -2.103873e-14 smoothemeana 0.000000e+00 -1.923461e-14 smoothemeana 0.000000e+00 -1.317002e-14 smoothemeana 0.000000e+00 -9.769963e-15 smoothemeana 0.000000e+00 -1.262879e-14 smoothemeana 0.000000e+00 -1.391942e-14 smoothemeana 0.000000e+00 -1.486311e-14 smoothemeana 0.000000e+00 -1.067202e-14 smoothemeana 0.000000e+00 -1.214306e-14 smoothemeana 0.000000e+00 -8.743006e-15 smoothemeana 0.000000e+00 -3.164136e-15 smoothemeana 0.000000e+00 3.289036e-15 smoothemeana 0.000000e+00 4.315992e-15 smoothemeana 0.000000e+00 -1.471046e-15 smoothemeana 0.000000e+00 7.355228e-16 smoothemeana 0.000000e+00 2.886580e-15 smoothemeana 0.000000e+00 -3.150258e-15 smoothemeana 0.000000e+00 1.929013e-15 smoothemeana 0.000000e+00 2.678413e-15 smoothemeana 0.000000e+00 3.497203e-15 smoothemeana 0.000000e+00 7.244205e-15 smoothemeana 0.000000e+00 7.716050e-15 smoothemeana 0.000000e+00 7.521761e-15 smoothemeana 0.000000e+00 8.104628e-15 smoothemeana 0.000000e+00 7.549517e-15 smoothemeana 0.000000e+00 1.304512e-15 smoothemeana 0.000000e+00 -1.193490e-15 smoothemeana 0.000000e+00 -5.828671e-15 smoothemeana 0.000000e+00 -3.663736e-15 smoothemeana 0.000000e+00 -1.582068e-15 smoothemeana 0.000000e+00 1.110223e-15 smoothemeana -2.220446e-16 -2.303713e-15 smoothemeana -2.220446e-16 -2.581269e-15 smoothemeana -2.220446e-16 -1.001976e-14 smoothemeana -2.220446e-16 -1.576517e-14 smoothemeana -2.220446e-16 -2.695066e-14 smoothemeana -2.220446e-16 -3.150258e-14 smoothemeana -4.440892e-16 -4.005130e-14 smoothemeana -4.440892e-16 -4.474199e-14 smoothemeana -4.440892e-16 -5.478951e-14 smoothemeana -4.440892e-16 -5.928591e-14 smoothemeana -4.440892e-16 -6.850076e-14 smoothemeana -4.440892e-16 -7.827072e-14 smoothemeana -4.440892e-16 -8.398837e-14 smoothemeana -4.440892e-16 -8.160139e-14 smoothemeana -6.661338e-16 -8.348877e-14 smoothemeana -6.661338e-16 -6.145084e-14 smoothemeana -4.440892e-16 -4.057865e-14 smoothemeana -2.220446e-16 -1.956768e-14 smoothemeana -2.220446e-16 1.165734e-15 smoothemeana -2.220446e-16 8.687495e-15 smoothevara 5.551115e-17 -2.657596e-15 smoothevara 8.326673e-17 -1.741662e-15 smoothevara 5.551115e-17 -1.353084e-15 smoothevara 5.551115e-17 -1.262879e-15 smoothevara 5.551115e-17 -1.311451e-15 smoothevara 4.857226e-17 -1.419004e-15 smoothevara 5.551115e-17 -1.536965e-15 smoothevara 6.245005e-17 -1.661865e-15 smoothevara 6.245005e-17 -1.755540e-15 smoothevara 6.938894e-17 -1.828399e-15 smoothevara 6.245005e-17 -1.880440e-15 smoothevara 6.938894e-17 -1.949829e-15 smoothevara 6.938894e-17 -1.987993e-15 smoothevara 6.245005e-17 -2.008810e-15 smoothevara 6.245005e-17 -2.053913e-15 smoothevara 5.551115e-17 -2.046974e-15 smoothevara 4.857226e-17 -2.060851e-15 smoothevara 5.551115e-17 -2.064321e-15 smoothevara 4.163336e-17 -2.060851e-15 smoothevara 3.469447e-17 -2.081668e-15 smoothevara 4.163336e-17 -2.105954e-15 smoothevara 5.551115e-17 -2.088607e-15 smoothevara 5.551115e-17 -2.074729e-15 smoothevara 4.857226e-17 -2.081668e-15 smoothevara 5.551115e-17 -2.085138e-15 smoothevara 5.551115e-17 -2.088607e-15 smoothevara 5.551115e-17 -2.078199e-15 smoothevara 5.551115e-17 -2.081668e-15 smoothevara 6.245005e-17 -2.088607e-15 smoothevara 7.632783e-17 -2.081668e-15 smoothevara 6.245005e-17 -2.102485e-15 smoothevara 6.938894e-17 -2.078199e-15 smoothevara 4.857226e-17 -2.081668e-15 smoothevara 4.163336e-17 -2.088607e-15 smoothevara 4.857226e-17 -2.088607e-15 smoothevara 5.551115e-17 -2.088607e-15 smoothevara 5.551115e-17 -2.102485e-15 smoothevara 6.245005e-17 -2.095546e-15 smoothevara 6.938894e-17 -2.095546e-15 smoothevara 7.632783e-17 -2.092077e-15 smoothevara 7.632783e-17 -2.092077e-15 smoothevara 5.551115e-17 -2.071260e-15 smoothevara 4.857226e-17 -2.085138e-15 smoothevara 6.245005e-17 -2.053913e-15 smoothevara 4.857226e-17 -2.046974e-15 smoothevara 5.551115e-17 -2.046974e-15 smoothevara 5.551115e-17 -2.019218e-15 smoothevara 5.551115e-17 -1.991463e-15 smoothevara 4.857226e-17 -1.977585e-15 smoothevara 5.551115e-17 -1.925543e-15 smoothevara 6.245005e-17 -1.859624e-15 smoothevara 6.245005e-17 -1.772887e-15 smoothevara 6.938894e-17 -1.696560e-15 smoothevara 5.551115e-17 -1.578598e-15 smoothevara 4.857226e-17 -1.439820e-15 smoothevara 4.163336e-17 -1.318390e-15 smoothevara 4.857226e-17 -1.196959e-15 smoothevara 5.551115e-17 -1.183081e-15 smoothevara 6.938894e-17 -1.360023e-15 smoothevara 6.938894e-17 -1.904726e-15 smoothevara 8.326673e-17 -3.164136e-15 sige 1.110223e-16 3.885781e-16 sigw 1.110223e-16 -8.368306e-15

catarinawor commented 2 years ago

See commit commit 6a0cd11b812a4103aae8c4a0045d24620bf58f45