0

I want to refit coxph model with variables selected from glmnet. I know how to extract variables name from cv.glmnet fit. However, for categorical data, variable's original name were changed. For example, Sex will become SexM (or SexF). Anyone knows how to extract original names from glmnet object?

Thaole
  • 9
  • 4
  • Those are _not_ the variable names but rather the variable name with the factor level of the non-reference level values as a suffix. – IRTFM Jan 20 '16 at 09:31
  • [link] (http://stackoverflow.com/questions/27801130/extracting-coefficient-variable-names-from-glmnet-into-a-data-frame) I saw someone asked similar question before, but the ways to extract variable name pointed out in the link is not working for variable with suffix. – Thaole Jan 20 '16 at 09:34

1 Answers1

1

Without an example it's difficult to tell exactly what you want, but on the example provided in the help page for glmnet the "variable names" are returned with:

(fit1)$beta@Dimnames[[1]]

Notice that the x argument in the example does not actually have those names as column names but they are assigned such values because the x-object was a matrix. There is also a second set of values (fit1)$beta@Dimnames[[1]]. The objects returned by cv.glmnet also might be what you want. They would be returned by

fit1_cv$glmnet.fit$beta@Dimnames[[1]] # or [[2]]

A specific example would be most helpful.

Note: Also get success with dimnames(coef(fit1_cv))[[1]] or [[2]]. (It's better to use the correct extractor functions.

IRTFM
  • 258,963
  • 21
  • 364
  • 487