Ok, Thanks foe the answer, Ken: *1L, 2L etc are integers. (That is, identical to as.integer(1) , as.integer(2) etc) Using integers (instead of "numeric" type) is more efficient as here they're used as indexes and would be converted to integer anyway. Compare> is(1)... and> is(1L)1L:p is the sequence 1, 2, 3, ..., p (just like 1:p) Just for curiosity, what is findFn('cov2cor') ? Regards, Kenn* I don't know what findFn('cov2cor') is, I'm a total newbie to R but I created a new, simpler to my opinion function for some descriptive statistics as matrix functions for a matrix called "x": one1=c(rep(1, nrow(x))) means <- t(one1)%*%x/3#row vector of means M=one1%*%means#A ?? ? ?? matrix ?? where each column is filled with the mean value for that column D=x-M#deviation matrix S=(t(D)%*%D)/(nrow(x)-1)#Covariance matrix R=function(S){###R is a Correlation matrix### V=matrix(nrow=nrow(S),ncol=ncol(S)) V1 <- sqrt(1/diag(S)) diag(V)=V1 V[is.na(V)]=0 R=V%*%S%*%V return(R) } R(S) -- View this message in context: http://r.789695.n4.nabble.com/cov2cor-exp-tp4676395p4676450.html Sent from the R help mailing list archive at Nabble.com.
Hello, I am just wondering why to reinvent the wheel? Regards, Pascal 2013/9/19 wacguy <gw57@duke.edu>> Ok, Thanks foe the answer, Ken: > > *1L, 2L etc are integers. (That is, identical to as.integer(1) , > as.integer(2) etc) > > Using integers (instead of "numeric" type) is more efficient as here > they're > used as indexes and would be converted to integer anyway. > > Compare > > is(1) > ... and > > is(1L) > > 1L:p is the sequence 1, 2, 3, ..., p (just like 1:p) > > Just for curiosity, what is findFn('cov2cor') ? > > Regards, > Kenn* > > I don't know what findFn('cov2cor') is, I'm a total newbie to R but I > created a new, simpler to my opinion function for some descriptive > statistics as matrix functions for a matrix called "x": > > one1=c(rep(1, nrow(x))) > means <- t(one1)%*%x/3#row vector of means > M=one1%*%means#A 𝑛 × 𝑝 matrix 𝑀 where each column is filled with the > mean > value for that column > D=x-M#deviation matrix > S=(t(D)%*%D)/(nrow(x)-1)#Covariance matrix > > R=function(S){###R is a Correlation matrix### > V=matrix(nrow=nrow(S),ncol=ncol(S)) > V1 <- sqrt(1/diag(S)) > diag(V)=V1 > V[is.na(V)]=0 > R=V%*%S%*%V > return(R) > } > R(S) > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/cov2cor-exp-tp4676395p4676450.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. >-- Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan [[alternative HTML version deleted]]
Hello, Asking help for homework is prohibited on this list. Regards, Pascal 2013/9/19 Guy Wachsman <guy.wachsmann@duke.edu>> Hi Pascal, > > The first reason is that it was a homework assignment, the second it > that this function is based on the algebraic equation for correlation > matrix (given to us by the instructor, not my initiative) and to me (and > probably to others) it is nice to see the correlation. > > Cheers, > Guy > > -- > Guy Wachsman > Benfey lab, FFSC #4131, Duke > 130 Science Drive > 27708, Durham, NC > email: gw57@duke.edu > > ------------------------------ > *From:* skalp.oettli@gmail.com [skalp.oettli@gmail.com] on behalf of > Pascal Oettli [kridox@ymail.com] > *Sent:* Wednesday, September 18, 2013 8:20 PM > *To:* wacguy > *Cc:* r-help > *Subject:* Re: [R] cov2cor exp > > Hello, > > I am just wondering why to reinvent the wheel? > > Regards, > Pascal > > > 2013/9/19 wacguy <gw57@duke.edu> > >> Ok, Thanks foe the answer, Ken: >> >> *1L, 2L etc are integers. (That is, identical to as.integer(1) , >> as.integer(2) etc) >> >> Using integers (instead of "numeric" type) is more efficient as here >> they're >> used as indexes and would be converted to integer anyway. >> >> Compare >> > is(1) >> ... and >> > is(1L) >> >> 1L:p is the sequence 1, 2, 3, ..., p (just like 1:p) >> >> Just for curiosity, what is findFn('cov2cor') ? >> >> Regards, >> Kenn* >> >> I don't know what findFn('cov2cor') is, I'm a total newbie to R but I >> created a new, simpler to my opinion function for some descriptive >> statistics as matrix functions for a matrix called "x": >> >> one1=c(rep(1, nrow(x))) >> means <- t(one1)%*%x/3#row vector of means >> M=one1%*%means#A 𝑛 × 𝑝 matrix 𝑀 where each column is filled with the >> mean >> value for that column >> D=x-M#deviation matrix >> S=(t(D)%*%D)/(nrow(x)-1)#Covariance matrix >> >> R=function(S){###R is a Correlation matrix### >> V=matrix(nrow=nrow(S),ncol=ncol(S)) >> V1 <- sqrt(1/diag(S)) >> diag(V)=V1 >> V[is.na(V)]=0 >> R=V%*%S%*%V >> return(R) >> } >> R(S) >> >> >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/cov2cor-exp-tp4676395p4676450.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help@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. >> > > > > -- > Pascal Oettli > Project Scientist > JAMSTEC > Yokohama, Japan >-- Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan [[alternative HTML version deleted]]
Seemingly Similar Threads
- error: Error in if (is.na(f0$objective)) { : argument is of length zero
- modes of objects
- Compute a correlation matrix from an existing covariance matrix
- Error: system is computationally singular: reciprocal condition number
- Converting variance covariance matrix to correlation matrix