I need to find a mathematical equation for a function $f(t)$ that fits the data in y but such that $g(t) = 1 – frac{f(t)}{f(t-1)}$ fits the data in z. For $g(t) = z$ I would just use the las 11 values in t.
t <- c(2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028)
y <- c(75.22707, 74.50115, 74.28088, 74.13483, 74.09919, 74.09704, 74.09077, 74.09077, 74.09077, 74.09077, 74.09077)
z <- (9.649739e-03, 2.956616e-03, 1.966184e-03, 4.806839e-04, 2.901921e-05, 8.458133e-05, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00)
So far I have this code:
df <- data.frame(t, y, z)
g0 <- glm(y ~ t, family = gaussian(link = "inverse"))
s0 <- with(as.list(coef(g0)), list(lambda = 1/`(Intercept)`, aii = t/`(Intercept)`))
y.fit0 <- s0$lambda/ (1 + s0$aii*t
y.2 <- 1/y
g1 <- glm(y ~ t)
s1 <- with(as.list(coef(g1)), list(lambda = 1/`(Intercept)`, aii = t/`(Intercept)`))
y.fit1 <- s1$lambda/ (1 + s1$aii*t)
g2 <- loess(y ~ t, df, span = 0.5)
y.fit2 <- predict(g2, t)
library(mgcv)
g3 <- gam(y ~ s(t, bs = "cs"), family = gaussian(), data = df)
y.fit3 <- predict(g3)
The one that provides the best fit is g3, but I can’t get a mathematical equation, $f(t) = y$, for that model so that I can see if the model holds its fit for $g(t) = 1 – frac{f(t)}{f(t-1)} = z$
Isa Junbad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.