leeper / cregg

Simple Conjoint Analyses, Tidying, and Visualization
Other
50 stars 7 forks source link

Variable importance metric? #41

Open markhwhiteii opened 3 years ago

markhwhiteii commented 3 years ago

Please specify whether your issue is about:


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))