在r

时间:2017-07-06 20:05:11

标签: r bootstrapping

我有一个数据框:

df <- structure(list(Gene = c("Dleu2", "Ano3", "Shisa2", "Cox6b2", 
"Ccnd3", "Tnfsf9", "Nynrin", "Pid1", "Cd200r1", "Syde1"), `condition-cKOvsaFL.FC` = c(2.483219034, 
2.276983629, 2.233439806, 2.133677932, 2.092328446, 2.047418548, 
2.018261269, 1.978336246, 1.967370561, 1.956986235), `condition-cKOvsaFL.RawP` = c(7.62e-33, 
NA, 1.28e-10, 1.03e-14, 2e-38, 1.18e-12, NA, 3.7e-07, 2.55e-17, 
6.07e-07), Sum = c(32, 0, 1, 9, 96, 480, 0, 0, 78, 6)), .Names = c("Gene", 
"condition-cKOvsaFL.FC", "condition-cKOvsaFL.RawP", "Sum"), row.names = c(762L, 
197L, 2431L, 636L, 468L, 2838L, 1821L, 1963L, 485L, 2655L), class = "data.frame")

并希望逐行将引导应用于此数据。我有一个函数,当与boot()一起使用时,可以计算具有条件的基因的比率-cKOvsaFL.FC&gt;图1基于具有Sum> = j的基因子集。这里的j是将由数据帧的每一行描述的变量(即,对于每一行,我希望boot()函数用'sum'替换该行的值为j)

function.ratio_up_bootstrap <- function(j,d,i)
{
d <- subset(d, `Sum` >= j)
d2 <- d[i,]
d.up = subset(d2,
          `condition-cKOvsaFL.RawP` <= 0.05 &
            `condition-cKOvsaFL.FC` >1)
all = d2
return(nrow(d.up) /nrow(d))
}

我已经通过手动替换j中的值来使这个boot()函数工作,但是希望能够将它应用于我的数据框中的每一行(数千行)。

b1 = boot(data=df, function.ratio_up_bootstrap, R=50, stype = 'i', j=32)
b2 = boot(data=df, function.ratio_up_bootstrap, R=50, stype = 'i', j=0)
b3 = boot(data=df, function.ratio_up_bootstrap, R=50, stype = 'i', j=1)

然后我想计算每个boot()调用的boot.ci()置信区间,并使用ggplot2绘制它们。

我一直在尝试使用apply()和lapply()执行此操作,但一直无法使其工作。提前谢谢!

P.S。 我看过帖子bootstrap samples by row of a data frame in r但它正在使用带有列表的for循环,我无法弄清楚如何将它应用于我自己的问题。我是R的新手所以非常感谢会员的答案!

0 个答案:

没有答案