I am trying to estimate the parameters of Truncated New Generalized Poisson Lindly distribution.
Here in this distribution, we use two parameters which are alpha1, beta1, When I run Optimum function then I should get the values of estimators alpha1, beta1.
I get those values in R, the value of alpha1 I get is correct,
But the problem is that I am getting the incorrect value of beta1.
I have tried to run this in R, but the estimate of beta1 is incorrect.
## Data Generation
## PMF of New Generalized Poisson Lindley distribution
marginal=function(alpha1, beta1,x1){
ab=(alpha1^2*(1+alpha1+beta1+beta1*x1))/((alpha1+beta1)*(alpha1+1)^(x1+2))
return(ab)
}
alpha1=0.2;beta1=3;Tr=3
t1=c();
for(i in 1:10000){
a=0:1000
pr1=marginal(alpha1,beta1,a)
y1=sample(a,1,replace=TRUE,prob=pr1);
t1[i]=y1;
}
t1
##_________________###_____________________##___________
length(t1)
summary(t1)
hist(t1)
# Mean and Variance of Untruncated NGPLD
#Mean of Untruncated NGPLD
U1=function(alpha1,beta1){
U1=(alpha1+2*beta1)/(alpha1*(beta1+alpha1))
return(sum(U1))
}
U1(alpha1,beta1);mean(t1)
# Variance of Untruncated NGPLD
var1=function(alpha1,beta1){
var1=(2*beta1^2*(1+alpha1)+alpha1^2*(1+alpha1)+alpha1*beta1*(4+3*alpha1))/(alpha1^2*(alpha1+beta1)^2)
return(sum(var1))
}
var1(alpha1,beta1);var(t1)
#Truncated data
Tx=t1[t1>Tr];Tx
hist(Tx)
length(Tx)
#Truncated NEw genralized poisson lindley Disrtribution ,where
#Truncated NGPLD=(PMF/1-Cf),where (1-Cf) is a Survival function
#survival Function
x=Tr
cf=((alpha1+beta1)*(1+alpha1)^(x+2)-(alpha1+alpha1^2+2*alpha1*beta1+alpha1*beta1*x+beta1))/((alpha1+beta1)*(1+alpha1)^(x+2))
1-cf
#Truncated NEw genralized poisson lindley Disrtribution
UT <-function(x1,alpha1,beta1,Tr){
x=Tr
cf=((alpha1+beta1)*(1+alpha1)^(x+2)-(alpha1+alpha1^2+2*alpha1*beta1+alpha1*beta1*x+beta1))/((alpha1+beta1)*(1+alpha1)^(x+2))
numerator =alpha1^2 * (1 + alpha1 + beta1 + beta1 * x1)
denominator = (alpha1 + beta1) * (alpha1 + 1)^(x1 + 2)
result=numerator/denominator
result1=result/(1-cf)
return(result1)
}
UT(4:100,0.2,3,3)
#sum of probilities of Truncated NGPLD is one
sum(UT(4:100,0.2,3,3))
plot(Tx,UT(Tx,alpha1,beta1,Tr))
#Mean and Varince of Truncated NGPLD
#mean of Truncated NGPLD
f1=function(alpha1,beta1,Tr){
x1=Tr+1:100
f1=(x1*alpha1^2*(1+alpha1+beta1+beta1*x1))/((alpha1+beta1)*(alpha1+1)^(x1+2))
return(sum(f1))
}
X=f1(alpha1,beta1,Tr)/(1-cf)
X;mean(Tx)
#varince of Truncated NGPLD
f3=function(alpha1,beta1,Tr){
x1=Tr+1:100
f3=(x1*(x1-1)*alpha1^2*(1+alpha1+beta1+beta1*x1))/((alpha1+beta1)*(alpha1+1)^(x1+2))
return(sum(f3))
}
vx=f3(alpha1,beta1,Tr)/(1-cf)+f1(alpha1,beta1,Tr)/(1-cf)-(f1(alpha1,beta1,Tr)/(1-cf))^2
vx;var(Tx)
#likelihood function of Truncated NGPLD
lik=function(par,data){
x1<-data
alpha1=par[1];beta1=par[2];
ll=-sum(log(UT(Tx, alpha1, beta1,Tr)))
return(ll)}
# MLE Of Truncated NGPLD
pp=optim(par=c(alph1=1,beta1=2),fn=lik,data=Tx,
control = list(parscale=c(alph1=1,beta1=1)))
#estimated parameter
ap1=pp$par[1];bt1=pp$par[2];ap1;bt1
Just changed your
negative log-likelihoodfunction to usex1instead ofTxand it worked for meThe next plot shows the
negative log-likelihoodfunction surface as a function ofalphaandbeta, the functionoptim()tries to minimize the function, starting from the initial point.Here is the distribution with MLE fitted parameters, the density plotted on data histogram:
EDIT
Take a closer look at the contour of the
NLLfunction, which we are aiming to minimize:Note that the
nllikfunction is very highly sensitive with the change in value ofalpha, but less sensitive with the change in the value ofbetabeyond a point.Note that the function keeps on decreasing (though the rate of decrease is small) till
beta=10whenalpha=0.205, that's whyoptim()finds highbetavalues for this particular value ofalpha(is it as per expectation? if not, you may want to double-check the functionUT()for the computation of the pmf for theTNGPLdistribution from the inverse CDF)This is a good resource to learn more about
It's good to include a reference for a distribution which is not common.