Questions tagged [log-likelihood]

Only questions related to the implementation and usage of the mathematical function - log-Likelihood should use this tag.

Given a sample and a parametric family of distributions (i.e., a set of distributions indexed by a parameter) that could have generated the sample, the Likelihood is a function that associates to each parameter the probability (or probability density) of observing the given sample.

The log-Likelihood a function which is the natural logarithm of the Likelihood function

For many applications, the log-Likelihood, is more convenient to work with as compared to the Likelihood. This is because we are generally interested in where the Likelihood reaches its maximum value. Since the logarithm is a strictly increasing function, the logarithm of a function achieves its maximum value at the same points as the function itself, hence the log-likelihood can be used in place of the likelihood for maximum likelihood estimation and related techniques.

Finding the maximum of a function often involves taking the derivative of a function and solving for the parameter being maximized, and this is often easier when the function being maximized is a log-likelihood rather than the original likelihood function, because the probability of the conjunction of several independent variables is the product of probabilities of the variables and solving an additive equation is usually easier than a multiplicative one.

232 questions
3
votes
2 answers

how to get the log likelihood for a logistic regression model in sklearn?

I'm using a logistic regression model in sklearn and I am interested in retrieving the log likelihood for such a model, so to perform an ordinary likelihood ratio test as suggested here. The model is using the log loss as scoring rule. In the…
2
votes
1 answer

Different values of the log-loss in statsmodels and sklearn

The libraries statsmodels and sklearn produce different values of the log-loss function. A toy example: import pandas as pd import statsmodels.api as sm from sklearn.metrics import log_loss df = pd.DataFrame( columns=['y','x1','x2'], …
dwolfeu
  • 1,103
  • 2
  • 14
  • 21
2
votes
2 answers

Fast logarithm of the negative binomial probability mass function computation in Python

I am implementing an MCMC procedure, in which the most time-consuming part is calculating the logarithm of the negative binomial probability mass function (with matices as argument). The likelihood is computed in every iteration of the procedure for…
2
votes
1 answer

Efficiently compute a sum based on sequences in R

I'm trying to compute a specific sum in R as quickly as possible. The object of interest is and the relevant input objects are two L times K matrices x (contains only positive integers) and alpha (contains only positive real values). A is…
yrx1702
  • 1,619
  • 15
  • 27
2
votes
0 answers

Maximum likelihood estimator stuck at bounds

I'm working on setting up a maximum likelihood estimator to estimate the parameters for a dirichlet-multinomial distribution. Based on what I've seen elsewhere, it looks like the function ddirichlet.multinom() is working as expected, but when I pass…
Mark Rieke
  • 306
  • 3
  • 13
2
votes
1 answer

Writing a log-likelihood as a function in R (what is theta?)

I have the following log-likelihood from my model which i am trying to write as a function in R. My issue come as i dont know how to write theta in terms of the the function. I have had a couple of attempts at this as shown below, any tips/advice…
Joe
  • 795
  • 1
  • 11
2
votes
1 answer

my location-scale estimator function not working with polynomial mean

I'm building my own maximum likelihood estimator that estimates the parameters associated with the mean and standard deviation. On simulated data my function works when the true mean is a linear function and the standard deviation is constant.…
WiggyStardust
  • 182
  • 1
  • 10
2
votes
1 answer

How to define a function of `f_n-chi-square and use `uniroot` to find Confidence Interval?

I want to get a 95% confidence interval for the following question. I have written function f_n in my R code. I first randomly sample 100 with Normal and then I define function h for lambda. Then I can get f_n. My question is that how to define a…
Hermi
  • 357
  • 1
  • 11
2
votes
1 answer

Creating a for loop to calculate AIC scores for different models using lm

Im trying to create AIC scores for several different models in a for loop. I have created a for loop with the log likeliness for each model. However, I am stuck to create the lm function so that it calculates a model for each combination of my…
kikib
  • 21
  • 1
2
votes
3 answers

Pythonic way to calculate cumulative sum with complex math over numpy array

I'm performing Data Science and am calculating the Log Likelihood of a Poisson Distribution of arrival times. def LogLikelihood(arrival_times, _lambda): """Calculate the likelihood that _lambda predicts the arrival_times well.""" ll = 0 for t…
2
votes
2 answers

how to prevent R from showing exp and log values inf and zero

I am going to calculate matrix normal densities to use them in loglikelihood formula. in my calculations, I need to calculate exponential of large numbers ( tens of million ). I realized, R gives back infinity for exp(i), when i >=710. is there…
Mathica
  • 1,241
  • 1
  • 5
  • 17
2
votes
1 answer

Error in solve.default(oout$hessian) : Lapack routine dgesv: system is exactly singular: U[1,1] = 0

I am using the maximum likelihood method to estimate a set of parameters. Now I am going to use mle function from the stats4 package in R to make a profile likelihood for one of the parameters. To do that, I need to fix one of the parameters when I…
2
votes
2 answers

How do I access the dispersion parameter estimate in glm(), and why doesn't it seem to be using Iteratively Reweighted Least Squares?

In this question / answer from 5 years ago about logLik.lm() and glm(), it was pointed out that code comments in the R stats module suggest that lm() and glm() are both internally calculating some kind of scale or dispersion parameter--presumably…
stachyra
  • 4,423
  • 4
  • 20
  • 34
2
votes
1 answer

Find log-likelihood using the predicted probabilities in r

I built a glm model and used it to predict probabilities for the test data. model = glm(y ~ x, data=dt, family=binomial(link='logit')) pred = predict(model, newdata=test.dt, type='response') How do I find the test log-likelihood for the predicted…
user572780
  • 257
  • 3
  • 10
2
votes
2 answers

Use of data with negative weights in unbinned maximum likelihood fit in zfit

I am trying to perform an unbinned 3D angular fit in zfit, where the input data is a sample with per-event sWeights assigned from a separate invariant mass peak fit. I think I'm running into issues of negatively weighted events in some regions of…
dhill89
  • 61
  • 4
1
2
3
15 16