Hello,
I'm trying to use a recipe and workflow approach to train and test a basic function (Qnew) to compare
it with the real result (Q) to compute the error (Q-Qnew). I have difficulty to use this approach using a time series sample. Can somebody
help please? Thank you !
function
Qnew <- function(v1,v2,P) {
output <- P^2 - v1P + v2P^0.5
return(output) }
#recipe
rec <- recipe(Q ~ ., data = DFnew) |> step_rm(Qnew,t,T) )
#fit
Q_model <- Qnew(v1,v2,P) #|> set_mode("regression")
Q_fit <- workflow() |> add_recipe(rec) |> add_model(Q_model) |> fit(data = training(DFnew[1:16,]))
dput(DFnew)
structure(list(t = structure(c(18632, 18632, 18632, 18632, 18722,
18722, 18722, 18722, 18722, 18722, 18722, 18722, 18722, 18722,
18722, 18722, 18752, 18752, 18752), class = "Date"), T = structure(c(18762,
18762, 18825, 18825, 18762, 18762, 18762, 18762, 18797, 18797,
18825, 18825, 18825, 18825, 18825, 18825, 18762, 18762, 18762
), class = "Date"), P = c(0.307226768393632, 0.301688731220703,
0.397136088790893, 0.383877823336263, 0.236323307903033, 0.233372881698608,
0.231780329830088, 0.23386123036873, 0.387233363333833, 0.383031632908323,
0.363130308318273, 0.362333112682333, 0.339339339130839, 0.336762032999268,
0.333986731161336, 0.33217086638931, 0.306362313368632, 0.300638233383397,
0.303293118713379), Q = c(0.48332, 0.48332, 0.328632, 0.328632,
0.48332, 0.48332, 0.48332, 0.48332, 0.30832, 0.30832, 0.32372,
0.32372, 0.32372, 0.32372, 0.32372, 0.32372, 0.4802, 0.4802,
0.4802), Var1 = c(2.50096020091677, 2.50096020091677, -0.5, -0.5,
2.54725668147744, 2.54725668147744, 2.54725668147744, 2.54725668147744,
1.97493725869699, 1.97493725869699, 1.70074362934695, 1.70074362934695,
1.70074362934695, 1.70074362934695, 1.70074362934695, 1.70074362934695,
2.49268651598907, 2.49268651598907, 2.49268651598907), Var2 = c(2.08792096570695,
2.08792096570695, 0.3, 0.3, 2.11818891732871, 2.11818891732871,
2.11818891732871, 2.11818891732871, 1.50848580270179, 1.50848580270179,
1.31326906963846, 1.31326906963846, 1.31326906963846, 1.31326906963846,
1.31326906963846, 1.31326906963846, 2.07769801039209, 2.07769801039209,
2.07769801039209), tau = c(0.515873015873016, 0.515873015873016,
0.765873015873016, 0.765873015873016, 0.158730158730159, 0.158730158730159,
0.158730158730159, 0.158730158730159, 0.297619047619048, 0.297619047619048,
0.408730158730159, 0.408730158730159, 0.408730158730159, 0.408730158730159,
0.408730158730159, 0.408730158730159, 0.0396825396825397, 0.0396825396825397,
0.0396825396825397), Qnew = c(0.483320047222566, 0.483320200650506,
0.545341320675823, 0.525174718921205, 0.483589787497889, 0.483271431205203,
0.483089884158565, 0.483325725694934, 0.323889795485953, 0.323844855278864,
0.305651870171315, 0.305560206891978, 0.303038500394118, 0.302768602694647,
0.302480343623321, 0.302292993804421, 0.480198627198239, 0.480198419841613,
0.480203029131672)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-19L))