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
r code-coverage confidence-interval mle
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.
add a comment |
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
r code-coverage confidence-interval mle
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
add a comment |
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
r code-coverage confidence-interval mle
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
r code-coverage confidence-interval mle
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.
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
add a comment |
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
add a comment |
active
oldest
votes
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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