IQSS / Amelia

Amelia: A Package for Missing Data

Home Page:http://gking.harvard.edu/amelia

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

chol() throws std::runtime_error on singular matrices causing R to terminate

jonlachmann opened this issue · comments

When testing a piece of software I am working on that uses Amelia I came across an error where R suddenly terminates. After some investigation it turns out that chol() throws a std::runtime_error when the matrix it tries to decompose is singular.

I have attached a file which causes the problem when running Amelia with the command

test <- amelia(temp_data, m = 5, ts = "dates", p2s = 0, idvars = NULL, cs = NULL, parallel="no", lags = colnames(temp_data)[-1])

I have also forked the repository to https://github.com/jonlachmann/Amelia where a fix is applied. Please let me know if you want me to create a pull request or if you find a better solution. My solution is quite simple, I have added try/catch blocks around the chol() calls, and on failure I let C++ return R_Nilvalue. This is then handled in R the same way as was already present when Amelia even before calling the C++ function was able to determine that the matrix was singular.

ameliacrash.RData.zip