profileci

Profiling a Log-Likelihood to Calculate Confidence Intervals

https://github.com/paulnorthrop/profileci

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 1 committers (100.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.8%) to scientific vocabulary

Keywords

confidence-interval confidence-intervals likelihood-based log-likelihood log-likelihood-functions statistical-uncertainties uncertainty-estimation
Last synced: 6 months ago · JSON representation

Repository

Profiling a Log-Likelihood to Calculate Confidence Intervals

Basic Info
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 1
Topics
confidence-interval confidence-intervals likelihood-based log-likelihood log-likelihood-functions statistical-uncertainties uncertainty-estimation
Created 10 months ago · Last pushed 8 months ago
Metadata Files
Readme Changelog License

README.Rmd

---
output: github_document
---



```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# profileCI

[![Appveyor Build status](https://ci.appveyor.com/api/projects/status/99jojhgk9t4agdmv/branch/main?svg=true)](https://ci.appveyor.com/project/paulnorthrop/profileCI/branch/main)
[![R-CMD-check](https://github.com/paulnorthrop/profileCI/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/paulnorthrop/profileCI/actions/workflows/R-CMD-check.yaml)
[![Coverage Status](https://codecov.io/github/paulnorthrop/profileCI/coverage.svg?branch=master)](https://app.codecov.io/github/paulnorthrop/profileCI?branch=master)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/profileCI)](https://cran.r-project.org/package=profileCI)
[![Downloads (monthly)](https://cranlogs.r-pkg.org/badges/profileCI?color=brightgreen)](https://cran.r-project.org/package=profileCI)
[![Downloads (total)](https://cranlogs.r-pkg.org/badges/grand-total/profileCI?color=brightgreen)](https://cran.r-project.org/package=profileCI)

## Profiling a Log-likelihood to Calculate Confidence Intervals

This package computes confidence intervals based on profile log-likelihood for one or more parameters in a user-supplied fitted multi-parameter model. The functionality of the main function, `profileCI()`, is like that of `confint.glm`, which calculates confidence intervals for the parameters of a Generalised Linear Model (GLM). 

Speed of computation can be improved by starting the profiling from limits based on large sample normal theory. The accuracy of the limits can be set by the user. A plot method visualises the log-likelihood and confidence interval. Cases where the profile log-likelihood flattens above the value at which a confidence limit is defined can be handled, leading to a limit at plus or minus infinity. Disjoint confidence intervals will not be found.
    
## An example

We illustrate the use of `profileCI()` using an example from the help file for `stats::glm()`. 

```{r}
## From example(glm)
counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12)
outcome <- gl(3, 1, 9)
treatment <- gl(3, 3)
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())
# Intervals based on profile log-likelihood
confint(glm.D93)
```

To calculate these intervals using `profileCI` we provide a function that calculates the log-likelihood for this Poisson GLM for an input parameter vector `pars`.

```{r}
poisson_loglik <- function(pars) {
  lambda <- exp(model.matrix(glm.D93) %*% pars)
  loglik <- stats::dpois(x = glm.D93$y, lambda = lambda, log = TRUE)
  return(sum(loglik))
}
```

The function `profileCI()` profiles the log-likelihood, with respect to one parameter at a time. For a given value of this parameter the log-likelihood is maximised over the other parameters. The aim is to search below and above the MLE of the parameter until the profile log-likelihood drops to a level corresponding to the limits of the confidence interval of a desired confidence level. 

Two arguments can be used to affect the speed with which the confidence limits are obtained: `mult` determines the amount, as a percentage of the estimated standard error of the estimator of the parameter of interest, by which the value of the parameter is incremented when profiling. Larger values of `mult` should result in a faster calculation but increase the risk that one of the optimisations required will fail. If the argument `faster = TRUE` then the searches for the lower and upper confidence limits are started from limits based on the approximate large  sample normal distribution for the maximum likelihood estimator of a parameter, rather than the maximum likelihood estimate. The defaults are `mult = 32` and `faster = TRUE`.
    
```{r}
library(profileCI)
prof <- profileCI(glm.D93, loglik = poisson_loglik)
prof
```

We can visualise the profile likelihood for a parameter using a plot method. 

```{r }
plot(prof, parm = "outcome2")
```

To obtain smooth version of this plot, we call `profileCI()` with `mult = 8` and `faster = FALSE`, but this is much slower calculation. 

```{r}
prof <- profileCI(glm.D93, loglik = poisson_loglik, mult = 8, faster = FALSE)
plot(prof, parm = "outcome2")
```


By default, once it has been determined that a limit lies between two values of the parameter, quadratic interpolation is used to estimate the value of the limit. If a specific degree of accuracy is required then this can be set by passing a positive tolerance `epsilon` to the `itp` function in the [itp package](https://cran.r-project.org/package=itp).

An alternative to passing the log-likelihood function using the argument `loglik` is to provide the same function via a `logLikFn` S3 method for the fitted model object.

## Installation

To get the current released version from CRAN:

```{r installation, eval = FALSE}
install.packages("profileCI")
```

To install the development version from GitHub:

```{r github, eval = FALSE}
remotes::install_github("paulnorthrop/profileCI")
```

Owner

  • Name: Paul Northrop
  • Login: paulnorthrop
  • Kind: user

GitHub Events

Total
  • Issues event: 1
  • Issue comment event: 8
  • Public event: 1
  • Push event: 49
  • Create event: 1
Last Year
  • Issues event: 1
  • Issue comment event: 8
  • Public event: 1
  • Push event: 49
  • Create event: 1

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 88
  • Total Committers: 1
  • Avg Commits per committer: 88.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 88
  • Committers: 1
  • Avg Commits per committer: 88.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Paul Northrop p****p@u****k 88
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 1
  • Total pull requests: 0
  • Average time to close issues: 6 days
  • Average time to close pull requests: N/A
  • Total issue authors: 1
  • Total pull request authors: 0
  • Average comments per issue: 11.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: 6 days
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 11.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • jsture (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 269 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 2
  • Total maintainers: 1
cran.r-project.org: profileCI

Profiling a Log-Likelihood to Calculate Confidence Intervals

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 269 Last month
Rankings
Dependent packages count: 26.4%
Dependent repos count: 32.5%
Average: 48.5%
Downloads: 86.6%
Maintainers (1)
Last synced: 7 months ago

Dependencies

.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v4 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v4 composite
  • actions/upload-artifact v4 composite
  • codecov/codecov-action v5 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
DESCRIPTION cran
  • R >= 4.1.0 depends
  • graphics * imports
  • itp * imports
  • stats * imports
  • testthat >= 3.0.0 suggests