# What does the degree of freedom (df) mean in the results of log-likelihood logLik

After doing the regression using lm for fixed effect model or lmer for mixed effects model, I pass the results to the logLik. Besides the value of log-likelihood, the function always returns a df, i.e. the degree of freedom.

However, the degree of freedom does not equal to the number of parameters in the model, df always larger. So what does the df mean exactly?

The reason I care about the df is that later I will use the BIC (Bayesian Information Criterion) to do the model selection. The BIC is defined as BIC=-2*logLik+k*log(n) where k is the number of parameters and n is the number of observations. When I pass my logLik value to the expression of BIC, the result is exactly the same when I use the build in BIC function in R if I specify the number of parameters as the df in logLik. Which means, in the build in BIC function, they also use the df as k when they calculate BIC.

• Possible duplicate of How to understand degrees of freedom?
– EdM
Feb 18, 2019 at 2:46
• Usually it is something like sample size minus number of parameters estimated. It can be a little more complicated though. Read the suggested question yours is a duplicate of. Feb 18, 2019 at 3:50

The help file for the logLik() function mentions that it returns the number of (estimated) parameters in the model as the degrees of freedom (df).

If you fit a linear model like the one below:

m <- lm(mpg ~ hp, data = mtcars)

summary(m)

logLik(m)


you will see that the model includes an intercept parameter, a slope parameter quantifying the effect of the predictor hp on mpg and an error variance (or standard deviation) parameter. These add up to three parameters, which is exactly what logLik() returns for the model.

If you fit a linear mixed effects model like this:

require(nlme)

M <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1)

summary(M)

logLik(M)


then you'll see that the model includes the following parameters: a fixed effect intercept, a fixed effect of age, a fixed effect of Sex, a parameter denoting the standard deviation of the random intercept and a standard deviation of the within-subject model errors. That makes for five parameters, which is what the logLik() returns.