---------- Forwarded message ----------
From: <r-help-bounces@r-project.org>
Date: Mon, May 11, 2009 at 10:24 PM
Subject: The results of your email commands
To: das.moumita.online@gmail.com


The results of your email command are provided below. Attached is your
original message.

- Results:
   Ignoring non-text/plain MIME parts

- Unprocessed:
   What is the function for partial correlation.The function which i found
   here:-- http://www.yilab.gatech.edu/pcor.R    and used the recursive
   version, showed errors while computing partial correlation,where the
third
   variable i.e controlled variable for a pair is more than that .That is
when
   i had more than one third variable ,it always became an infinite loop,it
   else.
   # By using recursive formula
   pcor.rec <- function(x,y,z,method="p",na.rm=T){
       #
       x <- c(x)
       y <- c(y)
       z <- as.data.frame(z)
       if(dim(z)[2] == 0){
               stop("There should be given data\n")
       }
       data <- data.frame(x,y,z)
       if(na.rm == T){
               data = na.omit(data)
       }

- Ignored:

       # recursive formula
       if(dim(z)[2] == 1){
               tdata <- na.omit(data.frame(data[,1],data[,2]))
               rxy <- cor(tdata[,1],tdata[,2],m=method)

               tdata <- na.omit(data.frame(data[,1],data[,-c(1,2)]))
               rxz <- cor(tdata[,1],tdata[,2],m=method)

               tdata <- na.omit(data.frame(data[,2],data[,-c(1,2)]))
               ryz <- cor(tdata[,1],tdata[,2],m=method)

               rxy.z <- (rxy - rxz*ryz)/( sqrt(1-rxz^2)*sqrt(1-ryz^2) )

               return(rxy.z)
       }else{
               x <- c(data[,1])
               y <- c(data[,2])
               z0 <- c(data[,3])
               zc <- as.data.frame(data[,-c(1,2,3)])

               rxy.zc <- pcor.rec(x,y,zc,method=method,na.rm=na.rm)
               rxz0.zc <- pcor.rec(x,z0,zc,method=method,na.rm=na.rm)
               ryz0.zc <- pcor.rec(y,z0,zc,method=method,na.rm=na.rm)

               rxy.z <- (rxy.zc - rxz0.zc*ryz0.zc)/(
sqrt(1-rxz0.zc^2)*sqrt(1-ryz0.zc^2) )
               return(rxy.z)
       }
   }

   and this piece of code also i tried to use.

   Rinv <- solve <http://wiki.r-project.org/rwiki/rhelp.php?id=solve>(R)
   D <- diag <http://wiki.r-project.org/rwiki/rhelp.php?id=diag>(1 / sqrt
   <http://wiki.r-project.org/rwiki/rhelp.php?id=sqrt>(diag
   <http://wiki.r-project.org/rwiki/rhelp.php?id=diag>(Rinv)))
   P <- -D <http://wiki.r-project.org/rwiki/rhelp.php?id=D> %*% Rinv %*%
   D <http://wiki.r-project.org/rwiki/rhelp.php?id=D>

   where R is teh correlation matrix.
   but NaN error at for
   sqrt <http://wiki.r-project.org/rwiki/rhelp.php?id=sqrt>(diag
   <http://wiki.r-project.org/rwiki/rhelp.php?id=diag>(Rinv) were
   generated.





http://wiki.r-project.org/rwiki/doku.php?id=tips:data-matrices:part_corr&s=correlation


   Any convinient function for partial correlation for both one
   controlled variable or more.



   --
   Thanks
   Moumita

- Done.



---------- Forwarded message ----------
From: Moumita Das <das.moumita.online@gmail.com>
To: r-help-request@r-project.org
Date: Mon, 11 May 2009 22:23:33 +0530
Subject: partial correlation function
Hi friends,
What is the function for partial correlation.The function which i found
here:-- http://www.yilab.gatech.edu/pcor.R    and used the recursive
version, showed errors while computing partial correlation,where the third
variable i.e controlled variable for a pair is more than that .That is when
i had more than one third variable ,it always became an infinite loop,it
else.

# By using recursive formula
pcor.rec <- function(x,y,z,method="p",na.rm=T){
	#

	x <- c(x)
	y <- c(y)
	z <- as.data.frame(z)

	if(dim(z)[2] == 0){
		stop("There should be given data\n")

	}

	data <- data.frame(x,y,z)

	if(na.rm == T){
		data = na.omit(data)
	}

	# recursive formula
	if(dim(z)[2] == 1){
		tdata <- na.omit(data.frame(data[,1],data[,2]))
		rxy <- cor(tdata[,1],tdata[,2],m=method)

		tdata <- na.omit(data.frame(data[,1],data[,-c(1,2)]))
		rxz <- cor(tdata[,1],tdata[,2],m=method)

		tdata <- na.omit(data.frame(data[,2],data[,-c(1,2)]))
		ryz <- cor(tdata[,1],tdata[,2],m=method)

		rxy.z <- (rxy - rxz*ryz)/( sqrt(1-rxz^2)*sqrt(1-ryz^2) )
		
		return(rxy.z)
	}else{
		x <- c(data[,1])
		y <- c(data[,2])
		z0 <- c(data[,3])
		zc <- as.data.frame(data[,-c(1,2,3)])

		rxy.zc <- pcor.rec(x,y,zc,method=method,na.rm=na.rm)
		rxz0.zc <- pcor.rec(x,z0,zc,method=method,na.rm=na.rm)
		ryz0.zc <- pcor.rec(y,z0,zc,method=method,na.rm=na.rm)
		
		rxy.z <- (rxy.zc - rxz0.zc*ryz0.zc)/( sqrt(1-rxz0.zc^2)*sqrt(1-ryz0.zc^2) )

		return(rxy.z)
	}			
}	

and this piece of code also i tried to use.

Rinv <- solve <http://wiki.r-project.org/rwiki/rhelp.php?id=solve>(R)
D <- diag <http://wiki.r-project.org/rwiki/rhelp.php?id=diag>(1 / sqrt
<http://wiki.r-project.org/rwiki/rhelp.php?id=sqrt>(diag
<http://wiki.r-project.org/rwiki/rhelp.php?id=diag>(Rinv)))
P <- -D <http://wiki.r-project.org/rwiki/rhelp.php?id=D> %*% Rinv %*%
D <http://wiki.r-project.org/rwiki/rhelp.php?id=D>

where R is teh correlation matrix.
but NaN error at for
sqrt <http://wiki.r-project.org/rwiki/rhelp.php?id=sqrt>(diag
<http://wiki.r-project.org/rwiki/rhelp.php?id=diag>(Rinv) were
generated.




http://wiki.r-project.org/rwiki/doku.php?id=tips:data-matrices:part_corr&s=correlation



Any convinient function for partial correlation for both one
controlled variable or more.



-- 
Thanks
Moumita




-- 
Thanks
Moumita

	[[alternative HTML version deleted]]


