annennenne / causalDisco

Tools for causal discovery in R
18 stars 0 forks source link

R session crashes if one variable is constant #5

Open RadoslavaS opened 5 months ago

RadoslavaS commented 5 months ago

When I tried to run tpc for subsets of data in for cycle sometimes one variable is constant (e.g. all values are 0) in that subset. If that happened, the whole R session crashed. Would it be please possible to make it work, just leave the associations with that variable empty, and maybe issue a warning, but still estimate the structure for the rest of the variables?

annennenne commented 5 months ago

Thank you for reporting this issue!

Could you check whether it works if you use a different test, e.g. the test for vanishing partial correlations. You can specify the test using test = corTest in your tpc() call.

RadoslavaS commented 5 months ago

That worked, with warning message "In cor(data, use = "pairwise.complete.obs") : the standard deviation is zero" which is OK. Under setting sparsity to 1 , arrows from all variables to all variables appeared, except for the constant variable, so the result is as expected. The error message before crash of R session under default test parameter is "Error in ns(constant_variable, df = 3): all interior knots match left boundary knot."

annennenne commented 5 months ago

Thank you for checking this!

That error message makes sense (the point is that you cannot use regression splines on variables with very little variation).

I am however surprised that your session crashes, it should just return that error and give up. Has the session crashing happened multiple times when this error message comes about?

By the way, I would recommend pre-processing the data to remove any variables with no variation before using causal discovery. Then the regTest should also work.

RadoslavaS commented 5 months ago

Thanks for getting back to me and for suggestions. Sure preprocessing must be done, and I also agree with the error message, but it would be nice if the session did not crash because of that. I have tested several times also with different data and different sparsity parameter and it always crashed. I will use it with more caution to preprocessing or correct test method.

annennenne commented 5 months ago

That is indeed strange, I will try to look into the issue with the session crashing. I completely agree: that should not happen.