id_plot_cov: Marginal Effects Plot for Hierarchical Covariates

View source: R/Plot.R

id_plot_covR Documentation

Marginal Effects Plot for Hierarchical Covariates

Description

This function will calculate and plot the ideal point marginal effects, or the first derivative of the IRT/ideal point model with respect to the hierarchical covariate, for each item in the model. The function id_me() is used to first calculate the ideal point marginal effects.

Usage

id_plot_cov(
  object,
  calc_param = NULL,
  label_high = "High",
  label_low = "Low",
  group_effects = NULL,
  plot_model_id = NULL,
  pred_outcome = NULL,
  lb = 0.05,
  upb = 0.95,
  facet_ncol = 2,
  cov_type = "person_cov",
  dim = 1,
  ...
)

Arguments

object

A fitted idealstan object

calc_param

Whether to calculate ideal point marginal effects for a given covariate. If NULL, the default, the function will instead produce a plot of the raw coefficients from the ideal point model. If passing the name of a covariate, should be a character value of a column in the data passed to the id_make function.

label_high

What label to use on the plot for the high end of the latent scale

label_low

What label to use on the plot for the low end of the latent scale

group_effects

Character value for name of column in data by which to subset the data. Must be a column passed to the id_make function

plot_model_id

The integer of the model ID to plot. If NULL and there are multiple model types, facet_wrap will be used to produce multiple plots with one for each model type.

pred_outcome

For discrete models with more than 2 categories, or binary models with missing data, which outcome to predict. This should be the value that matches what the outcome was coded as in the data passed to id_make().

lb

The lower limit of the posterior density to use for calculating credible intervals

upb

The upper limit of the posterior density to use for calculating credible intervals

facet_ncol

If facetting by multiple models or grouped factors, sets the number of columns in the multiple plots

cov_type

Either 'person_cov' for person or group-level hierarchical parameters, 'discrim_reg_cov' for bill/item discrimination parameters from regular (non-inflated) model, and 'discrim_infl_cov' for bill/item discrimination parameters from inflated model.

dim

For models with more than one dimension, the dimension whose covariate effects to plot. Default is 1.

...

Additional argument passed on to id_me

Details

The ends of the latent variable can be specified via the label_low and label_high options, which will use those labels for item discrimination.

Note that the function produces a ggplot2 object, which can be further modified with ggplot2 functions.

Value

A ggplot2 plot that can be further customized with ggplot2 functions if need be.

Examples



# Fit a model with a person-level covariate
data('senate114')
senate114$cast_code <- ifelse(senate114$cast_code=="Absent", NA,
                              as.integer(senate114$cast_code) - 1L)
senate114$age <- (2018 - senate114$born - mean(2018 - senate114$born)) / 10
sen_cov <- id_make(senate114, outcome_disc='cast_code',
                   person_id='bioname', item_id='rollnumber',
                   group_id='party_code', person_cov=~party_code+age)
sen_cov_est <- id_estimate(sen_cov, model_type=1, fixtype='vb_full', 
                use_method="pathfinder", nchains=2, ncores=4)

# Plot marginal effects of age on ideal points
id_plot_cov(sen_cov_est, calc_param='age')

# Plot the raw person-level covariate coefficients
id_plot_cov(sen_cov_est)



idealstan documentation built on Dec. 2, 2026, 5:07 p.m.