I am using the gls function from nlme to fit models with various ARMA terms. I would like to compare multiple different models to see which of the ARMA terms provides the best model.
My general model is as follows:
fit <- gls(y ~ x, data = na.omit(data), method = "ML", correlation = corARMA(p = 2, q = 3))
My y and x variables are percentages.
For every model with a combination of ARMA terms from p = 1 through p = 3 and q = 1 through q =3 work fine, however, when I fit the model specified above (ARMA(2,3)) I get the following error message.
"Error in `coef<-.corARMA`(`*tmp*`, value = value[parMap[, i]]) : NA/NaN/Inf in foreign function call (arg 1)"
If I rerun the model specifyig method = "REML"
it works ok, but i want to compare models using log-likelihood raio tests so I will need to stick with method = "ML"
.
Any idea what could be causing this?
Here is a dput
output of a few lines of data:
structure(list(date2 = structure(c(12234, 12265, 12296, 12357,
12509), class = "Date"), min = c(12, 114, 480, 818, 42), fai = c(0.632,
0.707, 3.397, 7.107, 2.011), total_time = c(1237L, 3337L, 4776L,
9385L, 3665L), min_stand = c(0.00970088924818108, 0.0341624213365298,
0.100502512562814, 0.0871603622802344, 0.0114597544338336), total_feed = c(6234L,
7120L, 5592L, 6252L, 2020L), perc_feed = c(0.192492781520693,
1.60112359550562, 8.58369098712446, 13.0838131797825, 2.07920792079208
), kcal = c(99.688648314, 923.280754221, 4671.223064892, 6851.385488668,
408.732018202), kcal_tot = c(26428.225231694, 47032.415227701,
20824.864136682, 44505.409085806, 16408.141649702), kcal_perc = c(0.377205232057916,
1.96307323311181, 22.4309893895724, 15.3945006447612, 2.49103175074932
), month = c(1L, 2L, 3L, 5L, 10L)), row.names = c(1L, 2L, 3L,
5L, 10L), class = "data.frame")
My "y" variable is "perc_kcal" and my "x" is "fai".
Thank you
PS. If I do the same modeling procedure using a different response variable ("min_stand") the model fails to converge only with the same p=2 and q=3 terms.
Error in gls(model = min_stand ~ fai, data = na.omit(df_cum_kam), method = "ML", :
function evaluation limit reached without convergence (9)