Pregunta

I'm using the package coxme and I want to extract the AIC from models, in order to select the best one.

1) I didn't found how to do this directly and I think this is not possible without changing the function coxme()'s code but I would be very happy to be wrong, let me know if I am !

2) I looked the function's code with the command :

coxme:::print.coxme

in order to add a variable to stock AIC and saw the code but if I call it 'coxme2' for example (I just add coxme2<- at the begining) and try to use it (without any other add), I get an error :

Error in colnames<-(*tmp*, value = c("NULL", "Integrated", "Fitted" : length of 'dimnames' [2] not equal to array extent

To sum it up, the coxme function works well but if I juste copy and paste its code, it doesn't. How can I fix this issue ?

¿Fue útil?

Solución

The AIC can be extracted through

extractAIC.coxme <- function(x){
  loglik <- x$loglik + c(0, 0, x$penalty)
  chi1 <- 2*diff(loglik[1:2]) 
  chi2 <- 2*diff(loglik[c(1,3)])
  c(chi1 - 2*x$df[1], chi2 - 2*x$df[2])
}

fit <- coxme(Surv(time, status) ~ age + sex + (1|ph.ecog), lung)
extractAIC(fit)

See the print.coxme function https://github.com/cran/coxme/blob/master/R/print.coxme.R

Otros consejos

have you tried getAnywhere(print.coxme)? It gives you all the code necessary to copy and modify the function in R.

Edit

Just write

copyOfAIC <<- temp

below of

dimnames(temp) <- list(c("Integrated loglik", " Penalized loglik"), 
                           c("Chisq", "df", "p", "AIC", "BIC"))

And you will get a copy of the values that you are looking for

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top