nowcasting
nowcasting copied to clipboard
remNANs_spline() should not fail when rows have less than 80% of NANs
The following code fails when rowSums(indNAN) is always <= N*0.8 because then nanLead is empty and therefore X[-nanLE,] contains no rows and t1 and t2 will be infinite and the function stats::spline() will fail.
Instead the code should work in all cases including when there is no rows full of NaNs. I don't understand why there is this 80% threshold.
}else if(options$method == 2){ # replace missing values after removing leading and closing zeros
rem1 <- (rowSums(indNaN)>N*0.8)
nanLead <- which(rem1)
# nanEnd <- which(rem1[length(rem1):1])
# nanLE <- c(nanEnd,nanLead)
nanLE<-nanLead
X<-X[-nanLE,]
indNaN=is.na(X)
for (i in 1:N){
x = X[,i]
isnanx = is.na(x)
t1 = min(which(!isnanx))
t2 = max(which(!isnanx))
x1<-stats::spline(x[t1:t2],xout = 1:(t2-t1+1))
I had the same problem. I think the code should not run X <- X[-nanLE, ] when none of the rows have more than 80% NAs.