[R-br] Calculo de correlcao entre coluas que apresentam NAS de varias matrizes

Éder Comunello comunello.eder em gmail.com
Quinta Março 19 15:40:23 BRT 2015


Michelle,

Aproveitando seu código inicial, pensei em algo assim...

### <code r>
urls1 <- c("
https://www.dropbox.com/s/kgxo3s8qrrv74p3/AAparaCalculodaMedia.txt",
          "
https://www.dropbox.com/s/fhutciprhgt077x/AIGparaCalculodaMedia.txt",
          "
https://www.dropbox.com/s/kvubgji1tce8sm8/AXPparaCalculodaMedia.txt")

urls2 <- sub("^.*/s/", "http://dl.dropbox.com/s/", urls1)

AA  <- read.table(urls2[1], header=T, as.is=T)
AIG <- read.table(urls2[2], header=T, as.is=T)
AXP <- read.table(urls2[3], header=T, as.is=T)

Symbols <- c("AA", "AIG", "AXP")
sapply(Symbols, function(x) length(get(x)))
sapply(Symbols, function(x) nrow(get(x)))
sapply(Symbols, function(x) tail(names(get(x)),1))

### Correlações entre leituras diferentes da mesma empresa
cor(AA[2:394],   use="pairwise.complete.obs")
cor(AIG[2:394],  use="pairwise.complete.obs")
cor(AXP[2:394],  use="pairwise.complete.obs")

### Correlações entre mesma leitura das diferentes empresas
### Testando com 4 matrizes
Symbols <- c("AA", "AIG", "AXP", "AXP")

COR <- NULL
for (i in 2:394) {
     DAT <- NULL
     for (a in Symbols) {
          col <- get(a)[,i]
          DAT <- cbind(DAT, col)
     }
     lin <- cbind(ID=i, cor(DAT,  use="pairwise.complete.obs"))
     colnames(lin) <- c("ID", Symbols)
     COR <- rbind(COR, lin)
}

### As 4 matrizes originariam  uma matriz cor 4x4 para cada leitura
### As matrizes cor foram empilhadas em uma saída única (COR), onde
### cada 4 linhas são referentes à uma leitura identificada por ID.

head(COR)
#     ID          AA         AIG          AXP          AXP
# col  2  1.00000000  0.64408120 -0.088884203 -0.088884203
# col  2  0.64408120  1.00000000 -0.109883913 -0.109883913
# col  2 -0.08888420 -0.10988391  1.000000000  1.000000000
# col  2 -0.08888420 -0.10988391  1.000000000  1.000000000
# col  3  1.00000000  0.01779314  0.003447422  0.003447422
# col  3  0.01779314  1.00000000  0.158657131  0.158657131
### </code>


Éder Comunello <c <comunello.eder em gmail.com>omunello.eder em gmail.com>
Dourados, MS - [22 16.5'S, 54 49'W]
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://listas.inf.ufpr.br/pipermail/r-br/attachments/20150319/70cf60a1/attachment.html>


Mais detalhes sobre a lista de discussão R-br