小编use*_*694的帖子

R reshape2中的cast()调用的自定义聚合函数出错

我想使用R将具有非唯一rownames的表中的数值数据汇总到具有唯一行名的结果表,其中值使用自定义函数进行汇总.摘要逻辑是:如果最大值与最小值的比率<1.5,则使用值的均值,否则使用中值.因为表非常大,我试图在reshape2包中使用melt()和cast()函数.

# example table with non-unique row-names
tab <- data.frame(gene=rep(letters[1:3], each=3), s1=runif(9), s2=runif(9))
# melt
tab.melt <- melt(tab, id=1)
# function to summarize with logic: mean if max/min < 1.5, else median
summarize <- function(x){ifelse(max(x)/min(x)<1.5, mean(x), median(x))}
# cast with summarized values
dcast(tab.melt, gene~variable, summarize)

上面的最后一行代码会导致错误通知.

Error in vapply(indices, fun, .default) : 
  values must be type 'logical',
 but FUN(X[[1]]) result is type 'double'
In addition: Warning messages:
1: In max(x) : no non-missing arguments to max; returning -Inf …

casting aggregate r reshape reshape2

8
推荐指数
2
解决办法
5614
查看次数

在使用R的CMA Bioconductor包时,解决SVM分类的交叉验证中的"模型空"错误

我正在使用Bioconductor软件包CMA在微阵列数据集中对SVM分类器执行内部蒙特卡罗交叉验证(MCCV).CMA内部使用e1071 R软件包进行SVM工作.

数据集有45个样本(观察)的387个变量(属性),它们属于两个类别之一(标签0或1;比例约为1:1).所有数据都是数字的,没有NA.我正在尝试使用limma统计数据进行差异基因表达分析,为SVM选择15个变量的1000次迭代MCCV .在MCCV期间,45个样本集的一部分用于训练SVM分类器,然后用于测试剩余分数,并且我正在尝试训练集分数的不同值.CMA还执行内循环验证(默认情况下在训练集内进行3次交叉验证),以微调用于针对测试集进行交叉验证的分类器.所有这些都是在CMA包中完成的.

有时,对于低训练集大小,CMA在控制台中显示错误并停止执行分类的其余代码.

[snip]tuning iteration 575
tuning iteration 576
tuning iteration 577
Error in predict.svm(ret, xhold, decision.values = TRUE) :   Model is empty!

即使我使用除limma之外的测试进行变量选择,或者使用两个而不是15个变量进行分类器生成,它也会发生.我使用的R代码应确保训练集始终具有两个类的成员.我很感激任何见解.

下面是我使用的R代码,Mac OS X 10.6.6,R 2.12.1,Biobase 2.10.0,CMA 1.8.1,limma 3.6.9和WilcoxCV 1.0.2.数据文件hy3ExpHsaMir.txt可以从http://rapidshare.com/files/447062901/hy3ExpHsaMir.txt下载.

一切顺利,直到gfor(g在0:10)循环中为9 (用于改变训练/测试集大小).


# exp is the expression table, a matrix; 'classes' is list of known classes
exp <- as.matrix(read.table(file='hy3ExpHsaMir.txt', sep='\t', row.names=1, header=T, check.names=F))
#best is to use 0 and 1 as class labels (instead of …
Run Code Online (Sandbox Code Playgroud)

r classification svm bioconductor

5
推荐指数
1
解决办法
3220
查看次数

标签 统计

r ×2

aggregate ×1

bioconductor ×1

casting ×1

classification ×1

reshape ×1

reshape2 ×1

svm ×1