楼主: 萨伦斯
1909 1

[经济] 跪求R软件问题 [推广有奖]

  • 0关注
  • 0粉丝

高中生

92%

还不是VIP/贵宾

-

威望
0
论坛币
137 个
通用积分
0
学术水平
1 点
热心指数
1 点
信用等级
1 点
经验
6714 点
帖子
19
精华
0
在线时间
60 小时
注册时间
2010-12-30
最后登录
2014-5-27

楼主
萨伦斯 发表于 2011-1-20 13:22:55 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
我想模仿以下的一段R代码统计我的数据(名为“mydata”)
在输入语言后,系统提示错误(红色字样)。由于是初学,不知问题出在哪里。本来想高分悬赏,可是我连一个论坛币也没有。因毕业在即,十分焦虑。请哪位好心人指点一下。万分感激!
library(pls)library(GeneNet)library(graph)library(Rgraphviz) example = function() {
data(ecoli)

# Apply PLS-PC network using 3 components on ecoli data

# Plot the resulting graph

result = PLSPC.network(ecoli)

} PLSPC.network = function(X, nbre = 3, method = "kernelpls", viz = 1){# X : Microarray experiments (n * p)#
n = number of experiments
#
p = number of genes
# nbre = Number of PLS components to include in the PLSPC network (default = 3 components)# method = implementation of the PLS algorithm (default = Kernel PLS)# viz = visualization (default = 1 -> visualization desired)
# Output : list of variables #
pcor
: PLSPC matrix
#
graph : data.frame with the significant edges
#
gr
: a graph object
#
coef
: PLS matrix coefficients
             if (viz ==1){X = X[ , as.logical(1-duplicated(colnames(X)))]X = X[ , which(colnames(X) != "NA")]} if ((nbre > qr(scale(X, center = TRUE, scale = TRUE))$rank) && (is.null(nbre) == FALSE)){ print(paste("Number of PLS components must be < ", qr(scale(X, center = TRUE, scale = TRUE))$rank))} else{# Construction of the Partial Correlation matrix
Package PLS required
# pcor = coef = diag(ncol(X))for (i in 1:ncol(X)){
temp = mvr(X[, i]~X[, -i], ncomp = nbre, method = method, scale = TRUE, stripped = TRUE)

coef[i, -i] = as.data.frame(temp$coefficients)[ , nbre]
} for (i in 1:ncol(X)){
for (j in i:ncol(X)){



if (i==j) pcor[i, j] = 1


else {

if(sign(coef[j, i]) != sign(coef[i, j])) pcor[i, j] = 0

else{


pcor[i, j] = sign(coef[j, i])*sqrt(coef[i, j]*coef[j, i])

}

}

pcor[j, i] = pcor[i, j]

}

}
}if (viz == 1){# Local fdr multiple testing on the PLS
test.results = ggm.test.edges(pcor, plot = FALSE)signif = test.results$prob > 0.8
if (sum(signif)>1){# Visualization of the PLSPC network node.labels = colnames(X)gr = ggm.make.graph(test.results[signif, ], node.labels, drop.singles = FALSE)x11(); plot(gr,"twopi")return(list(pcor = pcor, graph = test.results[signif, ], gr = gr, coef = coef))}else{print("No significant interaction !");return(list(pcor = pcor, coef = coef))}}else{return(list(pcor = pcor, coef = coef))}}我载入程序包并按照代码输入语言后的界面显示如下:

> example = function()
+ {
data(ecoli)

+
result = PLSPC.network(ecoli)

> PLSPC.network = function(X, nbre = 3, method = "kernelpls", viz = 1){

+ if (viz ==1){
+ X = X[ , as.logical(1-duplicated(colnames(X)))]
+ X = X[ , which(colnames(X) != "NA")]
+ }
+
+ if ((nbre > qr(scale(X, center = TRUE, scale = TRUE))$rank) && (is.null(nbre) == FALSE)){
+ print(paste("Number of PLS components must be < ", qr(scale(X, center = TRUE, scale = TRUE))$rank))
+ }
+ else{
+ pcor = coef = diag(ncol(X))
+ for (i in 1:ncol(X)){
+ temp = mvr(X[, i]~X[, -i], ncomp = nbre, method = method, scale = TRUE, stripped = TRUE)
+
coef[i, -i] = as.data.frame(temp$coefficients)[ , nbre]

+ }
+ for (i in 1:ncol(X)){
+
for (j in i:ncol(X)){

+
if (i==j) pcor[i, j] = 1

+
else {

+
if(sign(coef[j, i]) != sign(coef[i, j])) pcor[i, j] = 0

+
else{

+
pcor[i, j] = sign(coef[j, i])*sqrt(coef[i, j]*coef[j, i])

+
}

+
}

+
pcor[j, i] = pcor[i, j]

+
}

+
}

+ }
+ if (viz == 1){
+ test.results = ggm.test.edges(pcor, plot = FALSE)
+ signif = test.results$prob > 0.8


+ if (sum(signif)>1){


+ node.labels = colnames(X)
+ gr = ggm.make.graph(test.results[signif, ], node.labels, drop.singles = FALSE)
+ x11(); plot(gr,"twopi")
+ return(list(pcor = pcor, graph = test.results[signif, ], gr = gr, coef = coef))}
+ else{print("No significant interaction !");return(list(pcor = pcor, coef = coef))}
+ }
+ else{return(list(pcor = pcor, coef = coef))}
+ }
> d=read.table("mydata.txt")
> result = PLSPC.network(d) (此两行为我与代码不同之处)
错误于model.frame.default(formula = X[, i] ~ X[, -i]) :

变元'X[, -i]'的种类(list)不对


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:软件问题 r软件 coefficients Construction coefficient 软件

沙发
Henryzhu 在职认证  发表于 2011-1-20 13:32:02
1# 萨伦斯

我也正在学这个软件
不知道这个有没有帮助:
http://cran.r-project.org/doc/manuals/R-intro.html
很高兴能来这个论坛

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
jg-xs1
拉您进交流群
GMT+8, 2025-12-28 16:43