You are on page 1of 4

R version 3.2.

2 (2015-08-14) -- "Fire Safety"


Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: i386-w64-mingw32/i386 (32-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
[Previously saved workspace restored]
> data<-c(0.1,0.2,1,1,1,1,1,2,3,6,7,11,12,18,18,18,18,18,21,32,36,40,45,46,47,50
,55,60,63,63,67,67,67,67,72,75,79,82,82,83,84,84,84,85,85,85,85,85,86,86)
> n<-length(data)
> #declaration likelihood function
> lnl<-function(theta,x){
+ lambda<-theta[1]
+ beta<-theta[2]
+ gamma<-theta[3]
+ alpha<-theta[4]
+ n*(log(theta[1])+log(theta[2])+log(theta[3])+(1-theta[2])*log(theta[4])+theta[
1]*theta[4])+(theta[2]-1)*sum(log(x))+(1/(theta[4]^theta[2]))*sum(x^theta[2])-(t
heta[1]*theta[4])*sum(exp((x/theta[4])^theta[2]))+(theta[3]-1)*sum(1-(exp((theta
[1]*theta[4])*(1-(exp((x/theta[4])^theta[2]))))))
+ }
>
> #Optimization
> res<-maxLik(lnl,start=c(0.00007181,3.148,0.145,49.05),method="NR",x=data)
Error: could not find function "maxLik"
> library(maxLik)
Loading required package: miscTools
Please cite the 'maxLik' package as:
Henningsen, Arne and Toomet, Ott (2011). maxLik: A package for maximum likelihoo
d estimation in R. Computational Statistics 26(3), 443-458. DOI 10.1007/s00180-0
10-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/
Warning messages:
1: package maxLik was built under R version 3.2.3
2: package miscTools was built under R version 3.2.3
> res<-maxLik(lnl,start=c(0.00007181,3.148,0.145,49.05),method="NR",x=data)
There were 50 or more warnings (use warnings() to see the first 50)
> summary(res)
-------------------------------------------Maximum Likelihood estimation
Newton-Raphson maximisation, 43 iterations
Return code 3: Last step could not find a value above the current.

Boundary of parameter space?


Consider switching to a more robust optimisation method temporarily.
Log-Likelihood: 2499507215
4 free parameters
Estimates:
Estimate Std. error t value Pr(> t)
[1,] 6.056e-01
NA
NA
NA
[2,] 3.926e-03 2.195e-12 1.789e+09 <2e-16 ***
[3,] 4.999e+07 1.448e-03 3.452e+10 <2e-16 ***
[4,] 1.658e+01
NA
NA
NA
--Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1
1
-------------------------------------------Warning messages:
1: In sqrt(diag(vc)) : NaNs produced
2: In sqrt(diag(vc)) : NaNs produced
> AIC(res)
[1] -4999014423
>
> data
[1] 0.1 0.2 1.0 1.0 1.0 1.0 1.0 2.0 3.0 6.0 7.0 11.0 12.0 18.0 18.0
18.0 18.0
[18] 18.0 21.0 32.0 36.0 40.0 45.0 46.0 47.0 50.0 55.0 60.0 63.0 63.0 67.0 67.0
67.0 67.0
[35] 72.0 75.0 79.0 82.0 82.0 83.0 84.0 84.0 84.0 85.0 85.0 85.0 85.0 85.0 86.0
86.0
> n
[1] 50
> x<-c(0.1,0.2,1,1,1,1,1,2,3,6,7,11,12,18,18,18,18,18,21,32,36,40,45,46,47,50,55
,60,63,63,67,67,67,67,72,75,79,82,82,83,84,84,84,85,85,85,85,85,86,86)
> fn<-function(theta){
+ n*(log(theta[1])+log(theta[2])+log(theta[3])+(1-theta[2])*log(theta[4])+theta[
1]*theta[4])+(theta[2]-1)*sum(log(x))+(1/(theta[4]^theta[2]))*sum(x^theta[2])-(t
heta[1]*theta[4])*sum(exp((x/theta[4])^theta[2]))+(theta[3]-1)*sum(1-(exp((theta
[1]*theta[4])*(1-(exp((x/theta[4])^theta[2]))))))
+ }
> fn
function(theta){
n*(log(theta[1])+log(theta[2])+log(theta[3])+(1-theta[2])*log(theta[4])+theta[1]
*theta[4])+(theta[2]-1)*sum(log(x))+(1/(theta[4]^theta[2]))*sum(x^theta[2])-(the
ta[1]*theta[4])*sum(exp((x/theta[4])^theta[2]))+(theta[3]-1)*sum(1-(exp((theta[1
]*theta[4])*(1-(exp((x/theta[4])^theta[2]))))))
}
> fit<-nlm(fn,theta<-c(0.00007181,3.148,0.145,49.05),hessian=TRUE)
There were 50 or more warnings (use warnings() to see the first 50)
> fit
$minimum
[1] -665.6488
$estimate
[1] 2.506924e-06 3.148000e+00 1.450000e-01 4.905000e+01
$gradient
[1] 1.646800e+07 2.089756e+01 3.452544e+02 -8.769015e+00
$hessian
[,1]
[,2]
[,3]
[,4]
[1,] -1.460105e+10 -6.257459e+05 98571.2344971 70435.4015514
[2,] -6.257459e+05 1.188304e+01
1.2374097
-5.2688981
[3,] 9.857123e+04 1.237410e+00 -2374.8463605
-0.1385554

[4,] 7.043540e+04 -5.268898e+00

-0.1385554

0.5143110

$code
[1] 2
$iterations
[1] 6
> optim(theta<-c(0.00007181,3.148,0.145,49.05),fn,hessian=TRUE)
Error in optim(theta <- c(7.181e-05, 3.148, 0.145, 49.05), fn, hessian = TRUE) :
non-finite finite-difference value [1]
In addition: Warning messages:
1: In log(theta[3]) : NaNs produced
2: In log(theta[3]) : NaNs produced
3: In log(theta[1]) : NaNs produced
4: In log(theta[3]) : NaNs produced
5: In log(theta[3]) : NaNs produced
6: In log(theta[3]) : NaNs produced
7: In log(theta[3]) : NaNs produced
> fit<-nlm(fn,theta<-c(0.00007181,3.148,0.145,49.05),hessian=TRUE)
There were 50 or more warnings (use warnings() to see the first 50)
> fit
$minimum
[1] -665.6488
$estimate
[1] 2.506924e-06 3.148000e+00 1.450000e-01 4.905000e+01
$gradient
[1] 1.646800e+07 2.089756e+01 3.452544e+02 -8.769015e+00
$hessian
[,1]
-1.460105e+10
-6.257459e+05
9.857123e+04
7.043540e+04

[1,]
[2,]
[3,]
[4,]

[,2]
[,3]
[,4]
-6.257459e+05 98571.2344971 70435.4015514
1.188304e+01
1.2374097
-5.2688981
1.237410e+00 -2374.8463605
-0.1385554
-5.268898e+00
-0.1385554
0.5143110

$code
[1] 2
$iterations
[1] 6
> fn<-function(theta,x){
+ n*(log(theta[1])+log(theta[2])+log(theta[3])+(1-theta[2])*log(theta[4])+theta[
1]*theta[4])+(theta[2]-1)*sum(log(x))+(1/(theta[4]^theta[2]))*sum(x^theta[2])-(t
heta[1]*theta[4])*sum(exp((x/theta[4])^theta[2]))+(theta[3]-1)*sum(1-(exp((theta
[1]*theta[4])*(1-(exp((x/theta[4])^theta[2]))))))
+ }
> nlm(fn,theta<-c(0.00007181,3.148,0.145,49.05),hessian=TRUE)
Error in f(x, ...) : argument "x" is missing, with no default
> nlm(fn,theta<-c(0.00007181,3.148,0.145,49.05),x=x,hessian=TRUE)
$minimum
[1] -665.6488
$estimate
[1] 2.506924e-06 3.148000e+00 1.450000e-01 4.905000e+01

$gradient
[1] 1.646800e+07 2.089756e+01 3.452544e+02 -8.769015e+00
$hessian
[,1]
-1.460105e+10
-6.257459e+05
9.857123e+04
7.043540e+04

[1,]
[2,]
[3,]
[4,]

[,2]
[,3]
[,4]
-6.257459e+05 98571.2344971 70435.4015514
1.188304e+01
1.2374097
-5.2688981
1.237410e+00 -2374.8463605
-0.1385554
-5.268898e+00
-0.1385554
0.5143110

$code
[1] 2
$iterations
[1] 6
There were 50 or more warnings (use warnings() to see the first 50)
> AIC(fit)
Error in UseMethod("logLik") :
no applicable method for 'logLik' applied to an object of class "list"
> summary(fit)
Length Class Mode
minimum
1
-none- numeric
estimate
4
-none- numeric
gradient
4
-none- numeric
hessian
16
-none- numeric
code
1
-none- numeric
iterations 1
-none- numeric
>

You might also like