| Version: | 0.2.3 | 
| Title: | Likelihood Based Inference | 
| Description: | Maximum likelihood estimation and likelihood ratio test are essential for modern statistics. This package supports in calculating likelihood based inference. Reference: Pawitan Y. (2001, ISBN:0-19-850765-8). | 
| Depends: | R (≥ 3.0.0) | 
| Author: | Kyun-Seop Bae [aut, cre, cph] | 
| Maintainer: | Kyun-Seop Bae <k@acr.kr> | 
| Copyright: | 2023-, Kyun-Seop Bae | 
| License: | GPL-3 | 
| Repository: | CRAN | 
| URL: | https://cran.r-project.org/package=LBI | 
| Packaged: | 2025-08-21 03:29:45 UTC; Kyun-SeopBae | 
| NeedsCompilation: | no | 
| Date/Publication: | 2025-08-21 05:20:02 UTC | 
Likelihood Based Inference
Description
It conducts likelihood based inference.
Details
Modern likelihood concept and maximum likelihood estimation are established by Fisher RA, while Likelihood Ratio Test (LRT) is established by Neyman J. Post-Fisher methods - generalized linear model, survival analysis, and mixed effects model - are all likelihood based. Inferences from the perspective of Fisherian and pure likelihoodist are suggested here.
Author(s)
Kyun-Seop Bae <k@acr.kr>
References
- Wilks SS. The Large-sample Distribution of the Likelihood Ratio for Testing Composite Hypotheses. Ann Math Stat. 1938;9(1):60-62. 
- Edwards AWF. Likelihood. 1972. 
- Fisher RA. Statistical Methods and Scientific Inference. 3e. 1973. 
- Bates DM, Watts DG. Nonlinear Regression Analysis and its Application. 1988. 
- Ruppert D, Cressie N, Carroll RJ. A Transformation/Weighting Model for Estimating Michaelis-Menten Parameters. Cornell University Technical Report 796. 1988. 
- Royall R. Statistical Evidence. 1997. 
- Pinheiro JC, Bates DM. Mixed Effects Models in S and S-PLUS. 2000. 
- Pawitan Y. In All Likelihood: Statistical Modelling and Inference Using Likelihood. 2001. 
- Lehmann EL. Fisher, Nayman, and the Creation of Classical Statistics. 2011. 
- Rohde CA. Introductory Statistical Inference with the Likelihood Function. 2014. 
- Held L, Bové DS. Likelihood and Bayesian Inference. 2020. 
Likelihood Based Confidence Interval of sd and variance assuming Normal Distribution
Description
Likelihood based confidence interval of sd and variance assuming normal distribution. It usually shows narrower interval than convenrtional chi-square interval. This uses estimated likelihood, not profile likelihood.
Usage
  LBCIvar(x, conf.level=0.95)
Arguments
| x | a vector of observation | 
| conf.level | confidence level | 
Details
It calculates (same height) likelihood based confidence interval of sd and variance assuming normal distribution in one group. The likelihood interval is asymmetric and there is no standard error in the output.
Value
| PE | maximum likelihood estimate | 
| LL | lower limit of likelihood interval | 
| UL | upper limit of likelihood interval | 
Author(s)
Kyun-Seop Bae k@acr.kr
Examples
  LBCIvar(lh)
  (length(lh) - 1)*var(lh)/qchisq(c(0.975, 0.025), length(lh) - 1)
Likelihood Interval for a Proportion or a Binomial Distribution
Description
Likelihood interval of a proportion in one group
Usage
  LIbin(y, n, k, conf.level=0.95, eps=1e-8)
Arguments
| y | positive event count of a group | 
| n | total count of a group | 
| k | 1/k likelihood interval will be calculated | 
| conf.level | approximately corresponding confidence level. If k is specified, this is ignored. | 
| eps | Values less than eps are considered as 0. | 
Details
It calculates likelihood interval of a proportion in one group. The likelihood interval is asymmetric and there is no standard error in the output. If you need percent scale, multiply the output by 100.
Value
| y | positive (concerning) event count | 
| n | total trial count | 
| PE | maximum likelihood estimate on the proportion | 
| LL | lower limit of likelihood interval | 
| UL | upper limit of likelihood interval | 
Author(s)
Kyun-Seop Bae k@acr.kr
References
Fisher RA. Statistical methods and scientific inference. 3e. 1973. pp68-76.
See Also
binom.test, prop.test
Examples
  LIbin(3, 14, k=2)
  LIbin(3, 14, k=5)
  LIbin(3, 14, k=15)
  LIbin(3, 14)
# binom.test(3, 14)
# prop.test(3, 14) 
Likelihood Interval of mean, sd and variance assuming Normal Distribution
Description
Likelihood interval of mean and sd assuming normal distribution. This is estimated likelihood interval, not profile likelihood interval.
Usage
  LInorm(x, k, conf.level=0.95, PLOT="", LOCATE=FALSE, Resol=201)
Arguments
| x | a vector of observation | 
| k | 1/k likelihood interval will be calculated | 
| conf.level | approximately corresponding confidence level. If k is specified, this is ignored. | 
| PLOT | "1d" for profile plot or "2d" for contour plot. | 
| LOCATE | use locater. This works only with PLOT="2D" option. | 
| Resol | resolution for plot. This works only with PLOT=TRUE option. | 
Details
It calculates likelihood interval of mean and sd assuming normal distribution in one group. There is no standard error in the output.
Value
| PE | maximum likelihood estimate | 
| LL | lower limit of likelihood interval | 
| UL | upper limit of likelihood interval | 
Author(s)
Kyun-Seop Bae k@acr.kr
Examples
  x = c(-5.3, -4.5, -1.0, -0.7, 3.7, 3.9, 4.2, 5.5, 6.8, 7.4, 9.3)
  LInorm(x, k=1/0.15) # Pawitan Ex10-9 p289
  LInorm(x)
  LInorm(x, PLOT="1d")
  LInorm(x, PLOT="2d", LOCATE=TRUE)
Likelihood Interval of sd and variance assuming Normal Distribution
Description
Likelihood interval of sd and variance assuming normal distribution. This is estimated likelihood interval, not profile likelihood interval.
Usage
  LInormVar(x, k, conf.level=0.95)
Arguments
| x | a vector of observation | 
| k | 1/k likelihood interval will be calculated | 
| conf.level | approximately corresponding confidence level. If k is specified, this is ignored. | 
Details
It calculates likelihood interval of sd and variance assuming normal distribution in one group. The likelihood interval is asymmetric and there is no standard error in the output.
Value
| PE | maximum likelihood estimate | 
| LL | lower limit of likelihood interval | 
| UL | upper limit of likelihood interval | 
Author(s)
Kyun-Seop Bae k@acr.kr
Examples
  x = c(-5.3, -4.5, -1.0, -0.7, 3.7, 3.9, 4.2, 5.5, 6.8, 7.4, 9.3)
  LInormVar(x, k=1/0.15) # Pawitan Ex10-9 p289
  LInormVar(x)
Likelihood Interval of the Mean assuming Poisson Distribution
Description
Likelihood interval of lambda assuming Poisson distribution.
Usage
  LIpois(x, k, n = 1, conf.level = 0.95, eps = 1e-8)
Arguments
| x | raw data vector or a mean value. If the length of x is 1, x is considered as a mean. | 
| k | 1/k likelihood interval will be calculated. | 
| n | number of observations. If the length of x is 1, x is considered as the mean. | 
| conf.level | approximately corresponding confidence level. If k is specified, this is ignored. | 
| eps | estimated values less than this eps are considered as 0. | 
Details
It calculates likelihood interval of mean(lambda) assuming Poisson distribution. The likelihood interval is asymmetric and there is no standard error in the output.
Value
| PE | maximum likelihood estimate on the lambda | 
| LL | lower limit of likelihood interval | 
| UL | upper limit of likelihood interval | 
| n | number of observations | 
| k | 1/k likelihood interval provided | 
| logk | log(k) of k value | 
| maxLL without factorial | maximum log likelihood without factorial part | 
Author(s)
Kyun-Seop Bae k@acr.kr
Examples
  LIpois(4, k=15)     # Fisher
  LIpois(4, k=exp(2)) # Edwards
  LIpois(4, k=1/0.15) # Pawitan
  LIpois(4, k=8)      # Rhode
  LIpois(4, n=4)      # Bae
  LIpois(4)           # Bae
#  poisson.test(4)
  LIpois(4, k=32)     # 0.7454614 11.7893612
  LIpois(2.1, n=60)   # 1.750222   2.493533
Likelihood Interval of the ratio of two variances from two groups
Description
Likelihood interval of the ratio of two variances from two groups assuming normal distribution. Likelihood interval usually gives a narrower interval when the likelihood function is asymmetric.
Usage
  LIvRatio(x, y, k, conf.level=0.95)
Arguments
| x | observations from the first group, the test group, used for the numerator | 
| y | observations from the second group, the control group, used for the denominator | 
| k | 1/k likelihood interval will be provided | 
| conf.level | approximate confidence level | 
Details
It calculates likelihood interval of the ratio of two variances from two groups. Likelihood interval usually gives a narrower interval when the likelihood function is asymmetric.
Value
| PE | maximum likelihood estimate on the ratio | 
| LL | lower limit of likelihood interval | 
| UL | upper limit of likelihood interval | 
| logk | log(k) value used for LI | 
| maxLL | maximum log likelihood | 
| conf.level | approximate confidence level | 
Author(s)
Kyun-Seop Bae k@acr.kr
Examples
  LIvRatio(mtcars$drat, mtcars$wt)
  var.test(mtcars$drat, mtcars$wt)
  LIvRatio(mtcars$qsec, mtcars$wt)
  var.test(mtcars$qsec, mtcars$wt)
  LIvtest(sd(mtcars$qsec), nrow(mtcars), sd(mtcars$wt), nrow(mtcars))
Likelihood Interval of variance and sd assuming Normal Distribution with sample mean and sample size
Description
Likelihood interval of sd and variance assuming normal distribution. This is estimated likelihood interval, not profile likelihood interval.
Usage
  LIvar(s1, n1, k, conf.level=0.95)
Arguments
| s1 | standard deviation of the sample | 
| n1 | sample size | 
| k | 1/k likelihood interval will be calculated | 
| conf.level | approximately corresponding confidence level. If k is specified, this is ignored. | 
Details
It calculates likelihood interval of sd and variance assuming normal distribution in one group. The likelihood interval is asymmetric and there is no standard error in the output.
Value
| PE | maximum likelihood estimate on the population variance | 
| LL | lower limit of likelihood interval | 
| UL | upper limit of likelihood interval | 
Author(s)
Kyun-Seop Bae k@acr.kr
Examples
  x = c(-5.3, -4.5, -1.0, -0.7, 3.7, 3.9, 4.2, 5.5, 6.8, 7.4, 9.3)
  LInormVar(x)
  LIvar(sd(x), length(x))
Likelihood Interval of variance and sd assuming Normal Distribution using means and SDs
Description
Likelihood interval of variance and sd assuming normal distribution. This is estimated likelihood interval, not profile likelihood interval.
Usage
  LIvtest(s1, n1, s2, n2, k, conf.level=0.95)
Arguments
| s1 | sample standard deviation of the first group | 
| n1 | sample size of the first group | 
| s2 | sample standard deviation of the second group | 
| n2 | sample size of the second group | 
| k | 1/k likelihood interval will be calculated | 
| conf.level | approximate confidence level. If k is specified, this is ignored. | 
Details
It calculates likelihood interval of variance and sd using sufficient statistics. There is no standard error in the output.
Value
| PE | maximum likelihood estimate on the ratio | 
| LL | lower limit of likelihood interval | 
| UL | upper limit of likelihood interval | 
| logk | log(k) value used for LI | 
| maxLL | maximum log likelihood | 
| conf.level | approximate confidence level | 
Author(s)
Kyun-Seop Bae k@acr.kr
Examples
  LIvtest(10.5, 3529, 8.9, 5190)
  LIvtest(3, 10, 2, 10)
  LIvtest(3, 10, 2, 10, k=15)
Likelihood Ratio Test
Description
Likelihood ratio test with given fitting results, sample size, number of parameters, log-likelihoods, and alpha
Usage
  LRT(n, pFull, pReduced, logLikFull, logLikReduced, alpha=0.05, Wilks=FALSE)
Arguments
| n | number of observations | 
| pFull | number of parameters of full model | 
| pReduced | number of parameters of reduced model | 
| logLikFull | log likelihood of full model | 
| logLikReduced | log likelihood of reduced model | 
| alpha | alpha value for type I error, significance level | 
| Wilks | if TRUE, Wilks theorem (chi-square distribution) will be used, otherwise F distribution will be used. | 
Details
It performs likelihood ratio test with given fitting results. The default test is using F distribution. For small n (i.e. less than 100), you need to use F distribution. If the residuals are normally distributed, the delta -2 log likelihood (the difference between -2LL, the objective function value of each model) follows exactly an F-distribution, independent of sample size. When the distribution of the residuals is not normal (no matter what the distribution of the residuals is), it approaches a chi-square distribution as sample size increases (Wilks' theorem). The extreme distribution of the F-distribution (when the degrees of freedom in the denominator go to infinity) is chi-square distribution. The p-value from the F-distribution is slightly larger than the p-value from the chi-square distribution, meaning the F-distribution is more conservative. The difference decreases as sample size increases.
Value
| n | number of observations | 
| paraFull | number of parameters of full model | 
| paraReduced | number of parameters of reduced model | 
| deltaPara | difference of parameter counts | 
| cutoff | cutoff, threshold, critical value of log-likelihood for the test | 
| deltaLogLik | difference of log likelihood, if negative 0 is used. | 
| Chisq or Fval | statistics according to the used distribution Chi-square of F | 
| pval | p-value of null hypothesis. i.e. the reduced model is better. | 
| Verdict | the model preferred. | 
Author(s)
Kyun-Seop Bae k@acr.kr
References
- Ruppert D, Cressie N, Carroll RJ. A Transformation/Weighting Model For Estimating Michaelis-Menten Parameters. School of Operations Research and Industrial Engineering, College of Engineering, Cornell University. Technical Report No. 796. May 1988. 
- Scheffé H. The Analysis of Variance. Wiley. 1959. 
- Wilks SS. The Large-Sample Distribution of the Likelihood Ratio for Testing Composite Hypotheses. Annals Math. Statist. 1938;9:60-62 
Examples
  LRT(20, 4, 2, -58.085, -60.087)
  LRT(20, 4, 2, -58.085, -60.087, Wilks=TRUE)
  LRT(20, 4, 2, -57.315, -66.159)
  LRT(20, 4, 2, -57.315, -66.159, Wilks=TRUE)
  r1 = lm(mpg ~ disp + drat + wt, mtcars)
  r2 = lm(mpg ~ disp + drat, mtcars)
  anova(r2, r1)
  LRT(nrow(mtcars), r1$rank, r2$rank, logLik(r1), logLik(r2))  
Odds Ratio and its Likelihood Interval between two groups without strata
Description
Odds ratio and its likelihood interval between two groups without stratification
Usage
  ORLI(y1, n1, y2, n2, conf.level=0.95, k, eps=1e-8)
Arguments
| y1 | positive event count of test (the first) group | 
| n1 | total count of the test (the first) group. Maximum allowable value is 1e8. | 
| y2 | positive event count of control (the second) group | 
| n2 | total count of control (the second) group. Maximum allowable value is 1e8. | 
| conf.level | approximate confidence level to calculate k when k is missing. | 
| k | 1/k likelihood interval will be provided | 
| eps | absolute value less than eps is regarded as negligible | 
Details
It calculates risk (proportion) difference and its likelihood interval between the two groups. The likelihood interval is asymmetric, and there is no standard error in the output. This does not support stratification.
Value
There is no standard error.
| odd1 | odd from the first group, y1/(n1 - y1) | 
| odd2 | odd from the second group, y2/(n2 - y2) | 
| OR | odds ratio, odd1/odd2 | 
| lower | lower likelihood limit of OR | 
| upper | upper likelihood limit of OR | 
Author(s)
Kyun-Seop Bae k@acr.kr
Examples
  ORLI(7, 10, 3, 10)
  ORLI(3, 10, 7, 10)
Likelihood Ratio Test for One group vs Two group gaussian mixture model
Description
With a given vector, it performs likelihood ratio test which model - one or two group - is better.
Usage
  OneTwo(x, alpha=0.05)
Arguments
| x | a vector of numbers | 
| alpha | alpha value for type I error, significance level | 
Details
It performs likelihood ratio test using both F distribution and Chi-square distribution (by Wilks' theorem).
Value
| Estimate | n, Mean, SD for each group assumption and prior probability of each group in two group model | 
| Delta | delta number of parameters and log-likelihoods | 
| Statistic | Statistics from both the F distribution and Chi-square distribtuion. Cutoff is in terms of log-likelihood not the statistic. | 
Author(s)
Kyun-Seop Bae k@acr.kr
Examples
  OneTwo(c(7, 5, 17, 13, 16, 5, 7, 3, 8, 10, 8, 14, 14, 11, 14, 17, 2, 12, 15, 19))
  OneTwo(c(5, 3, 0, 6, 5, 2, 6, 6, 4, 4, 15, 13, 18, 18, 19, 14, 19, 13, 19, 18))
Risk (Proportion) Difference and its Likelihood Interval between two groups without strata
Description
Risk difference and its likelihood interval between two groups without stratification
Usage
  RDLI(y1, n1, y2, n2, conf.level=0.95, k, eps=1e-8)
Arguments
| y1 | positive event count of test (the first) group | 
| n1 | total count of the test (the first) group. Maximum allowable value is 1e8. | 
| y2 | positive event count of control (the second) group | 
| n2 | total count of control (the second) group. Maximum allowable value is 1e8. | 
| conf.level | approximate confidence level to calculate k when k is missing. | 
| k | 1/k likelihood interval will be provided | 
| eps | absolute value less than eps is regarded as negligible | 
Details
It calculates risk (proportion) difference and its likelihood interval between the two groups. The likelihood interval is asymmetric, and there is no standard error in the output. This does not support stratification.
Value
There is no standard error.
| p1 | proportion from the first group, y1/n1 | 
| p2 | proportion from the second group, y2/n2 | 
| RD | risk difference, p1 - p2 | 
| lower | lower likelihood limit of RD | 
| upper | upper likelihood limit of RD | 
Author(s)
Kyun-Seop Bae k@acr.kr
Examples
  RDLI(7, 10, 3, 10)
  RDLI(3, 10, 7, 10)
Relative Risk and its Likelihood Interval between two groups without strata
Description
Relative risk and its likelihood interval between two groups without stratification
Usage
  RRLI(y1, n1, y2, n2, conf.level=0.95, k, eps=1e-8)
Arguments
| y1 | positive event count of test (the first) group | 
| n1 | total count of the test (the first) group. Maximum allowable value is 1e8. | 
| y2 | positive event count of control (the second) group | 
| n2 | total count of control (the second) group. Maximum allowable value is 1e8. | 
| conf.level | approximate confidence level to calculate k when k is missing. | 
| k | 1/k likelihood interval will be provided | 
| eps | absolute value less than eps is regarded as negligible | 
Details
It calculates relative risk and its likelihood interval between the two groups. The likelihood interval is asymmetric, and there is no standard error in the output. This does not support stratification.
Value
There is no standard error.
| p1 | proportion from the first group, y1/n1 | 
| p2 | proportion from the second group, y2/n2 | 
| RR | relative risk, p1/p2 | 
| lower | lower likelihood limit of RR | 
| upper | upper likelihood limit of RR | 
Author(s)
Kyun-Seop Bae k@acr.kr
Examples
  RRLI(7, 10, 3, 10)
  RRLI(3, 10, 7, 10)