【问题标题】:R glm.nb Error in x[good, , drop = FALSE] : (subscript) logical subscript too longR glm.nb x[good, , drop = FALSE] 中的错误:(下标)逻辑下标太长
【发布时间】:2015-04-28 11:55:19
【问题描述】:

我正在处理一些数据,但我得到一个错误,我不知道为什么......

initial <-read.table....
library(Mass)

一切都很好,直到:

glm.percent <- glm.nb(cbind(Count, Rest)~ Plasmid+Region*Plasmid, data=initial)

Error in x[good, , drop = FALSE] : (subscript) logical subscript too long

所以对于更多的背景。我想比较6个组织层中细胞的比例。不,我知道我必须在 R 中使用整数作为负二项式,并且我读到我必须使用 cbind 将我的正计数链接到我的负计数。所以这就是我上面所做的。我之前读到这个错误可能是由于缺少数据点,但一切都很好。有没有人有什么有用的想法?

'data.frame':   54 obs. of  4 variables:
 $ Plasmid: Factor w/ 2 levels "CTR","EXP": 2 2 2 2 2 2 2 2 2 2 ...
 $ Region : Factor w/ 6 levels "L0","L1","L2+3",..: 2 2 2 2 2 3 3 3 3 3 ...
 $ Count  : int  0 3 34 12 83 361 426 185 402 565 ...
 $ Rest   : int  464 592 306 482 791 103 169 155 92 309 ...

干杯!

【问题讨论】:

    标签: r glm


    【解决方案1】:

    您对二项式模型和负二项式模型之间的区别感到困惑;这是一个常见的混淆。对于比例,您应该使用二项式(不是负二项式)模型...

    model <- glm(cbind(Count, Rest)~ Region*Plasmid, 
                 family=binomial, data=initial)
    

    initial <- transform(initial,
                         total=Rest+Count,
                         prop=Count/(Rest+Count))
    model <- glm(prop ~ Region*Plasmid, weights=total,
                 family=binomial, data=initial)
    

    【讨论】:

    • 谢谢。我最后使用了一个准二项式,因为它似乎给我的抱怨最少
    猜你喜欢
    • 2020-11-07
    • 1970-01-01
    • 2012-09-10
    • 2016-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-11
    • 2022-06-20
    相关资源
    最近更新 更多