cregg icon indicating copy to clipboard operation
cregg copied to clipboard

Variable importance metric?

Open markhwhiteii opened this issue 4 years ago • 0 comments

Please specify whether your issue is about:

  • [ ] a possible bug
  • [X] a question about package functionality
  • [ ] a suggested code or documentation change, improvement to the code, or feature request

Is there a way to get an idea of "variable importance" using the cregg package? For example, one might look at the plotted marginal means and ask me, "Well, which variable had the biggest effect?" I was thinking maybe looking at the variance of the marginal means? By way of an example, in the code below, I added a noise variable to immigration. I would want noise to perform very poorly on this variable importance metric.

Another ludicrous example might be testing profiles of political candidates where we say their party and whether or not they like macaroni and cheese. We'd want some metric that says "Political party matters X times more than whether or not they like macaroni and cheese." Is that possible to derive from the output of cj()? I wasn't sure if there is some canonical way of approaching this.

library(cregg)
library(tidyverse)
data("immigration")

set.seed(1839)
immigration$noise <- factor(sample(letters[1:5], nrow(immigration), TRUE))

f <- ChosenImmigrant ~ Gender + Education +
  LanguageSkills + CountryOfOrigin + Job + JobExperience +
  JobPlans + ReasonForApplication + PriorEntry + noise

res <- cj(immigration, f, id = ~ CaseID)

# maybe?
res %>% 
  group_by(feature) %>% 
  summarise(est_var = var(estimate)) %>% 
  arrange(desc(est_var))

markhwhiteii avatar Sep 30 '21 21:09 markhwhiteii