Re: [R] positive semi-definite matrix
Martin, You are most welcome. I apologize for my faux pas. I really did mean to say "Matrix" package, but got sloppy! There is also another (more recent) article by Higham: http://www.maths.man.ac.uk/~nareports/narep369.pdf Best, Ravi. -- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html -- > -Original Message- > From: Martin Maechler [mailto:[EMAIL PROTECTED] > Sent: Friday, July 21, 2006 1:14 PM > To: Ravi Varadhan > Cc: 'Duncan Murdoch'; 'roger bos'; 'RHelp'; [EMAIL PROTECTED] > Subject: Re: [R] positive semi-definite matrix > > >>>>> "Ravi" == Ravi Varadhan <[EMAIL PROTECTED]> > >>>>> on Fri, 21 Jul 2006 11:33:23 -0400 writes: > > Ravi> There is a paper by N.J. Higham (SIAM J Matrix Anal, > Ravi> 1998) on a modified cholesky decomposition of > Ravi> symmetric and not necessarily positive definite matrix > Ravi> (say, A), with an important goal of producing a > Ravi> "small-normed" perturbation of A (say, delA), that > Ravi> makes (A + delA) positive definite. > > Ravi> http://epubs.siam.org/sam-bin/dbq/article/30289 > > Ravi> There is also an algorithm in Gill, Murray and > Ravi> Wright's text - Practical Optimization (section > Ravi> 4.4.2). > > Thanks a lot, Ravi, > for the interesting references, in the past I once had looked > for such things but did not find any --- most probably because I > used wrong keywords. > > Ravi> These may be relevant to your problem. I am not sure > Ravi> if these algorithms have been implemented in R, for > Ravi> example, in the "matrix" library. > > O... ! It's "Matrix" and `package', yes `package', yes `package' .. > > but no, it hasn't been implemented there yet, AFAIK. > OTOH, it's not a bad idea to do there, since it's building on > the LDL' cholesky factorization which we are using > in "Matrix" in other places anyway. > > Thanks again for your help! > Martin Maechler, ETH Zurich > > Ravi> > -- > Ravi> Ravi Varadhan, Ph.D. > Ravi> Assistant Professor, The Center on Aging and Health > Ravi> Division of Geriatric Medicine and Gerontology > Ravi> Johns Hopkins University > Ravi> Ph: (410) 502-2619 > Ravi> Fax: (410) 614-9625 > Ravi> Email: [EMAIL PROTECTED] > Ravi> Webpage: > http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html > Ravi> > -- > > >> -Original Message- > >> From: [EMAIL PROTECTED] [mailto:r-help- > >> [EMAIL PROTECTED] On Behalf Of Duncan Murdoch > >> Sent: Friday, July 21, 2006 9:45 AM > >> To: roger bos > >> Cc: RHelp > >> Subject: Re: [R] positive semi-definite matrix > >> > >> On 7/21/2006 8:59 AM, roger bos wrote: > >> > I have a covariance matrix that is not positive semi-definite > matrix and > >> I > >> > need it to be via some sort of adjustment. Is there any R > routine or > >> > package to help me do this? > >> > >> I think you need to be more specific about what have and what you > want, > >> but if the matrix is symmetric and nearly positive semi-definite > (but > >> not exactly because of rounding error), you might try something > like > >> > >> fixit <- function(A) { > >> eig <- eigen(A, symmetric = TRUE) > >> eig$values <- pmax(0, eig$values) > >> return(eig$vectors %*% diag(eig$values) %*% t(eig$vectors)) > >> } > >> > >> Rounding error means this is not guaranteed to be positive > >> semi-definite, but it will be very close. > >> > >> Duncan Murdoch > __ R-help@stat.math.ethz.ch mailing list 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] positive semi-definite matrix
>>>>> "Ravi" == Ravi Varadhan <[EMAIL PROTECTED]> >>>>> on Fri, 21 Jul 2006 11:33:23 -0400 writes: Ravi> There is a paper by N.J. Higham (SIAM J Matrix Anal, Ravi> 1998) on a modified cholesky decomposition of Ravi> symmetric and not necessarily positive definite matrix Ravi> (say, A), with an important goal of producing a Ravi> "small-normed" perturbation of A (say, delA), that Ravi> makes (A + delA) positive definite. Ravi> http://epubs.siam.org/sam-bin/dbq/article/30289 Ravi> There is also an algorithm in Gill, Murray and Ravi> Wright's text - Practical Optimization (section Ravi> 4.4.2). Thanks a lot, Ravi, for the interesting references, in the past I once had looked for such things but did not find any --- most probably because I used wrong keywords. Ravi> These may be relevant to your problem. I am not sure Ravi> if these algorithms have been implemented in R, for Ravi> example, in the "matrix" library. O... ! It's "Matrix" and `package', yes `package', yes `package' .. but no, it hasn't been implemented there yet, AFAIK. OTOH, it's not a bad idea to do there, since it's building on the LDL' cholesky factorization which we are using in "Matrix" in other places anyway. Thanks again for your help! Martin Maechler, ETH Zurich Ravi> -- Ravi> Ravi Varadhan, Ph.D. Ravi> Assistant Professor, The Center on Aging and Health Ravi> Division of Geriatric Medicine and Gerontology Ravi> Johns Hopkins University Ravi> Ph: (410) 502-2619 Ravi> Fax: (410) 614-9625 Ravi> Email: [EMAIL PROTECTED] Ravi> Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html Ravi> -- >> -Original Message----- >> From: [EMAIL PROTECTED] [mailto:r-help- >> [EMAIL PROTECTED] On Behalf Of Duncan Murdoch >> Sent: Friday, July 21, 2006 9:45 AM >> To: roger bos >> Cc: RHelp >> Subject: Re: [R] positive semi-definite matrix >> >> On 7/21/2006 8:59 AM, roger bos wrote: >> > I have a covariance matrix that is not positive semi-definite matrix and >> I >> > need it to be via some sort of adjustment. Is there any R routine or >> > package to help me do this? >> >> I think you need to be more specific about what have and what you want, >> but if the matrix is symmetric and nearly positive semi-definite (but >> not exactly because of rounding error), you might try something like >> >> fixit <- function(A) { >> eig <- eigen(A, symmetric = TRUE) >> eig$values <- pmax(0, eig$values) >> return(eig$vectors %*% diag(eig$values) %*% t(eig$vectors)) >> } >> >> Rounding error means this is not guaranteed to be positive >> semi-definite, but it will be very close. >> >> Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list 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] positive semi-definite matrix
There is a paper by N.J. Higham (SIAM J Matrix Anal, 1998) on a modified cholesky decomposition of symmetric and not necessarily positive definite matrix (say, A), with an important goal of producing a "small-normed" perturbation of A (say, delA), that makes (A + delA) positive definite. http://epubs.siam.org/sam-bin/dbq/article/30289 There is also an algorithm in Gill, Murray and Wright's text - Practical Optimization (section 4.4.2). These may be relevant to your problem. I am not sure if these algorithms have been implemented in R, for example, in the "matrix" library. Ravi. -- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html -- > -Original Message- > From: [EMAIL PROTECTED] [mailto:r-help- > [EMAIL PROTECTED] On Behalf Of Duncan Murdoch > Sent: Friday, July 21, 2006 9:45 AM > To: roger bos > Cc: RHelp > Subject: Re: [R] positive semi-definite matrix > > On 7/21/2006 8:59 AM, roger bos wrote: > > I have a covariance matrix that is not positive semi-definite matrix and > I > > need it to be via some sort of adjustment. Is there any R routine or > > package to help me do this? > > I think you need to be more specific about what have and what you want, > but if the matrix is symmetric and nearly positive semi-definite (but > not exactly because of rounding error), you might try something like > > fixit <- function(A) { >eig <- eigen(A, symmetric = TRUE) >eig$values <- pmax(0, eig$values) >return(eig$vectors %*% diag(eig$values) %*% t(eig$vectors)) > } > > Rounding error means this is not guaranteed to be positive > semi-definite, but it will be very close. > > Duncan Murdoch > > __ > R-help@stat.math.ethz.ch mailing list > 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@stat.math.ethz.ch mailing list 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] positive semi-definite matrix
Take a look at make.positive.definite in the corpcor package. The implementation is very similar to what Duncan suggested. Regards, Francisco Dr. Francisco J. Zagmutt College of Veterinary Medicine and Biomedical Sciences Colorado State University >From: Duncan Murdoch <[EMAIL PROTECTED]> >To: roger bos <[EMAIL PROTECTED]> >CC: RHelp >Subject: Re: [R] positive semi-definite matrix >Date: Fri, 21 Jul 2006 09:44:42 -0400 > >On 7/21/2006 8:59 AM, roger bos wrote: > > I have a covariance matrix that is not positive semi-definite matrix and >I > > need it to be via some sort of adjustment. Is there any R routine or > > package to help me do this? > >I think you need to be more specific about what have and what you want, >but if the matrix is symmetric and nearly positive semi-definite (but >not exactly because of rounding error), you might try something like > >fixit <- function(A) { >eig <- eigen(A, symmetric = TRUE) >eig$values <- pmax(0, eig$values) >return(eig$vectors %*% diag(eig$values) %*% t(eig$vectors)) >} > >Rounding error means this is not guaranteed to be positive >semi-definite, but it will be very close. > >Duncan Murdoch > >__ >R-help@stat.math.ethz.ch mailing list >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@stat.math.ethz.ch mailing list 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] positive semi-definite matrix
> "Duncan" == Duncan Murdoch <[EMAIL PROTECTED]> > on Fri, 21 Jul 2006 09:44:42 -0400 writes: Duncan> On 7/21/2006 8:59 AM, roger bos wrote: >> I have a covariance matrix that is not positive semi-definite matrix and I >> need it to be via some sort of adjustment. Is there any R routine or >> package to help me do this? Duncan> I think you need to be more specific about what have and what you want, Duncan> but if the matrix is symmetric and nearly positive semi-definite (but Duncan> not exactly because of rounding error), you might try something like Duncan> fixit <- function(A) { Duncan> eig <- eigen(A, symmetric = TRUE) Duncan> eig$values <- pmax(0, eig$values) Duncan> return(eig$vectors %*% diag(eig$values) %*% t(eig$vectors)) Duncan> } Duncan> Rounding error means this is not guaranteed to be positive Duncan> semi-definite, but it will be very close. A slightly more general and stable version of the above is available via sfsmisc::posdefify(.) : install.packages("sfsmisc") ?posdefify Martin Maechler, ETH Zurich __ R-help@stat.math.ethz.ch mailing list 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] positive semi-definite matrix
On 7/21/2006 8:59 AM, roger bos wrote: > I have a covariance matrix that is not positive semi-definite matrix and I > need it to be via some sort of adjustment. Is there any R routine or > package to help me do this? I think you need to be more specific about what have and what you want, but if the matrix is symmetric and nearly positive semi-definite (but not exactly because of rounding error), you might try something like fixit <- function(A) { eig <- eigen(A, symmetric = TRUE) eig$values <- pmax(0, eig$values) return(eig$vectors %*% diag(eig$values) %*% t(eig$vectors)) } Rounding error means this is not guaranteed to be positive semi-definite, but it will be very close. Duncan Murdoch __ R-help@stat.math.ethz.ch mailing list 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] positive semi-definite matrix
I have a covariance matrix that is not positive semi-definite matrix and I need it to be via some sort of adjustment. Is there any R routine or package to help me do this? Thanks, Roger [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list 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.