使用R语言做成对的相关分析和偏相关分析
(2012-11-27 09:49:13)
标签:
r语言相关分析杂谈 |
.libPaths(); #add new path
getwd(); #get the directory of working space
setwd("/home/mingyang/R/data"); #set the directory of working space
data = read.table(file="data.txt",header=TRUE); #loading the data set
edit(data);
#viewing the data set
dim(data);
#get the dimension of data set
names(data);
#view the names of variable
nrow(data)
#correlation analysis
#pairwise mode
for (i in 1:(ncol(data)-1)){
for (j in (i+1):ncol(data)){
lab =
paste("the correlation analysis between ",names(data)[i]," and
",names(data)[j]);
print(lab);
re =
cor.test(data[,i],data[,j]);
print(re);
}
}
#partial correlation analysis
#pairwise mode
library(ppcor); #load the
library of ppcor
for (i in 1:(ncol(data)-1)){
for (j in (i+1):ncol(data)){
lab =
paste("the partial correlation analysis between ",names(data)[i],"
and ",names(data)[j]);
print(lab);
re =
pcor.test(data[,i],data[,j],data[,-c(i,j)]);
print(re);
}
}
getwd(); #get the directory of working space
setwd("/home/mingyang/R/data"); #set the directory of working space
data = read.table(file="data.txt",header=TRUE); #loading the data set
edit(data);
dim(data);
names(data);
nrow(data)
#correlation analysis
#pairwise mode
for (i in 1:(ncol(data)-1)){
}
#partial correlation analysis
#pairwise mode
library(ppcor);
for (i in 1:(ncol(data)-1)){
}
后一篇:主成分回归的直接程序