Hello,
I would like to estimate a parameter x. I join the code for the SSE and the sample data.
I would like to complete the code with a function to estimate the x corresponding to each period
like:
5-1-2021 to 5-15-2021: first x
5-1-2021 to 6-19-2021: second x
5-1-2021 to 7-18-2021: third x
...
I did a try to include the function 'for(i in 1:nrow(df[1:j,])){}' but got no decent results
so i prefer no to copy paste it. Can anyone do a suggestion please? Many thanks.
Below is the basic code:
- parameters to read
t = df$t # begining
T = df$T # end
P = df$P # theoretical cost
Q = df$Q # real cost
f <- function(x){P^2 - P*x^3.5 + 5}
MSE <- function(x){ mean((f(x)-Q)^2) }
XX <- nlm(MSE,.5)
Below is the table (i did not know how to upload)
|Column 1 | Column 2 | Column 3 | Column 4|
|t | T | P | Q|
|05/01/2021 | 5-15-2021 | 28.1526245271719 | 16.2|
|05/01/2021 | 5-15-2021 | 31.0374701077521 | 16.25|
|05/01/2021 | 5-15-2021 | 33.7793286109241 | 16.3|
|05/01/2021 | 5-15-2021 | 37.4022801498769 | 16.35|
|05/01/2021 | 6-19-2021 | 40.9596399443349 | 11.75|
|05/01/2021 | 6-19-2021 | 44.8941281749715 | 11.8|
|05/01/2021 | 6-19-2021 | 48.8157358179208 | 11.9|
|05/01/2021 | 6-19-2021 | 53.3207228878127 | 12|
|05/01/2021 | 6-19-2021 | 57.7738530980319 | 12.2|
|05/01/2021 | 7-18-2021 | 62.5236845819242 | 12.75|
|05/01/2021 | 7-18-2021 | 67.3270001586133 | 13.2|
|05/01/2021 | 7-18-2021 | 72.2907124853028 | 13.25|
|05/01/2021 | 7-18-2021 | 77.1012119122497 | 13.5|
|05/01/2021 | 7-18-2021 | 81.9988293252421 | 13.6|
|05/01/2021 | 7-18-2021 | 87.0004730550886 | 13.65|
|05/01/2021 | 7-18-2021 | 92.0020964833537 | 13.7|
|05/04/2021 | 5-15-2021 | 96.9589367658646 | 21.2|
|05/04/2021 | 5-15-2021 | 102.005211124637 | 21.25|
|05/04/2021 | 5-15-2021 | 107.006712608529 | 21.3|
|05/04/2021 | 5-15-2021 | 111.926997774298 | 21.35|
|05/04/2021 | 5-15-2021 | 116.927960560155 | 21.4|
|05/04/2021 | 5-15-2021 | 121.890052104498 | 21.85|
|05/04/2021 | 5-15-2021 | 126.846498258905 | 21.9|
|05/04/2021 | 6-19-2021 | 136.847619112249 | 14.05|
|05/04/2021 | 6-19-2021 | 146.848676071273 | 14.1|
|05/04/2021 | 6-19-2021 | 151.84919455444 | 14.15|
|05/04/2021 | 6-19-2021 | 0.103524619770535 | 14.2|
|05/04/2021 | 6-19-2021 | 0.103506257603117 | 14.25|
|05/04/2021 | 6-19-2021 | 0.103441845896075 | 14.3|
|05/04/2021 | 6-19-2021 | 0.103359839336302 | 14.35|
|05/04/2021 | 6-19-2021 | 0.205395884926941 | 14.4|
|05/04/2021 | 6-19-2021 | 0.103190917272473 | 14.8|
|05/04/2021 | 6-19-2021 | 0.205284783697305 | 14.85|
|05/04/2021 | 6-19-2021 | 0.205157605182112 | 14.9|
|05/04/2021 | 6-19-2021 | 0.102999244352431 | 14.95|
|05/04/2021 | 7-17-2021 | 0.221862896678315 | 13|
|05/04/2021 | 7-17-2021 | 0.221759591534659 | 13.1|
|05/04/2021 | 7-17-2021 | 0.127137687828712 | 13.2|
|05/04/2021 | 7-17-2021 | 0.221623235949667 | 13.25|
|05/04/2021 | 7-17-2021 | 0.22150678271241 | 13.3|
|05/04/2021 | 7-17-2021 | 0.12690006301537 | 13.35|
|05/04/2021 | 7-17-2021 | 0.126809526748304 | 13.4|
|05/04/2021 | 7-17-2021 | 0.12672136985722 | 13.45|
|05/04/2021 | 7-17-2021 | 0.171509850309103 | 13.5|
|05/04/2021 | 7-17-2021 | 0.148062999444731 | 13.55|
|05/04/2021 | 7-17-2021 | 0.148006943405468 | 13.6|
|05/04/2021 | 7-17-2021 | 0.198100748961343 | 13.65|
|05/05/2021 | 5-15-2021 | 0.198018416853687 | 20.05|
|05/05/2021 | 5-15-2021 | 0.147720761862854 | 20.1|
|05/05/2021 | 5-15-2021 | 0.147672200328692 | 20.15|
|05/05/2021 | 5-15-2021 | 0.147599028101768 | 20.2|
|05/05/2021 | 5-15-2021 | 0.147537774835907 | 20.25|
|05/05/2021 | 5-15-2021 | 0.147479830307385 | 20.3|
|05/05/2021 | 5-15-2021 | 0.147420990424604 | 20.35|
|05/05/2021 | 5-15-2021 | 0.147356932923342 | 20.4|
|05/05/2021 | 5-15-2021 | 0.197267807152614 | 20.45|
|05/05/2021 | 5-15-2021 | 0.252039096686449 | 20.5|
|05/05/2021 | 5-15-2021 | 0.166873154549201 | 20.55|
|05/05/2021 | 5-15-2021 | 0.251867638945013 | 20.6|
|05/05/2021 | 5-15-2021 | 0.251802856073001 | 20.65|
|05/05/2021 | 5-15-2021 | 0.264100645685321 | 20.7|
|05/05/2021 | 5-15-2021 | 0.251616645928542 | 20.75|
|05/05/2021 | 5-15-2021 | 0.25155481886409 | 20.8|
|05/05/2021 | 5-15-2021 | 0.166453578451474 | 20.85|
|05/05/2021 | 5-15-2021 | 0.166370951569743 | 20.9|
|05/05/2021 | 5-15-2021 | 0.300404850007174 | 20.95|
|05/05/2021 | 5-15-2021 | 0.310982625879516 | 21|
|05/05/2021 | 5-15-2021 | 0.310884063211701 | 21.05|
|05/05/2021 | 5-15-2021 | 0.184458913190428 | 21.1|
|05/05/2021 | 5-15-2021 | 0.328110933303664 | 21.6|
|05/05/2021 | 5-15-2021 | 0.324826205328924 | 21.65|
|05/05/2021 | 5-15-2021 | 0.324737739322167 | 21.7|
|05/05/2021 | 5-15-2021 | 0.32464833875156 | 21.75|
|05/05/2021 | 5-15-2021 | 0.324568477528462 | 21.8|
|05/05/2021 | 5-15-2021 | 0.391365324569997 | 21.85|
|05/05/2021 | 5-15-2021 | 0.280786120728432 | 21.9|
|05/05/2021 | 5-15-2021 | 0.517069625897987 | 21.95|
|05/05/2021 | 5-15-2021 | 0.2805859248693 | 22|
|05/05/2021 | 5-15-2021 | 0.217947215371299 | 22.1|
|05/05/2021 | 5-15-2021 | 0.338056553996876 | 22.15|
|05/05/2021 | 6-19-2021 | 0.337961807201776 | 12.9|
|05/05/2021 | 6-19-2021 | 0.351786150963446 | 13|
|05/05/2021 | 6-19-2021 | 0.480374804740862 | 13.1|
|05/05/2021 | 6-19-2021 | 0.351595746920873 | 13.2|
|05/05/2021 | 6-19-2021 | 0.572031655988992 | 13.25|
|05/05/2021 | 6-19-2021 | 0.443191568986322 | 13.3|
|05/06/2021 | 5-15-2021 | 0.505750739173 | 17.45|
|05/06/2021 | 5-15-2021 | 0.459057152955033 | 17.5|
|05/06/2021 | 5-15-2021 | 0.737382755889556 | 17.55|
|05/06/2021 | 5-15-2021 | 0.339351092871443 | 17.6|
|05/06/2021 | 5-15-2021 | 0.41703590440116 | 17.65|
|05/06/2021 | 5-15-2021 | 0.547195056545363 | 17.7|
|05/06/2021 | 5-15-2021 | 0.655506047426648 | 17.75|
|05/06/2021 | 5-15-2021 | 0.608035149661355 | 17.8|
|05/06/2021 | 5-15-2021 | 0.573593680954865 | 17.85|
|05/06/2021 | 5-15-2021 | 0.336371479476565 | 17.9|
|05/06/2021 | 5-15-2021 | 0.767094268645232 | 17.95|
|05/06/2021 | 5-15-2021 | 0.35009250200978 | 18|
|05/06/2021 | 5-15-2021 | 0.349954683385633 | 18.05|
|05/06/2021 | 5-15-2021 | 0.440554070864674 | 18.1|