Last active
August 29, 2015 14:08
-
-
Save aa989190f363e46d/36b0d87df8611d7145b6 to your computer and use it in GitHub Desktop.
ariel32.post241967
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library('dplyr') | |
library('corrplot') | |
d = read.csv("data.csv", sep = ";", skip = 1) # загружаем данные | |
# присваиваем удобочитаемые имена | |
names(d) <- c("time" , "oil" , "gold" , "iron" , "logs", | |
"maize" , "beef" , "chicken" , "gas" , "liquid_gas", | |
"tea" , "tobacco" , "wheat" , "sugar" , "soy", | |
"silver" , "rice" , "platinum" , "cotton" , "copper", | |
"coffee" , "coal" , "aluminum") | |
# в своем посте автор использовал среднее геометрическое (СГ) - я пошел проторенной им тропой. | |
# так как в базовой комплектации R нет функции для расчета СГ, набросал свою: | |
# сперто отсюда: | |
# http://stackoverflow.com/questions/2602583/geometric-mean-is-there-a-built-in | |
# и капелька магии dplyr | |
d.t <- mutate_each(d,funs(. / exp(sum(log(.[.>0]),na.rm=TRUE) / n())),2:23) | |
#apply(d.t, 2, shapiro.test) # проверяем нормальность распределения | |
cor.m = cor(d.t[2:23], method = "spearman") # строим корреляционную матрицу | |
cor.p.vals <- sapply(2:ncol(d.t), | |
function(i){sapply(2:ncol(d.t), | |
function(j){cor.test(d.t[,i],d.t[,j],method='sp')$p.value})}) | |
cor.m[abs(cor.m) < 0.5 | cor.p.vals > 0.01] = 0 | |
corrplot(cor.m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment