stan-dev / projpred

Projection predictive variable selection
https://mc-stan.org/projpred/
Other
110 stars 26 forks source link

Add argument `size_position` to `plot.vsel()` #484

Closed fweber144 closed 7 months ago

fweber144 commented 7 months ago

This adds argument size_position to plot.vsel(). Illustrations:

data("df_gaussian", package = "projpred")
dat <- data.frame(y = df_gaussian$y, df_gaussian$x)
rfit <- rstanarm::stan_glm(y ~ X1 + X2 + X3 + X4 + X5, data = dat, chains = 1,
                           iter = 500, seed = 8582, refresh = 0)

library(projpred)
vs <- varsel(rfit, method = "L1", nclusters_pred = 2, seed = 7203)
# Moving the submodel sizes above the (primary) x-axis:
plot(vs, text_angle = 90, size_position = "primary_x_top") +
  ggplot2::theme(axis.text.x.bottom = ggplot2::element_text(hjust = 1))

Rplot

# Moving the submodel sizes into a secondary x-axis:
plot(vs, text_angle = 90, size_position = "secondary_x") +
    ggplot2::theme(axis.text.x.bottom = ggplot2::element_text(hjust = 1))

Rplot01

Tests are running through with this PR, but I haven't had the time to implement new tests for this argument size_position. I suggest we implement these in the future (will add that to my projpred to-do list).

fweber144 commented 7 months ago

With commit https://github.com/stan-dev/projpred/pull/484/commits/2e705b38eb417806edfc0445d2c2b89f467ab30c, the plots from above can be created as follows:

data("df_gaussian", package = "projpred")
dat <- data.frame(y = df_gaussian$y, df_gaussian$x)
rfit <- rstanarm::stan_glm(y ~ X1 + X2 + X3 + X4 + X5, data = dat, chains = 1,
                           iter = 500, seed = 8582, refresh = 0)

library(projpred)
vs <- varsel(rfit, method = "L1", nclusters_pred = 2, seed = 7203)
# Moving the submodel sizes above the (primary) x-axis:
plot(vs, text_angle = 90, size_position = "primary_x_top")

Rplot

# Moving the submodel sizes into a secondary x-axis:
plot(vs, text_angle = 90, size_position = "secondary_x")

Rplot01

The tests are still running through.

@avehtari: Can this be merged?

avehtari commented 7 months ago

Tested. Looks good!

fweber144 commented 7 months ago

Thanks. Merging now.