[R] Calculating interval for conditional/unconditional correlation matrix
Moshe Olshansky
m_olshansky at yahoo.com
Mon Sep 22 04:54:28 CEST 2008
Hi Ana,
There are two problems:
First of all, if you want your matrix to have 4 columns it's number of elements should not be 17!
Secondly, and this is what causes your error message, you should not call your second function matrix. Call it matrix1, my_matrix, whatever. Otherwise R thinks that you are calling your matrix function within itself.
--- On Sun, 21/9/08, Ana Kolar <annakolar at yahoo.com> wrote:
> From: Ana Kolar <annakolar at yahoo.com>
> Subject: [R] Calculating interval for conditional/unconditional correlation matrix
> To: "R" <r-help at r-project.org>
> Received: Sunday, 21 September, 2008, 8:05 PM
> Hi there,
>
> Could anyone please help me to understand what should be
> done in order not to get this error message: Error:
> evaluation nested too deeply: infinite recursion /
> options(expressions=)?
>
> Here is my code:
>
> determinant<-
> function(x){det(matrix(c(1.0,0.2,0.5,0.8,0.2,1.0,0.5,0.6,0.5,0.5,0.5,1.0,x,0.8,0.6,x,1.0),ncol=4,byrow=T))}
>
> matrix<-
> function(x){(matrix(c(1.0,0.2,0.5,0.8,0.2,1.0,0.5,0.6,0.5,0.5,0.5,1.0,x,0.8,0.6,x,1.0),ncol=4,byrow=T))}
>
>
> conditional<-function(x,varcov){
> varcov<-matrix(x)
> sigmaxx<-varcov[3,3]
> sigmaxz<-varcov[3,1:2]
> sigmayy<-varcov[4,4]
> sigmayz<-varcov[4,1:2]
> sigmazx<-varcov[1:2,3]
> sigmazy<-varcov[1:2,4]
> sigmazz<-varcov[1:2,1:2]
>
> (x-sigmaxz%*%solve(sigmaZZ)%*%sigmazy)/sqrt((sigmaxx-sigmaxz%*%solve(sigmaZZ)%*%sigmazx)*(sigmayy-sigmayz%*%solve(sigmaZZ)%*%sigmazy))}
>
> interval<-uniroot(determinant,lower = min(c(0,1)), upper
> = max(c(0,1)))
>
> I tried also with the code below, but got the same Error
> message.
>
> lower.bound<-uniroot(determinant,c(0,0.5))$root
> upper.bound<-uniroot(determinant,c(0.51,1))$root
>
>
> Your help will be greatly appreciate!
>
> Ana
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
More information about the R-help
mailing list