【问题标题】:Binomial Distribution in in RR中的二项式分布
【发布时间】:2018-10-21 06:06:36
【问题描述】:

我应用了这段代码,但我一遍又一遍地得到这个错误。

library(mixtools)

simulate <- function(lambda=0.3, mu=c(0, 4), sd=c(1, 1), n.obs=10^5) {
    x1 <- rnorm(n.obs, mu[1], sd[1])
    x2 <- rnorm(n.obs, mu[2], sd[2])    
    return(ifelse(runif(n.obs) < lambda, x1, x2)) 
}

x <- simulate()

model <- normalmixEM(x=x, k=2)

错误:找不到对象“C_normpost”

谁能帮我解决这个问题?

另一方面,如果有人能想出一种方法来分离两个二项分布,那就太好了。

【问题讨论】:

  • 第一步是options(error=recover)进行调试
  • 我无法重现该错误,它对我来说运行流畅。我不知道结果是否有意义,但没有错误。
  • 我也是,没有错误。您正在运行哪个版本的 R? sessionInfo() ?

标签: r expectation-maximization


【解决方案1】:

如果您正确安装了mixtools 软件包,则不会出现错误。我安装了 1.1.0 版,CRAN 告诉我这是最新发布的版本。 .C() 对C_normpost 的调用是在normalmixEM 正文的三个不同位置进行的。在我看到的代码之后:

str(model)   # don't type just `model` ... appears to have no print method for it.
List of 9
 $ x         : num [1:100000] 3.33 3.17 -2.04 3.66 5.11 ...
 $ lambda    : num [1:2] 0.299 0.701
 $ mu        : num [1:2] -0.00253 3.9986
 $ sigma     : num [1:2] 0.994 1.001
 $ loglik    : num -197426
 $ posterior : num [1:100000, 1:2] 1.94e-03 3.66e-03 1.00 5.17e-04 1.42e-06 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:2] "comp.1" "comp.2"
 $ all.loglik: num [1:39] -427524 -216959 -208812 -204523 -200531 ...
 $ restarts  : num 0
 $ ft        : chr "normalmixEM"
 - attr(*, "class")= chr "mixEM"

summary(model)
summary of normalmixEM object:
           comp 1   comp 2
lambda  0.2992979 0.700702
mu     -0.0025302 3.998599
sigma   0.9935503 1.001362
loglik at estimate:  -197426.2 

因此,它在估计均值(0 和 4)以及估计这些分量(1 和 1)的方差方面做得非常好。您可能应该尝试在新会话中重新安装 mixtools 并重新运行代码。

【讨论】:

    猜你喜欢
    • 2021-12-13
    • 1970-01-01
    • 2018-12-30
    • 1970-01-01
    • 1970-01-01
    • 2013-08-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    相关资源
    最近更新 更多