hturner / PlackettLuce

PlackettLuce package for Plackett-Luce models in R
https://hturner.github.io/PlackettLuce/
18 stars 5 forks source link

logLikNull from a pltree #36

Closed kauedesousa closed 5 years ago

kauedesousa commented 5 years ago

I recall that version 0.2-4 used to show the logLikNull from a pltree object in its print method. However I cannot see it now. Can you show me how to get it from a pltree in v0.2-6?

example("beans", package = "PlackettLuce")
G <- grouped_rankings(R, rep(seq_len(nrow(beans)), 4))
d <- cbind(G, beans)

pl <- pltree(G ~ maxTN, data = d)

print(pl)
hturner commented 5 years ago

As far as I can see the printed output from pltree has not changed - it only shows the negative log-likelihood of the rankings under the tree model (at the terminal nodes).

The null log-likelihood is the likelihood under the model where all choices are equally likely, i.e. where all items have the same worth. So there is no tree in this case.

One option is to fit the standard PlackettLuce model and extract the null log-likelihood from there:

pl0 <- PlackettLuce(G)
pl0$null.loglik
pl0$df.null

Alternatively, you can extract it from the model at the root of the PlackettLuce tree:

library(partykit)
node_party(pl)$info$object$null.loglik
node_party(pl)$info$object$df.null

which will give the same result.

hturner commented 5 years ago

I just realised another possibility is that the print method from partykit has changed, since the print method for "pltree" objects calls partykit::print.modelparty. In which case possibly the null likelihood could be defined as the likelihood with no tree, i.e. the likelihood of the model at the root node.

In this case, the answer can be obtained in a similar way, but you can use the logLik function:

library(partykit)
logLik(node_party(pl)$info$object)

Hopefully one of those is what you are after!

kauedesousa commented 5 years ago

Both

pl0$null.loglik

and

node_party(pl)$info$object$null.loglik

is what I wanted.

thank you!