我有一个矩阵
结果[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))
有什么想法吗?
谢谢!
答案 0 :(得分: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"))