Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:mixdist包中的mix()返回错误_R_Normal Distribution_Mixed Models_Nlm - Fatal编程技术网

R:mixdist包中的mix()返回错误

R:mixdist包中的mix()返回错误,r,normal-distribution,mixed-models,nlm,R,Normal Distribution,Mixed Models,Nlm,我已经在R中安装了mixdist包来合并发行版。具体来说,我使用的是mix()函数。 基本上,我得到了 nlm中的错误(mixlike,lmixdat=mixdat,lmixpar=fitpar,ldist=dist,: 参数中缺少值 我用谷歌搜索了错误消息,但没有弹出有用的结果 mix()的第一个参数是名为data.df的数据帧。它的格式与内置数据集pike65完全相同。我还使用链接到的测试数据执行了data.df library(mixdist) time <- seq(673,

我已经在R中安装了mixdist包来合并发行版。具体来说,我使用的是
mix()
函数。 基本上,我得到了

nlm中的错误(mixlike,lmixdat=mixdat,lmixpar=fitpar,ldist=dist,: 参数中缺少值

我用谷歌搜索了错误消息,但没有弹出有用的结果


mix()
的第一个参数是名为data.df的数据帧。它的格式与内置数据集pike65完全相同。我还使用链接到的测试数据执行了
data.df

library(mixdist) 
time <- seq(673,723) 
counts <-c(3,12,8,12,18,24,39,48,64,88,101,132,198,253,331,
   419,563,781,1134,1423,1842,2505,374,6099,9343,13009, 
   15097,13712,9969,6785,4742,3626,3794,4737,5494,5656,4806,
   3474,2165,1290,799,431,213,137,66,57,41,35,27,27,27) 
data.df <- data.frame(time=time, counts=counts) 
两者正好都是1,这似乎是导致错误的原因。当
mix
取1减去该值并将比率与估计组进行比较时,它会得到
NaN
值,该值会传播到比例估计值。当这些
NaN
值在内部传递到
nlm()时
要进行估算,您会收到错误消息

Error in nlm(mixlike, lmixdat = mixdat, lmixpar = fitpar, ldist = dist,  : 
  missing value in parameter
可以使用复制相同的错误消息

f <- function(x) sum((x-1:length(x))^2)
nlm(f, c(10,10))
nlm(f, c(10,NaN)) #error

f现在,我不是混合分布方面的专家,但我认为@MrFlick的公认答案对任何通过谷歌搜索错误消息的人来说都有点误导(尽管他给出的例子毫无疑问是正确的)。核心问题是,在您和您的示例中,
sigma
值与
mu
值相比非常小。我认为该算法无法找到具有如此小的起始sigma值的解决方案。如果您增加sigma值,您将得到一个解决方案。例如:

library(mixdist) 
time <- seq(673,723) 
counts <- c(3, 12, 8, 12, 18, 24, 39, 48, 64, 88, 101, 132, 198, 253, 331, 419, 563, 781, 1134, 1423, 1842, 2505, 374, 6099, 9343, 13009, 15097, 13712, 9969, 6785, 4742, 3626, 3794, 4737, 5494, 5656, 4806, 3474, 2165, 1290, 799, 431, 213, 137, 66, 57, 41, 35, 27, 27, 27) 
data.df <- data.frame(time=time, counts=counts) 
data.mix <- as.mixdata(data.df) 
startparam <- mixparam(mu = c(699,707), sigma = 1) 
data.fit <- mix(data.mix, startparam, "norm") ## Leads to the error message 

startparam <- mixparam(mu = c(699,707), sigma = 5) # Adjust start parameters
data.fit <- mix(data.mix, startparam, "norm")
plot(data.fit)
data.fit ### Estimates somewhat reasonable mixture distributions
# Parameters:
#     pi    mu sigma
# 1 0.853 699.3 4.494
# 2 0.147 708.6 2.217
库(mixdist)

时间此外,如果数据集中缺少数据,则可以收到此消息

从示例集

data(pike65)
data(pikepar)
pike65$freq[10] <- NA
fitpike1 <- mix(pike65, pikepar, "lnorm", constr = mixconstr(consigma = "CCV"), emsteps = 3)
数据(pike65)
数据(皮克帕)

pike65$freq[10]请创建一个,以便我们可以复制和粘贴代码以获得相同的错误。如果我们可以重新创建问题,而不必花费大量时间猜测特定的
datapar
中的实际值或其结构如何,则会更容易提供帮助。我很愿意这样做,但不幸的是,我使用的数据是专有的。但是,我我的代码看起来几乎一样。
library(mixdist) 
time <- seq(673,723) 
counts <- c(3, 12, 8, 12, 18, 24, 39, 48, 64, 88, 101, 132, 198, 253, 331, 419, 563, 781, 1134, 1423, 1842, 2505, 374, 6099, 9343, 13009, 15097, 13712, 9969, 6785, 4742, 3626, 3794, 4737, 5494, 5656, 4806, 3474, 2165, 1290, 799, 431, 213, 137, 66, 57, 41, 35, 27, 27, 27) 
data.df <- data.frame(time=time, counts=counts) 
data.mix <- as.mixdata(data.df) 
startparam <- mixparam(mu = c(699,707), sigma = 1) 
data.fit <- mix(data.mix, startparam, "norm") ## Leads to the error message 

startparam <- mixparam(mu = c(699,707), sigma = 5) # Adjust start parameters
data.fit <- mix(data.mix, startparam, "norm")
plot(data.fit)
data.fit ### Estimates somewhat reasonable mixture distributions
# Parameters:
#     pi    mu sigma
# 1 0.853 699.3 4.494
# 2 0.147 708.6 2.217
data(pike65)
data(pikepar)
pike65$freq[10] <- NA
fitpike1 <- mix(pike65, pikepar, "lnorm", constr = mixconstr(consigma = "CCV"), emsteps = 3)