Wald confidence intervals and coverage











up vote
-1
down vote

favorite












I am trying to compute observed 95% Wald Confidence intervals centred at the maximum likelihood estimate for realisations of i.i.d Zero Inflated Poisson(p, lambda) random variables (for both p and lambda). I also am trying to use simulations to compute the coverage of these intervals. At the moment I am generating my simulations from (alpha, n, p, lambda)=(0.05, 100, 0.2, 1.5). I am creating multiple functions in r but am wondering if there is an easier way?
This is the code I have so far for the Wald Confidence Intervals



compute.ml.estimates <- function(xs) {


z <- ifelse(xs>0, 0, 1)
n0 <- sum(z)
n <- length(xs)
g <- function(ab) {
p <- ab[1]
lambda <- ab[2]
n0*log(p + (1-p)*exp(-lambda)) + (n-n0)*(log(1-p)-lambda) + log(lambda)*sum(xs)
}
optim.out <- optim(c(0.1, 0.5), fn=g, method="L-BFGS-B", lower=c(0,0), upper=c(Inf, Inf), control=list(fnscale=-1))
p.hat <- optim.out$par[1]
lambda.hat <- optim.out$par[2]
return(c(p.hat, lambda.hat))
}
compute.ml.estimates(data)
theta <- compute.ml.estimates(data)

Fisher.info <- function(theta) {

p <- theta[1]
lambda <- theta[2]
phi <- p + (1-p)*exp(-lambda)

Fisher.info.matrix <- matrix(c(((1-exp(-lambda))/((1-p)*phi)),
(-(exp(-lambda)/phi)),
(-(exp(-lambda)/phi)),
((1-p)*(phi-p*lambda*exp(-lambda))/lambda*phi)),
nrow=2, byrow=TRUE)

return(Fisher.info.matrix)
}

phi

Fisher.info(data)

solve(Fisher.info(data))


but these are the answers



[1] 0.04480545 2.42678858
[1] 0.1291682
[,1] [,2]
[1,] 0 -1
[2,] -1 Inf
[,1] [,2]
[1,] NaN -1
[2,] NaN 0


which is obviously not ideal. I can't tell why it gives NaN










share|improve this question









New contributor




Clem.Rev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




    I think that you should put your code here and see if someone can help. Your request is, in my view, too vague.
    – paoloeusebi
    Nov 21 at 22:29















up vote
-1
down vote

favorite












I am trying to compute observed 95% Wald Confidence intervals centred at the maximum likelihood estimate for realisations of i.i.d Zero Inflated Poisson(p, lambda) random variables (for both p and lambda). I also am trying to use simulations to compute the coverage of these intervals. At the moment I am generating my simulations from (alpha, n, p, lambda)=(0.05, 100, 0.2, 1.5). I am creating multiple functions in r but am wondering if there is an easier way?
This is the code I have so far for the Wald Confidence Intervals



compute.ml.estimates <- function(xs) {


z <- ifelse(xs>0, 0, 1)
n0 <- sum(z)
n <- length(xs)
g <- function(ab) {
p <- ab[1]
lambda <- ab[2]
n0*log(p + (1-p)*exp(-lambda)) + (n-n0)*(log(1-p)-lambda) + log(lambda)*sum(xs)
}
optim.out <- optim(c(0.1, 0.5), fn=g, method="L-BFGS-B", lower=c(0,0), upper=c(Inf, Inf), control=list(fnscale=-1))
p.hat <- optim.out$par[1]
lambda.hat <- optim.out$par[2]
return(c(p.hat, lambda.hat))
}
compute.ml.estimates(data)
theta <- compute.ml.estimates(data)

Fisher.info <- function(theta) {

p <- theta[1]
lambda <- theta[2]
phi <- p + (1-p)*exp(-lambda)

Fisher.info.matrix <- matrix(c(((1-exp(-lambda))/((1-p)*phi)),
(-(exp(-lambda)/phi)),
(-(exp(-lambda)/phi)),
((1-p)*(phi-p*lambda*exp(-lambda))/lambda*phi)),
nrow=2, byrow=TRUE)

return(Fisher.info.matrix)
}

phi

Fisher.info(data)

solve(Fisher.info(data))


but these are the answers



[1] 0.04480545 2.42678858
[1] 0.1291682
[,1] [,2]
[1,] 0 -1
[2,] -1 Inf
[,1] [,2]
[1,] NaN -1
[2,] NaN 0


which is obviously not ideal. I can't tell why it gives NaN










share|improve this question









New contributor




Clem.Rev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




    I think that you should put your code here and see if someone can help. Your request is, in my view, too vague.
    – paoloeusebi
    Nov 21 at 22:29













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I am trying to compute observed 95% Wald Confidence intervals centred at the maximum likelihood estimate for realisations of i.i.d Zero Inflated Poisson(p, lambda) random variables (for both p and lambda). I also am trying to use simulations to compute the coverage of these intervals. At the moment I am generating my simulations from (alpha, n, p, lambda)=(0.05, 100, 0.2, 1.5). I am creating multiple functions in r but am wondering if there is an easier way?
This is the code I have so far for the Wald Confidence Intervals



compute.ml.estimates <- function(xs) {


z <- ifelse(xs>0, 0, 1)
n0 <- sum(z)
n <- length(xs)
g <- function(ab) {
p <- ab[1]
lambda <- ab[2]
n0*log(p + (1-p)*exp(-lambda)) + (n-n0)*(log(1-p)-lambda) + log(lambda)*sum(xs)
}
optim.out <- optim(c(0.1, 0.5), fn=g, method="L-BFGS-B", lower=c(0,0), upper=c(Inf, Inf), control=list(fnscale=-1))
p.hat <- optim.out$par[1]
lambda.hat <- optim.out$par[2]
return(c(p.hat, lambda.hat))
}
compute.ml.estimates(data)
theta <- compute.ml.estimates(data)

Fisher.info <- function(theta) {

p <- theta[1]
lambda <- theta[2]
phi <- p + (1-p)*exp(-lambda)

Fisher.info.matrix <- matrix(c(((1-exp(-lambda))/((1-p)*phi)),
(-(exp(-lambda)/phi)),
(-(exp(-lambda)/phi)),
((1-p)*(phi-p*lambda*exp(-lambda))/lambda*phi)),
nrow=2, byrow=TRUE)

return(Fisher.info.matrix)
}

phi

Fisher.info(data)

solve(Fisher.info(data))


but these are the answers



[1] 0.04480545 2.42678858
[1] 0.1291682
[,1] [,2]
[1,] 0 -1
[2,] -1 Inf
[,1] [,2]
[1,] NaN -1
[2,] NaN 0


which is obviously not ideal. I can't tell why it gives NaN










share|improve this question









New contributor




Clem.Rev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am trying to compute observed 95% Wald Confidence intervals centred at the maximum likelihood estimate for realisations of i.i.d Zero Inflated Poisson(p, lambda) random variables (for both p and lambda). I also am trying to use simulations to compute the coverage of these intervals. At the moment I am generating my simulations from (alpha, n, p, lambda)=(0.05, 100, 0.2, 1.5). I am creating multiple functions in r but am wondering if there is an easier way?
This is the code I have so far for the Wald Confidence Intervals



compute.ml.estimates <- function(xs) {


z <- ifelse(xs>0, 0, 1)
n0 <- sum(z)
n <- length(xs)
g <- function(ab) {
p <- ab[1]
lambda <- ab[2]
n0*log(p + (1-p)*exp(-lambda)) + (n-n0)*(log(1-p)-lambda) + log(lambda)*sum(xs)
}
optim.out <- optim(c(0.1, 0.5), fn=g, method="L-BFGS-B", lower=c(0,0), upper=c(Inf, Inf), control=list(fnscale=-1))
p.hat <- optim.out$par[1]
lambda.hat <- optim.out$par[2]
return(c(p.hat, lambda.hat))
}
compute.ml.estimates(data)
theta <- compute.ml.estimates(data)

Fisher.info <- function(theta) {

p <- theta[1]
lambda <- theta[2]
phi <- p + (1-p)*exp(-lambda)

Fisher.info.matrix <- matrix(c(((1-exp(-lambda))/((1-p)*phi)),
(-(exp(-lambda)/phi)),
(-(exp(-lambda)/phi)),
((1-p)*(phi-p*lambda*exp(-lambda))/lambda*phi)),
nrow=2, byrow=TRUE)

return(Fisher.info.matrix)
}

phi

Fisher.info(data)

solve(Fisher.info(data))


but these are the answers



[1] 0.04480545 2.42678858
[1] 0.1291682
[,1] [,2]
[1,] 0 -1
[2,] -1 Inf
[,1] [,2]
[1,] NaN -1
[2,] NaN 0


which is obviously not ideal. I can't tell why it gives NaN







r code-coverage confidence-interval mle






share|improve this question









New contributor




Clem.Rev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Clem.Rev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 22 at 12:31





















New contributor




Clem.Rev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 21 at 22:13









Clem.Rev

11




11




New contributor




Clem.Rev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Clem.Rev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Clem.Rev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 2




    I think that you should put your code here and see if someone can help. Your request is, in my view, too vague.
    – paoloeusebi
    Nov 21 at 22:29














  • 2




    I think that you should put your code here and see if someone can help. Your request is, in my view, too vague.
    – paoloeusebi
    Nov 21 at 22:29








2




2




I think that you should put your code here and see if someone can help. Your request is, in my view, too vague.
– paoloeusebi
Nov 21 at 22:29




I think that you should put your code here and see if someone can help. Your request is, in my view, too vague.
– paoloeusebi
Nov 21 at 22:29

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Clem.Rev is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421185%2fwald-confidence-intervals-and-coverage%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Clem.Rev is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Clem.Rev is a new contributor. Be nice, and check out our Code of Conduct.













Clem.Rev is a new contributor. Be nice, and check out our Code of Conduct.












Clem.Rev is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421185%2fwald-confidence-intervals-and-coverage%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Catalogne

Violoncelliste

Héron pourpré