统计初学 发表于 2017-2-20 16:36
首先你定义的LL函数里面没有用到dataDF里的数据,但是函数的变量里却加上了。
其次,那个错误是说在用梯 ...
您好,我根据您说的修改了下程序但是为什么还是报错,您可以粘贴下您的程序我看下吗,方便留个联系方式么qq或微信,谢谢了
> curwd = setwd("D:/R/work")
> df <- read.csv('activedata.csv',header = TRUE)
> dataDF <- df[,2:4]
> head(dataDF)
x t T
1 39 2 17
2 18 1 17
3 90 15 17
4 26 2 17
5 34 7 17
6 148 15 17
> library(maxLik)
载入需要的程辑包:miscTools
Please cite the 'maxLik' package as:
Henningsen, Arne and Toomet, Ott (2011). maxLik: A package for maximum likelihood estimation in R. Computational Statistics 26(3), 443-458. DOI 10.1007/s00180-010-0217-1.
If you have questions, suggestions, or comments regarding the 'maxLik' package, please use a forum or 'tracker' at maxLik's R-Forge site:
https://r-forge.r-project.org/projects/maxlik/
> LL <- function(para)
+ {r <- para[1]
+ s <- para[2]
+ a <- para[3]
+ b <- para[4]
+ logL <- log(gamma(r+x))-log(gamma(r))+r*log(s)+log(gamma(a+b))+log(gamma(b+x))-log(gamma(b))-log(gamma(a+b+x))+log((s+T)^(-r-x)+(a/(b+x-1))*(s+t)^(-r-x))
+ return(logL)
+ }
> x <- as.numeric(dataDF$x)
> t <- as.numeric(dataDF$t)
> T <- as.numeric(dataDF$T)
> result <- maxLik(LL,grad = NULL,hess = NULL,start=c(0.58,0.64,0.8,1))
There were 50 or more warnings (use warnings() to see the first 50)
> summary(result)
--------------------------------------------
Maximum Likelihood estimation
Newton-Raphson maximisation, 0 iterations
Return code 100: Initial value out of range.
--------------------------------------------
> result=maxLik(LL,grad = NULL,hess = NULL,start=c(0.58,0.64,0.8,1))
There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
警告信息:
1: In fnOrig(theta, ...) : value out of range in 'gammafn'
2: In fnOrig(theta, ...) : value out of range in 'gammafn'
3: In fnOrig(theta, ...) : value out of range in 'gammafn'
4: In fnOrig(theta, ...) : value out of range in 'gammafn'
5: In fnOrig(theta, ...) : value out of range in 'gammafn'
6: In fnOrig(theta, ...) : value out of range in 'gammafn'
7: In fnOrig(theta, ...) : value out of range in 'gammafn'
8: In fnOrig(theta, ...) : value out of range in 'gammafn'
9: In fnOrig(theta, ...) : value out of range in 'gammafn'
10: In fnOrig(theta, ...) : value out of range in 'gammafn'
再粘贴几个数据:
mac x t T
00003a16723a 39 2 17
000271d5e0c2 18 1 17
0002723ec760 90 15 17
0002723ec771 26 2 17
0002723ec781 34 7 17
000272c243c4 148 15 17
000272c2cee2 84 15 17
000272c2cee7 114 15 17
000272c2cf07 115 15 17
000272c2cf65 91 15 17
000272c2cf6b 64 8 17
00037f05c0ca 13 11 17
00049454b178 35 2 17
000668334b87 10 12 17
00066838b933 11 3 17
000668d281e2 33 6 17
0006e21f8773 11 14 17
0007a6391eee 11 8 17
0007a838fdc5 61 7 17
0007a83d91d1 163 8 17
0007a83eb29c 15 14 17
0007a8605eb6 36 16 17
0007ab34b831 13 12 17
00082200befb 5 16 17
000822010e2d 12 2 17
00082202bcfb 4 7 17
00082202c1fb 5 14 17
00082204bafb 7 11 17
00082204cefb 5 11 17
00082204d8fb 4 3 17
00082206434f 7 4 17
00082206b8fb 5 12 17
00082206bdfb 5 17 17
00082208b6fb 8 5 17
00082208e8fb 5 11 17
0008220cbcfb 11 15 17
0008220cd0fb 7 12 17
0008220eb0fb 6 17 17
0008220f3526 16 1 17
000822103f25 24 15 17
00082210b8fb 6 15 17
00082210c2fb 6 7 17
00082212553b 4 5 17
00082214b4fb 5 15 17
00082214befb 10 17 17
00082214c8fb 4 6 17
000822150a09 279 16 17
00082216dffb 4 16 17
00082218703e 6 1 17