ChainLadder icon indicating copy to clipboard operation
ChainLadder copied to clipboard

MultiChainLadder plot error when NA's in triangle

Open trinostics opened this issue 6 years ago • 1 comments

When upper left of triangle is NA, plot fails. Here is a simple example:

GenIns[1, 1] <- NA plot(MultiChainLadder(list(GenIns))) Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ In addition: Warning message: In cbind(do.call("rbind", fitted.values), dev) : number of rows of result is not a multiple of vector length (arg 2)

This appears to be caused in the fitted method. By removing NA's in the variable 'x' (in the "MCL" case) after line 1272 thus 1272: x <- sapply(Triangles, "[", 1:(m-i),i)
x <- x[!is.na(x)] old 1273: fitted[[i]] <- x%*%diag(B[[i]],nrow=p) the package compiled and the error went away for me.

I did not thoroughly test, nor test the "GMCL" case.

Perhaps a more elegant solution would utilize each model's fitted method as is currently done for the 'residuals' method, but I did not investigate that.

Thanks, Dan

R.version _
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 5.3
year 2019
month 03
day 11
svn rev 76217
language R
version.string R version 3.5.3 (2019-03-11) nickname Great Truth

trinostics avatar Mar 18 '19 12:03 trinostics

Apologies, but that fix did not work when more than one triangle is included:

plot(MultiChainLadder(list(GenIns, RAA))) Error in x %*% diag(B[[i]], nrow = p) : non-conformable arguments

But this hack after lines 736 and 737 worked: # fitted values fitted.values <- fitted(object) # remove all-NA rows, maintaining matrix structure fitted.values <- lapply(fitted.values, function(x) x[rowSums(is.na(x)) != ncol(x), , drop = FALSE])

trinostics avatar Mar 21 '19 03:03 trinostics