[R] GAM (mgcv) warning: matrix not positive definite

Simon Wood s.wood at bath.ac.uk
Fri Feb 3 22:39:58 CET 2012


It is completely safe to ignore this. Here is what is going on...

mgcv routine 'mroot' is calling R routine 'chol' to find the *pivoted* 
Choleski factor of a positive semi definite matrix. This is deliberate, 
and completely ok to do, but 'chol' issues a warning when a matrix is 
only positive semi-definite (as opposed to strictly +ve def), even if 
pivoting has been requested. 'mroot' therefore suppresses the warning.

best,
Simon

On 03/02/12 20:38, Arnaud Mosnier wrote:
> Dear list,
>
>
> I fitted the same GAM model using directly the function gam(mgcv) ...
> then as a parameter of another function that capture the warnings
> messages (see below).
> In the first case, there is no warning message printed, but in the last
> one, the function find two warning messages stating "matrix not positive
> definite"
>
> So my question is: Do I have to worry about those warnings and then why
> are they not printed in the simple use of the gam function.
>
> #####################################################
>
> Here is some further description:
>
> ## Simple use of gam
>
> gam(USE ~ X1 + s(X2) + s(X3), family = binomial, data = data,
> method="REML") # print no warning message.
>
> ## Using a function that capture warnings
>
> Model_n_Warnings <- function(expr) {
>              localWarnings <- list()
>              outModel <- withCallingHandlers(expr,
>              warning = function(w) {
>              localWarnings[[length(localWarnings)+1]] <<- w$message  #
> store warning message
>              invokeRestart("muffleWarning") # avoid printing warning
> message to console
>              })
>              list(outModel=outModel, warnings=localWarnings)
>    }
>
> out <- Model_n_Warnings (gam(USE ~ X1 + s(X2) + s(X3), family =
> binomial, data = data, method="REML"))
>
> out$warnings
>
> [[1]]
> [1] "matrix not positive definite"
>
> [[2]]
> [1] "matrix not positive definite"
>
>
> Thanks,
>
> Arnaud


-- 
Simon Wood, Mathematical Science, University of Bath BA2 7AY UK
+44 (0)1225 386603               http://people.bath.ac.uk/sw283



More information about the R-help mailing list