plotForecastErrors(rainseriesforecasts2$residuals)
Error in quantile.default(as.numeric(x), c(0.25, 0.75), na.rm = na.rm, :
missing values and NaN's not allowed if 'na.rm' is FALSE
Could you help me find any revisions for the function?
The error message says "missing values and NaN's not allowed if 'na.rm' is FALSE" so do
sum(is.na(rainseriesforecasts2$residuals))
and you will see that you have one NA in the residuals. You need to remove that NA or to set na.rm = TRUE at the appropriate step. You can find which step in the function causes the problem by setting
forecasterrors <- rainseriesforecasts2$residuals
and executing the steps of your function one by one as if they were steps in a script.
I will also note that the line
mybins <- seq(mymin, mymax, mybinsize)
is likely to cause other problems. The values of mymin and mymax may have been set by the limits of mynorm but mybinsize was set by the limits of forecasterrors. mybinsize may not fit an integer number of times between mymin and mymax. You might try using the length.out parameter of seq() instead.
Also, please format code by typing three back tics ,```, before and after the code. On a US keyboard, the back tic is just above the TAB key. The code you posted is very difficult to read.
The main problem with your code is that the 1st observation in rainseriesforecasts2$residuals is NA. So, all of mysd, mymin, mymax are NA, as you haven't used na.rm = TRUE. This leads to the fact that all elements of mynorm are NaN, because you're supplying NA to sd argument of rnorm.
If you add na.rm = TRUE to the calculations of mysd, mymin and mymax, then you'll avoid this problem. However, I cannot test it, as I don't know what is mybinsize. You're using it inside the function, but haven't defined it anywhere in your latest code. In my solution below, I used what was here before edits, without knowing whether it's correct or not.
It's not really relevant to this thread, but you shouldn't use :::. I know I suggested it to you earlier, but since Nathan already gave you a better solution (and you also chose it), you should use that only.
Thank you very much for your great solution!
I will use this for the plot.
About :::, I did not have time to check the correct method yet.
Using this just for the convenience, I will use the right code for the next time.
Best,