Hello
I have a problem: I want to do a computation of one figure each step with a sample that increments by one step.
Concretely, I want to fit a model from 2021-01-05 until 2021-04-05, then predict on 2021-05-05.
I have a problem to code a loop for sliding window over the sample:
I want to estimate a function (Qnew) from line 1 to line 44 then for each out the sample line
going from 45 to 51 (1 to 45, then 1 to 46, ...to 1 to 51), I want i) to estimate the two daily parameters (v1,v2) and compute the
corresponding daily Qnew to compare it finally with Q.
Thanks a lot
-
function:
Qnew <- function(v1,v2,P) { output <- P^2 - v1P + v2P^0.5
return(output) } -
data:
dput(DF)
structure(list(t = structure(c(18632, 18632, 18632, 18632, 18632,
18632, 18632, 18632, 18632, 18632, 18632, 18632, 18632, 18632,
18632, 18632, 18632, 18632, 18722, 18722, 18722, 18722, 18722,
18722, 18722, 18722, 18722, 18722, 18722, 18722, 18722, 18722,
18722, 18722, 18722, 18722, 18722, 18722, 18722, 18722, 18722,
18722, 18722, 18722, 18752, 18752, 18752, 18752, 18752, 18752,
18752), class = "Date"), T = structure(c(18762, 18762, 18762,
18797, 18797, 18797, 18797, 18797, 18797, 18797, 18797, 18825,
18825, 18825, 18825, 18825, 18825, 18825, 18762, 18762, 18762,
18762, 18762, 18762, 18762, 18762, 18762, 18797, 18797, 18797,
18797, 18797, 18797, 18825, 18825, 18825, 18825, 18825, 18825,
18825, 18825, 18825, 18825, 18825, 18762, 18762, 18762, 18762,
18762, 18762, 18762), class = "Date"), P = c(0.307226768393632,
0.301688731220703, 0.396139887693312, 0.323209211730937, 0.319602633192871,
0.312321320233133, 0.30329073088301, 0.322303373168933, 0.103883903792236,
0.100133319383373, 0.110331003036399, 0.303272396369116, 0.373632906761169,
0.313616062927236, 0.331809311366162, 0.303132639693213, 0.397136088790893,
0.383877823336263, 0.236323307903033, 0.233372881698608, 0.231780329830088,
0.23386123036873, 0.233308869933082, 0.229373693777893, 0.0928117196083069,
0.0916033303396606, 0.0936313619063331, 0.396189322171021, 0.392973268331063,
0.389768168238667, 0.386373310360718, 0.387233363333833, 0.383031632908323,
0.363130308318273, 0.362333112682333, 0.339339339130839, 0.336762032999268,
0.333986731161336, 0.361321991729736, 0.333963620030893, 0.33217086638931,
0.339383693376263, 0.0960337319166363, 0.0993326877973363, 0.383237680311373,
0.33337396282939, 0.318139362363087, 0.312297829337236, 0.306362313368632,
0.300638233383397, 0.303293118713379), Q = c(0.48332, 0.48332,
0.48332, 0.343432, 0.343432, 0.343432, 0.343432, 0.343432, 0.343432,
0.343432, 0.343432, 0.328632, 0.328632, 0.328632, 0.328632, 0.328632,
0.328632, 0.328632, 0.48332, 0.48332, 0.48332, 0.48332, 0.48332,
0.48332, 0.48332, 0.48332, 0.48332, 0.30832, 0.30832, 0.30832,
0.30832, 0.30832, 0.30832, 0.32372, 0.32372, 0.32372, 0.32372,
0.32372, 0.32372, 0.32372, 0.32372, 0.32372, 0.32372, 0.32372,
0.4802, 0.4802, 0.4802, 0.4802, 0.4802, 0.4802, 0.4802)), class = "data.frame", row.names = c(NA,
-51L))