Re: [R] matrix which results singular but at the same time positive definite
Dear Dr.Gilbert, it took me a bit of time to understand your thoughtful comment. You are right on everything. I was not able to see it, and likely I still have something to understand better some consequences on what I am trying to do. Thank you Stefano Da: Paul Gilbert [pgilbert...@gmail.com] Inviato: martedì 15 dicembre 2015 15.28 A: Stefano Sofia Cc: r-help@r-project.org; Fox, John; peter dalgaard Oggetto: Re: [R] matrix which results singular but at the same time positive definite Stefano I think in other response to in this thread you got the answer to the question you asked, but you may be asking the wrong question. I'm not familiar with the specific papers you mention and you have not provided enough detail about what you are doing, so I am guessing a bit. The term "dynamic linear model" can refer to both linear ARMA/ARIMA models and to linear state-space models, however some authors use it to refer exclusively to state-space models and from your phrasing I am guessing you are doing that. There would be many state-space models equivalent to a given ARMA/ARIMA model, but without specifying structural aspects of the system you will likely be using one of the innovations form state-space models that are equivalent. In an innovations form state-space model the state is defined as an expectation. From a practical point of view, this is one of the most important differences between an innovation form and a non-innovations form state-space model. Since the expectation is known exactly, the state-tracking error is zero. That means the covariance matrix from the filter or smoother should be a zero matrix, which you should not be trying to invert. In a non-innovations form the state has a physical interpretation rather than being an expectation, so the state tracking error should not be degenerate in that case. I mention all this because your covariance matrix looks very close to zero. Paul Gilbert On 12/11/2015 06:00 AM, r-help-requ...@r-project.org wrote: > Dear John, thank you for your considerations. This matrix (which is a > variance matrix) is part of an algorithm for forward-filtering and > backward-sampling of Dynamic Linear Models (West and Harrison, 1997), > applied to DLM representation of ARIMA processes (Petris, Petrone, > Campagnoli). It is therefore very difficult to explain why this > variance matrix becomes so ill conditioned. This already happens at > the first iteration of the algorithm. I will try to work on initial > conditions and some fixed parameters. > > Thank you again Stefano > AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario. IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] matrix which results singular but at the same time positive definite
Stefano I think in other response to in this thread you got the answer to the question you asked, but you may be asking the wrong question. I'm not familiar with the specific papers you mention and you have not provided enough detail about what you are doing, so I am guessing a bit. The term "dynamic linear model" can refer to both linear ARMA/ARIMA models and to linear state-space models, however some authors use it to refer exclusively to state-space models and from your phrasing I am guessing you are doing that. There would be many state-space models equivalent to a given ARMA/ARIMA model, but without specifying structural aspects of the system you will likely be using one of the innovations form state-space models that are equivalent. In an innovations form state-space model the state is defined as an expectation. From a practical point of view, this is one of the most important differences between an innovation form and a non-innovations form state-space model. Since the expectation is known exactly, the state-tracking error is zero. That means the covariance matrix from the filter or smoother should be a zero matrix, which you should not be trying to invert. In a non-innovations form the state has a physical interpretation rather than being an expectation, so the state tracking error should not be degenerate in that case. I mention all this because your covariance matrix looks very close to zero. Paul Gilbert On 12/11/2015 06:00 AM, r-help-requ...@r-project.org wrote: Dear John, thank you for your considerations. This matrix (which is a variance matrix) is part of an algorithm for forward-filtering and backward-sampling of Dynamic Linear Models (West and Harrison, 1997), applied to DLM representation of ARIMA processes (Petris, Petrone, Campagnoli). It is therefore very difficult to explain why this variance matrix becomes so ill conditioned. This already happens at the first iteration of the algorithm. I will try to work on initial conditions and some fixed parameters. Thank you again Stefano __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] matrix which results singular but at the same time positive definite
Dear John and dear Peter, I needed time to understand better some practical implications derived from your hints. Thank you Stefano Da: Fox, John [j...@mcmaster.ca] Inviato: giovedì 10 dicembre 2015 17.24 A: peter dalgaard; Stefano Sofia Cc: r-help@r-project.org Oggetto: RE: [R] matrix which results singular but at the same time positive definite Dear Peter, > -Original Message- > From: peter dalgaard [mailto:pda...@gmail.com] > Sent: Thursday, December 10, 2015 11:09 AM > To: Stefano Sofia > Cc: Fox, John; r-help@r-project.org > Subject: Re: [R] matrix which results singular but at the same time > positive definite > > Looks like the ill-conditioning is almost entirely due to scaling, e.g. Yes, that's my point. Sorry I didn't make it clearer. Best, John > > > eigen(cov2cor(m)) > $values > [1] 1.7234899 1.3380701 0.6619299 0.2765101 > ... > > This is an annoyance in several parts of numerical linear algebra: > Routines assume that R^n has all coordinates on a similar scale and > therefore think that anything on the order of 1e-7 or so is effectively > zero. > > Condition numbers do this too: > > > kappa(m) > [1] 1.066582e+13 > > kappa(cov2cor(m)) > [1] 5.489243 > > > -pd > > On 10 Dec 2015, at 16:41 , Stefano Sofia > <stefano.so...@regione.marche.it> wrote: > > > Dear John, > > thank you for your considerations. > > This matrix (which is a variance matrix) is part of an algorithm for > forward-filtering and backward-sampling of Dynamic Linear Models (West > and Harrison, 1997), applied to DLM representation of ARIMA processes > (Petris, Petrone, Campagnoli). It is therefore very difficult to > explain why this variance matrix becomes so ill conditioned. This > already happens at the first iteration of the algorithm. I will try to > work on initial conditions and some fixed parameters. > > > > Thank you again > > Stefano > > > > > > > > Da: Fox, John [j...@mcmaster.ca] > > Inviato: giovedì 10 dicembre 2015 14.41 > > A: Stefano Sofia; r-help@r-project.org > > Oggetto: RE: matrix which results singular but at the same time > positivedefinite > > > > Dear Stefano, > > > > You've already had a couple of informative responses directly > addressing your question, but are you aware how ill-conditioned the > matrix is (one of the responses alluded to this)? > > > >> kappa(X, exact=TRUE) > > [1] 7.313338e+12 > > > >> eigen(X)$values > > [1] 4.964711e+00 9.356881e-01 4.863392e-12 6.788344e-13 > > > > Two of the variables have variances around 10^0 and the other two > around 10^-12. Of course, you haven't said anything about the context, > but does it really make sense to analyze the data on these scales? > > > > Best, > > John > > > > - > > John Fox, Professor > > McMaster University > > Hamilton, Ontario > > Canada L8S 4M4 > > Web: socserv.mcmaster.ca/jfox > > > > > > > > > >> -Original Message- > >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of > Stefano Sofia > >> Sent: December 10, 2015 5:08 AM > >> To: r-help@r-project.org > >> Subject: [R] matrix which results singular but at the same time > positive definite > >> > >> Dear list users, > >> through the "matrixcalc" package I am performing some checks of > variance > >> matrices (which must be positive definite). > >> In this example, it happens that the matrix A here reported is > singular but > >> positive definite. Is it possible? > >> > >> [,1] [,2] [,3] [,4] > >> [1,] 1.904255e-12 -1.904255e-12 -8.238960e-13 -1.240294e-12 [2,] - > >> 1.904255e-12 3.637979e-12 1.364242e-12 1.818989e-12 [3,] - > 8.238960e-13 > >> 1.364242e-12 4.809988e+00 7.742369e-01 [4,] -1.240294e-12 > 1.818989e-12 > >> 7.742369e-01 1.090411e+00 > >> > >> print(is.non.singular.matrix(A, tol = 1e-18)) FALSE > print(is.positive.definite(A, > >> tol=1e-18)) TRUE > >> > >> Is there something wrong with this matrix? > >> Any comment will be appreciated. > >> Stefano > >> > >> > >> > >> > >> AVVISO IMPORTANTE: Questo messaggio di posta elettronica può > contenere > >> informazioni confidenziali, pertanto è destinato solo a persone > autorizzate alla > >> rice
Re: [R] matrix which results singular but at the same time positive definite
Decrease the "tol" parameter specified into the "is.non.singular.matrix() call, for example as: m <- matrix(c( 1.904255e-12, -1.904255e-12, -8.238960e-13, -1.240294e-12, -1.904255e-12, 3.637979e-12, 1.364242e-12, 1.818989e-12, -8.238960e-13, 1.364242e-12, 4.809988e+00, 7.742369e-01, -1.240294e-12, 1.818989e-12, 7.742369e-01, 1.090411e+00), nrow=4, ncol=4) > m [,1] [,2] [,3] [,4] [1,] 1.904255e-12 -1.904255e-12 -8.238960e-13 -1.240294e-12 [2,] -1.904255e-12 3.637979e-12 1.364242e-12 1.818989e-12 [3,] -8.238960e-13 1.364242e-12 4.809988e+00 7.742369e-01 [4,] -1.240294e-12 1.818989e-12 7.742369e-01 1.090411e+00 > print(is.non.singular.matrix(m, tol = 1e-24)) [1] TRUE > print(is.positive.definite(m, tol=1e-18)) [1] TRUE -- GG http://around-r.blogspot.it [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] matrix which results singular but at the same time positive definite
Dear list users, through the "matrixcalc" package I am performing some checks of variance matrices (which must be positive definite). In this example, it happens that the matrix A here reported is singular but positive definite. Is it possible? [,1] [,2] [,3] [,4] [1,] 1.904255e-12 -1.904255e-12 -8.238960e-13 -1.240294e-12 [2,] -1.904255e-12 3.637979e-12 1.364242e-12 1.818989e-12 [3,] -8.238960e-13 1.364242e-12 4.809988e+00 7.742369e-01 [4,] -1.240294e-12 1.818989e-12 7.742369e-01 1.090411e+00 print(is.non.singular.matrix(A, tol = 1e-18)) FALSE print(is.positive.definite(A, tol=1e-18)) TRUE Is there something wrong with this matrix? Any comment will be appreciated. Stefano AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario. IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] matrix which results singular but at the same time positive definite
On 10/12/15 23:08, Stefano Sofia wrote: Dear list users, through the "matrixcalc" package I am performing some checks of variance matrices (which must be positive definite). In this example, it happens that the matrix A here reported is singular but positive definite. Is it possible? [,1] [,2] [,3] [,4] [1,] 1.904255e-12 -1.904255e-12 -8.238960e-13 -1.240294e-12 [2,] -1.904255e-12 3.637979e-12 1.364242e-12 1.818989e-12 [3,] -8.238960e-13 1.364242e-12 4.809988e+00 7.742369e-01 [4,] -1.240294e-12 1.818989e-12 7.742369e-01 1.090411e+00 print(is.non.singular.matrix(A, tol = 1e-18)) FALSE print(is.positive.definite(A, tol=1e-18)) TRUE Is there something wrong with this matrix? Any comment will be appreciated. There is nothing wrong with A (at least nothing that either a nice bowl of chicken soup or a bloody good swim wouldn't cure). Look at the code for the two functions. The tests use the tolerance in very different ways. My initial reaction is that the code for these functions is rather naive. cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] matrix which results singular but at the same time positive definite
Dear Stefano, You've already had a couple of informative responses directly addressing your question, but are you aware how ill-conditioned the matrix is (one of the responses alluded to this)? > kappa(X, exact=TRUE) [1] 7.313338e+12 > eigen(X)$values [1] 4.964711e+00 9.356881e-01 4.863392e-12 6.788344e-13 Two of the variables have variances around 10^0 and the other two around 10^-12. Of course, you haven't said anything about the context, but does it really make sense to analyze the data on these scales? Best, John - John Fox, Professor McMaster University Hamilton, Ontario Canada L8S 4M4 Web: socserv.mcmaster.ca/jfox > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Stefano Sofia > Sent: December 10, 2015 5:08 AM > To: r-help@r-project.org > Subject: [R] matrix which results singular but at the same time positive > definite > > Dear list users, > through the "matrixcalc" package I am performing some checks of variance > matrices (which must be positive definite). > In this example, it happens that the matrix A here reported is singular but > positive definite. Is it possible? > > [,1] [,2] [,3] [,4] > [1,] 1.904255e-12 -1.904255e-12 -8.238960e-13 -1.240294e-12 [2,] - > 1.904255e-12 3.637979e-12 1.364242e-12 1.818989e-12 [3,] -8.238960e-13 > 1.364242e-12 4.809988e+00 7.742369e-01 [4,] -1.240294e-12 1.818989e-12 > 7.742369e-01 1.090411e+00 > > print(is.non.singular.matrix(A, tol = 1e-18)) FALSE > print(is.positive.definite(A, > tol=1e-18)) TRUE > > Is there something wrong with this matrix? > Any comment will be appreciated. > Stefano > > > > > AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere > informazioni confidenziali, pertanto è destinato solo a persone autorizzate > alla > ricezione. I messaggi di posta elettronica per i client di Regione Marche > possono contenere informazioni confidenziali e con privilegi legali. Se non > si è il > destinatario specificato, non leggere, copiare, inoltrare o archiviare questo > messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al > mittente > ed eliminarlo completamente dal sistema del proprio computer. Ai sensi > dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed > urgenza, la risposta al presente messaggio di posta elettronica può essere > visionata da persone estranee al destinatario. > IMPORTANT NOTICE: This e-mail message is intended to be received only by > persons entitled to receive the confidential information it may contain. > E-mail > messages to clients of Regione Marche may contain information that is > confidential and legally privileged. Please do not read, copy, forward, or > store > this message unless you are an intended recipient of it. If you have received > this message in error, please forward it to the sender and delete it > completely > from your computer system. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] matrix which results singular but at the same time positive definite
Dear John, thank you for your considerations. This matrix (which is a variance matrix) is part of an algorithm for forward-filtering and backward-sampling of Dynamic Linear Models (West and Harrison, 1997), applied to DLM representation of ARIMA processes (Petris, Petrone, Campagnoli). It is therefore very difficult to explain why this variance matrix becomes so ill conditioned. This already happens at the first iteration of the algorithm. I will try to work on initial conditions and some fixed parameters. Thank you again Stefano Da: Fox, John [j...@mcmaster.ca] Inviato: giovedì 10 dicembre 2015 14.41 A: Stefano Sofia; r-help@r-project.org Oggetto: RE: matrix which results singular but at the same time positive definite Dear Stefano, You've already had a couple of informative responses directly addressing your question, but are you aware how ill-conditioned the matrix is (one of the responses alluded to this)? > kappa(X, exact=TRUE) [1] 7.313338e+12 > eigen(X)$values [1] 4.964711e+00 9.356881e-01 4.863392e-12 6.788344e-13 Two of the variables have variances around 10^0 and the other two around 10^-12. Of course, you haven't said anything about the context, but does it really make sense to analyze the data on these scales? Best, John - John Fox, Professor McMaster University Hamilton, Ontario Canada L8S 4M4 Web: socserv.mcmaster.ca/jfox > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Stefano Sofia > Sent: December 10, 2015 5:08 AM > To: r-help@r-project.org > Subject: [R] matrix which results singular but at the same time positive > definite > > Dear list users, > through the "matrixcalc" package I am performing some checks of variance > matrices (which must be positive definite). > In this example, it happens that the matrix A here reported is singular but > positive definite. Is it possible? > > [,1] [,2] [,3] [,4] > [1,] 1.904255e-12 -1.904255e-12 -8.238960e-13 -1.240294e-12 [2,] - > 1.904255e-12 3.637979e-12 1.364242e-12 1.818989e-12 [3,] -8.238960e-13 > 1.364242e-12 4.809988e+00 7.742369e-01 [4,] -1.240294e-12 1.818989e-12 > 7.742369e-01 1.090411e+00 > > print(is.non.singular.matrix(A, tol = 1e-18)) FALSE > print(is.positive.definite(A, > tol=1e-18)) TRUE > > Is there something wrong with this matrix? > Any comment will be appreciated. > Stefano > > > > > AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere > informazioni confidenziali, pertanto è destinato solo a persone autorizzate > alla > ricezione. I messaggi di posta elettronica per i client di Regione Marche > possono contenere informazioni confidenziali e con privilegi legali. Se non > si è il > destinatario specificato, non leggere, copiare, inoltrare o archiviare questo > messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al > mittente > ed eliminarlo completamente dal sistema del proprio computer. Ai sensi > dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed > urgenza, la risposta al presente messaggio di posta elettronica può essere > visionata da persone estranee al destinatario. > IMPORTANT NOTICE: This e-mail message is intended to be received only by > persons entitled to receive the confidential information it may contain. > E-mail > messages to clients of Regione Marche may contain information that is > confidential and legally privileged. Please do not read, copy, forward, or > store > this message unless you are an intended recipient of it. If you have received > this message in error, please forward it to the sender and delete it > completely > from your computer system. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008
Re: [R] matrix which results singular but at the same time positive definite
Dear Stefano, I don't really know anything about your application, but my point is about the scaling of the variables. Can't you rescale some or all of the variables so their variances aren't so different? For example, the correlation matrix among these four variables isn't ill-conditioned. Best, John > -Original Message- > From: Stefano Sofia [mailto:stefano.so...@regione.marche.it] > Sent: Thursday, December 10, 2015 10:42 AM > To: Fox, John; r-help@r-project.org > Subject: RE: matrix which results singular but at the same time positive > definite > > Dear John, > thank you for your considerations. > This matrix (which is a variance matrix) is part of an algorithm for > forward-filtering and backward-sampling of Dynamic Linear Models (West > and Harrison, 1997), applied to DLM representation of ARIMA processes > (Petris, Petrone, Campagnoli). It is therefore very difficult to > explain why this variance matrix becomes so ill conditioned. This > already happens at the first iteration of the algorithm. I will try to > work on initial conditions and some fixed parameters. > > Thank you again > Stefano > > > > Da: Fox, John [j...@mcmaster.ca] > Inviato: giovedì 10 dicembre 2015 14.41 > A: Stefano Sofia; r-help@r-project.org > Oggetto: RE: matrix which results singular but at the same time positive > definite > > Dear Stefano, > > You've already had a couple of informative responses directly addressing > your question, but are you aware how ill-conditioned the matrix is (one > of the responses alluded to this)? > > > kappa(X, exact=TRUE) > [1] 7.313338e+12 > > > eigen(X)$values > [1] 4.964711e+00 9.356881e-01 4.863392e-12 6.788344e-13 > > Two of the variables have variances around 10^0 and the other two around > 10^-12. Of course, you haven't said anything about the context, but does > it really make sense to analyze the data on these scales? > > Best, > John > > - > John Fox, Professor > McMaster University > Hamilton, Ontario > Canada L8S 4M4 > Web: socserv.mcmaster.ca/jfox > > > > > > -Original Message----- > > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of > Stefano Sofia > > Sent: December 10, 2015 5:08 AM > > To: r-help@r-project.org > > Subject: [R] matrix which results singular but at the same time > positive definite > > > > Dear list users, > > through the "matrixcalc" package I am performing some checks of > variance > > matrices (which must be positive definite). > > In this example, it happens that the matrix A here reported is > singular but > > positive definite. Is it possible? > > > > [,1] [,2] [,3] [,4] > > [1,] 1.904255e-12 -1.904255e-12 -8.238960e-13 -1.240294e-12 [2,] - > > 1.904255e-12 3.637979e-12 1.364242e-12 1.818989e-12 [3,] - > 8.238960e-13 > > 1.364242e-12 4.809988e+00 7.742369e-01 [4,] -1.240294e-12 > 1.818989e-12 > > 7.742369e-01 1.090411e+00 > > > > print(is.non.singular.matrix(A, tol = 1e-18)) FALSE > print(is.positive.definite(A, > > tol=1e-18)) TRUE > > > > Is there something wrong with this matrix? > > Any comment will be appreciated. > > Stefano > > > > > > > > > > AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere > > informazioni confidenziali, pertanto è destinato solo a persone > autorizzate alla > > ricezione. I messaggi di posta elettronica per i client di Regione > Marche > > possono contenere informazioni confidenziali e con privilegi legali. > Se non si è il > > destinatario specificato, non leggere, copiare, inoltrare o archiviare > questo > > messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al > mittente > > ed eliminarlo completamente dal sistema del proprio computer. Ai sensi > > dell'art. 6 della DGR n. 1394/2008 si segnala che, in caso di > necessità ed > > urgenza, la risposta al presente messaggio di posta elettronica può > essere > > visionata da persone estranee al destinatario. > > IMPORTANT NOTICE: This e-mail message is intended to be received only > by > > persons entitled to receive the confidential information it may > contain. E-mail > > messages to clients of Regione Marche may contain information that is > > confidential and legally privileged. Please do not read, copy, > forward, or store > > this message unless you are an intended recipient of it. If you have > receive
Re: [R] matrix which results singular but at the same time positive definite
Looks like the ill-conditioning is almost entirely due to scaling, e.g. > eigen(cov2cor(m)) $values [1] 1.7234899 1.3380701 0.6619299 0.2765101 ... This is an annoyance in several parts of numerical linear algebra: Routines assume that R^n has all coordinates on a similar scale and therefore think that anything on the order of 1e-7 or so is effectively zero. Condition numbers do this too: > kappa(m) [1] 1.066582e+13 > kappa(cov2cor(m)) [1] 5.489243 -pd On 10 Dec 2015, at 16:41 , Stefano Sofia <stefano.so...@regione.marche.it> wrote: > Dear John, > thank you for your considerations. > This matrix (which is a variance matrix) is part of an algorithm for > forward-filtering and backward-sampling of Dynamic Linear Models (West and > Harrison, 1997), applied to DLM representation of ARIMA processes (Petris, > Petrone, Campagnoli). It is therefore very difficult to explain why this > variance matrix becomes so ill conditioned. This already happens at the first > iteration of the algorithm. I will try to work on initial conditions and some > fixed parameters. > > Thank you again > Stefano > > > > Da: Fox, John [j...@mcmaster.ca] > Inviato: giovedì 10 dicembre 2015 14.41 > A: Stefano Sofia; r-help@r-project.org > Oggetto: RE: matrix which results singular but at the same time positive > definite > > Dear Stefano, > > You've already had a couple of informative responses directly addressing your > question, but are you aware how ill-conditioned the matrix is (one of the > responses alluded to this)? > >> kappa(X, exact=TRUE) > [1] 7.313338e+12 > >> eigen(X)$values > [1] 4.964711e+00 9.356881e-01 4.863392e-12 6.788344e-13 > > Two of the variables have variances around 10^0 and the other two around > 10^-12. Of course, you haven't said anything about the context, but does it > really make sense to analyze the data on these scales? > > Best, > John > > - > John Fox, Professor > McMaster University > Hamilton, Ontario > Canada L8S 4M4 > Web: socserv.mcmaster.ca/jfox > > > > >> -Original Message----- >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Stefano Sofia >> Sent: December 10, 2015 5:08 AM >> To: r-help@r-project.org >> Subject: [R] matrix which results singular but at the same time positive >> definite >> >> Dear list users, >> through the "matrixcalc" package I am performing some checks of variance >> matrices (which must be positive definite). >> In this example, it happens that the matrix A here reported is singular but >> positive definite. Is it possible? >> >> [,1] [,2] [,3] [,4] >> [1,] 1.904255e-12 -1.904255e-12 -8.238960e-13 -1.240294e-12 [2,] - >> 1.904255e-12 3.637979e-12 1.364242e-12 1.818989e-12 [3,] -8.238960e-13 >> 1.364242e-12 4.809988e+00 7.742369e-01 [4,] -1.240294e-12 1.818989e-12 >> 7.742369e-01 1.090411e+00 >> >> print(is.non.singular.matrix(A, tol = 1e-18)) FALSE >> print(is.positive.definite(A, >> tol=1e-18)) TRUE >> >> Is there something wrong with this matrix? >> Any comment will be appreciated. >> Stefano >> >> >> >> >> AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere >> informazioni confidenziali, pertanto è destinato solo a persone autorizzate >> alla >> ricezione. I messaggi di posta elettronica per i client di Regione Marche >> possono contenere informazioni confidenziali e con privilegi legali. Se non >> si è il >> destinatario specificato, non leggere, copiare, inoltrare o archiviare questo >> messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al >> mittente >> ed eliminarlo completamente dal sistema del proprio computer. Ai sensi >> dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed >> urgenza, la risposta al presente messaggio di posta elettronica può essere >> visionata da persone estranee al destinatario. >> IMPORTANT NOTICE: This e-mail message is intended to be received only by >> persons entitled to receive the confidential information it may contain. >> E-mail >> messages to clients of Regione Marche may contain information that is >> confidential and legally privileged. Please do not read, copy, forward, or >> store >> this message unless you are an intended recipient of it. If you have received >> this message in error, please forward it to the sender and delete it >> completely >> from
Re: [R] matrix which results singular but at the same time positive definite
Dear Peter, > -Original Message- > From: peter dalgaard [mailto:pda...@gmail.com] > Sent: Thursday, December 10, 2015 11:09 AM > To: Stefano Sofia > Cc: Fox, John; r-help@r-project.org > Subject: Re: [R] matrix which results singular but at the same time > positive definite > > Looks like the ill-conditioning is almost entirely due to scaling, e.g. Yes, that's my point. Sorry I didn't make it clearer. Best, John > > > eigen(cov2cor(m)) > $values > [1] 1.7234899 1.3380701 0.6619299 0.2765101 > ... > > This is an annoyance in several parts of numerical linear algebra: > Routines assume that R^n has all coordinates on a similar scale and > therefore think that anything on the order of 1e-7 or so is effectively > zero. > > Condition numbers do this too: > > > kappa(m) > [1] 1.066582e+13 > > kappa(cov2cor(m)) > [1] 5.489243 > > > -pd > > On 10 Dec 2015, at 16:41 , Stefano Sofia > <stefano.so...@regione.marche.it> wrote: > > > Dear John, > > thank you for your considerations. > > This matrix (which is a variance matrix) is part of an algorithm for > forward-filtering and backward-sampling of Dynamic Linear Models (West > and Harrison, 1997), applied to DLM representation of ARIMA processes > (Petris, Petrone, Campagnoli). It is therefore very difficult to > explain why this variance matrix becomes so ill conditioned. This > already happens at the first iteration of the algorithm. I will try to > work on initial conditions and some fixed parameters. > > > > Thank you again > > Stefano > > > > > > > > Da: Fox, John [j...@mcmaster.ca] > > Inviato: giovedì 10 dicembre 2015 14.41 > > A: Stefano Sofia; r-help@r-project.org > > Oggetto: RE: matrix which results singular but at the same time > positivedefinite > > > > Dear Stefano, > > > > You've already had a couple of informative responses directly > addressing your question, but are you aware how ill-conditioned the > matrix is (one of the responses alluded to this)? > > > >> kappa(X, exact=TRUE) > > [1] 7.313338e+12 > > > >> eigen(X)$values > > [1] 4.964711e+00 9.356881e-01 4.863392e-12 6.788344e-13 > > > > Two of the variables have variances around 10^0 and the other two > around 10^-12. Of course, you haven't said anything about the context, > but does it really make sense to analyze the data on these scales? > > > > Best, > > John > > > > - > > John Fox, Professor > > McMaster University > > Hamilton, Ontario > > Canada L8S 4M4 > > Web: socserv.mcmaster.ca/jfox > > > > > > > > > >> -Original Message- > >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of > Stefano Sofia > >> Sent: December 10, 2015 5:08 AM > >> To: r-help@r-project.org > >> Subject: [R] matrix which results singular but at the same time > positive definite > >> > >> Dear list users, > >> through the "matrixcalc" package I am performing some checks of > variance > >> matrices (which must be positive definite). > >> In this example, it happens that the matrix A here reported is > singular but > >> positive definite. Is it possible? > >> > >> [,1] [,2] [,3] [,4] > >> [1,] 1.904255e-12 -1.904255e-12 -8.238960e-13 -1.240294e-12 [2,] - > >> 1.904255e-12 3.637979e-12 1.364242e-12 1.818989e-12 [3,] - > 8.238960e-13 > >> 1.364242e-12 4.809988e+00 7.742369e-01 [4,] -1.240294e-12 > 1.818989e-12 > >> 7.742369e-01 1.090411e+00 > >> > >> print(is.non.singular.matrix(A, tol = 1e-18)) FALSE > print(is.positive.definite(A, > >> tol=1e-18)) TRUE > >> > >> Is there something wrong with this matrix? > >> Any comment will be appreciated. > >> Stefano > >> > >> > >> > >> > >> AVVISO IMPORTANTE: Questo messaggio di posta elettronica può > contenere > >> informazioni confidenziali, pertanto è destinato solo a persone > autorizzate alla > >> ricezione. I messaggi di posta elettronica per i client di Regione > Marche > >> possono contenere informazioni confidenziali e con privilegi legali. > Se non si è il > >> destinatario specificato, non leggere, copiare, inoltrare o > archiviare questo > >> messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo > al mittente > >