我想在multiroot
包中使用rootSolve
命令来查找b和m。
代码如下。
我尝试了不同的起始值,但结果是NaN
或NaNs produced
。
n <- 23
model <- function(theta){
b <- theta[1]
m <- theta[2]
power <- exp(-(x-m)*b)
a <- -n/sum(log(1-power))
betat <- apply(x,1,function(x) (x-m)*power/(1-power))
mut <- apply(x,1, function(x) power/(1-power))
F1 <- n/b-sum(x)+n*m+(a-1)*sum(betat)
F2 <- n*b-b*(a-1)*sum(mut)
c(F1=F1,F2=F2)
}
multiroot(f = model, start = c(.5, .5))
那么,有人可以解释我的错误吗?
答案 0 :(得分:0)
library(rootSolve)
x<- c(17.88,28.92,33,41.52,42.12,45.6,48.40,51.84,51.96,54.12,55.56,67.80,
68.64,68.64,68.88,84.12,93.12, 98.64,105.12,105.84,127.92,128.04,173.4)
n <- length(x)
model <- function(theta){
b <- theta[1]
m <- theta[2]
power <- exp(-(x-m)*b)
a <- -n/sum(log(1-power))
F1 <- n/b-sum(x-m) + (a-1)*sum((x-m)*power/(1-power))
F2 <- n*b - b*(a-1)*sum(power/(1-power))
c(F1=F1,F2=F2)
}
# model(c(b = 0.031, m = 4.748))
multiroot(f = model, start = c(.03, 5))
所以结果是:
> multiroot(f = model, start = c(.03, 5))
$root
[1] 0.03140027 4.55976021
$f.root
F1 F2
-2.046363e-12 -6.217249e-15
$iter
[1] 5
$estim.precis
[1] 1.02629e-12