3
$\begingroup$

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.

$\endgroup$
2
  • 2
    $\begingroup$ Possible duplicate of How to understand degrees of freedom? $\endgroup$
    – EdM
    Feb 18, 2019 at 2:46
  • $\begingroup$ 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. $\endgroup$ Feb 18, 2019 at 3:50

1 Answer 1

3
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.