0

我有一个矩阵

结果[i]

带有一些数据(分布参数):

list(structure(c(0.005, 0.004),
.Names = c("mean", "sd")))

例如。我想使用 fdist 并使用 results[i] 中包含的值作为分布参数的种子:

params = fitdist( data, dist,method="mle",
                    start=list(mean =mapply("[", results[1], 1),
                               sd=mapply("[", results[1], 2)))

我收到以下错误:

the function mle failed to estimate the parameters, 
            with the error code 100

因为开始列表是:

structure(list(mean = structure(0.005, .Names = "mean"), 
sd = structure(0.004, .Names = "sd")), .Names = c("mean","sd"))

它应该是:

structure(list(mean = 0.005, sd = 0.004), .Names = c("mean","sd"))

最后的输出来自:

params = fitdist( data, dist,method="mle",
                    start=list(mean=0.005,
                               sd=0.004))

任何想法?

谢谢!

4

1 回答 1

2

尝试使用“[[”而不是“[”,原因是“[[”将值拉到列表节点,而“[”将值留在列表中。

res =list(structure(c(0.005, 0.004),
          .Names = c("mean", "sd")))
list(mean =mapply("[[", res, 1),
                                sd=mapply("[[", res, 2))
$mean
[1] 0.005

$sd
[1] 0.004

(虽然我会使用 sapply。)

> list(mean =sapply( res,"[[", 1),
+                                sd=sapply(res,"[[", 2))
$mean
[1] 0.005

$sd
[1] 0.004

> dput( list(mean =sapply( res,"[[", 1),
+                                sd=sapply(res,"[[", 2)) )
structure(list(mean = 0.005, sd = 0.004), .Names = c("mean", 
"sd"))
于 2012-08-23T17:31:08.867 回答