id_sim_gen: Simulate IRT ideal point data

View source: R/Simulate.R

id_sim_genR Documentation

Simulate IRT ideal point data

Description

A function designed to simulate IRT ideal point data.

Usage

id_sim_gen(
  num_person = 20,
  num_items = 50,
  cov_effect = NULL,
  person_cov = NULL,
  person_cov_effect = NULL,
  item_cov = NULL,
  item_discrim_cov_effect = NULL,
  item_miss_cov = NULL,
  item_miss_discrim_cov_effect = NULL,
  model_type = "binary",
  latent_space = FALSE,
  absence_discrim_sd = 3,
  absence_diff_mean = 0,
  discrim_reg_upb = 1,
  discrim_reg_lb = -1,
  discrim_miss_upb = 1,
  discrim_miss_lb = -1,
  discrim_reg_scale = 2,
  discrim_reg_shape = 2,
  discrim_miss_scale = 2,
  discrim_miss_shape = 2,
  discrim_corr = 0,
  num_dim = 1,
  diff_sd = 3,
  time_points = 1,
  time_process = "random",
  time_sd = 0.1,
  ideal_pts_sd = 3,
  prior_type = "gaussian",
  ordinal_outcomes = 3,
  inflate = FALSE,
  sigma_sd = 1,
  spline_knots = NULL,
  spline_degree = 2,
  spline_intercept_sd = 0.5,
  spline_basis_sd = 0.5,
  phi = 1,
  binom_trials = 10,
  gp_rho = 0.5,
  gp_alpha = 0.5,
  gp_nugget = 0.1
)

Arguments

num_person

The number of persons/persons

num_items

The number of items (bills in the canonical ideal point model)

cov_effect

The effect of a hierarchical/external covariate on the person ideal points. The covariate will be a uniformly-distributed random variable on the [0,1] scale, so covariate effects in the [-2,2] approximate range would result in noticeable effects on the ideal point scale. This is a legacy parameter; prefer using person_cov and person_cov_effect for more control.

person_cov

Either NULL (no covariate), "continuous" to generate a uniform random covariate, "binary" to generate a binary (0/1) covariate, or a numeric matrix with num_person rows where each column is a covariate. If cov_effect is provided and person_cov is NULL, defaults to "continuous" for backward compatibility.

person_cov_effect

A numeric vector of regression coefficients for person covariates. Length must match the number of columns in person_cov matrix. If person_cov is "continuous" or "binary", a single value should be provided.

item_cov

Either NULL (no covariate), "continuous" to generate a uniform random covariate, "binary" to generate a binary (0/1) covariate, or a numeric matrix with num_items rows where each column is a covariate.

item_discrim_cov_effect

A numeric vector of regression coefficients for the effect of item covariates on item discrimination parameters (gamma). Length must match the number of columns in item_cov matrix.

item_miss_cov

Either NULL (no covariate), "continuous" to generate a uniform random covariate, "binary" to generate a binary (0/1) covariate, or a numeric matrix with num_items rows where each column is a covariate. Used for missingness model parameters.

item_miss_discrim_cov_effect

A numeric vector of regression coefficients for the effect of item missing covariates on absence discrimination parameters (nu). Length must match the number of columns in item_miss_cov matrix.

model_type

One of 'binary', 'ordinal_ratingscale', 'ordinal_grm', 'poisson' 'normal', 'lognormal', 'ordbeta' or 'binomial'

latent_space

Whether to use the latent space formulation of the ideal point model FALSE by default. NOTE: currently, the package only has estimation for a binary response with the latent space formulation. The positions of the persons (in time-varying models, their starting positions) are then drawn from the same generalized Beta distribution as the item positions (discrim_reg_lb, discrim_reg_upb, discrim_reg_scale and discrim_reg_shape), so that persons and items share a space. A person outside the range of the item positions has an ideal point the data can't identify, because the person intercept absorbs its distance to the items. The person and item intercepts are drawn from Normal(0, 0.5) (instead of using ideal_pts_sd and diff_sd): there is no coefficient on the distances, so wider intercepts would swamp them and leave little information about the positions.

absence_discrim_sd

The SD of the discrimination parameters for the inflated model

absence_diff_mean

The mean intercept for the inflated model; increasing it will lower the total number of missing data

discrim_reg_upb

The upper bound of the generalized Beta distribution for the observed discrimination parameters (gamma)

discrim_reg_lb

The lower bound of the generalized Beta distribution for the observed discrimination parameters (gamma)

discrim_miss_upb

The upper bound of the generalized Beta distribution for the missingness discrimination parameters (nu)

discrim_miss_lb

The lower bound of the generalized Beta distribution for the missingness discrimination parameters (nu)

discrim_reg_scale

The scale parameter for the generalized Beta distribution for the observed discrimination parameters (gamma)

discrim_reg_shape

The shape parameter for the generalized Beta distribution for the observed discrimination parameters (gamma)

discrim_miss_scale

The scale parameter for the generalized Beta distribution for the missingness discrimination parameters (nu)

discrim_miss_shape

The shape parameter for the generalized Beta distribution for the missingness discrimination parameters (nu)

discrim_corr

The correlation between each item's observed (gamma) and missingness (nu) discriminations, between -1 and 1. The two are drawn from a Gaussian copula with this correlation, so each keeps its generalized Beta distribution. Corresponds to discrim_corr=TRUE in id_estimate(). Default is 0 (independent discriminations).

num_dim

The number of dimensions of the ideal points. Default is 1. Each extra dimension has its own person ideal points (from the same time_process) and its own observed and missingness discriminations (from the same generalized Beta distributions, correlated by discrim_corr). Person covariates only shift dimension

  1. The values for dimensions 2 to num_dim are stored in true_person_d (persons x time points x num_dim - 1), true_reg_discrim_d and true_abs_discrim_d (items x num_dim - 1) in the simul_data slot of the result. Corresponds to num_dim in id_estimate().

diff_sd

The SD of the difficulty parameters (bill/item intercepts) for both missing and observed parameters (beta and omega). With latent_space=TRUE, the item and person intercepts instead have SD 0.5 (see latent_space).

time_points

The number of time points for time-varying legislator/person parameters

time_process

The process used to generate the ideal points: either 'random' for a random walk, 'AR' for an AR1 process, 'GP' for a Gaussian process, or 'splines' for a spline (see parameters spline_knots and spline_degree).

time_sd

The standard deviation of the change in ideal points over time (should be low relative to ideal_pts_sd)

ideal_pts_sd

The SD for the person/person ideal points (not used with latent_space=TRUE; see latent_space)

prior_type

The statistical distribution that generates the data for ideal point parameters (alpha) and difficulty intercepts (beta and omega). Currently only 'gaussian' is supported.

ordinal_outcomes

If model is 'ordinal', an integer giving the total number of categories

inflate

If TRUE, an missing-data-inflated dataset is produced.

sigma_sd

If a normal or log-normal distribution is being fitted, this parameter gives the standard

spline_knots

Number of knots (essentially, number of points at which to calculate time-varying ideal points given T time points). Default is NULL, which means that the spline is equivalent to polynomial time trend of degree spline_degree. Note that the spline number (if not null) must be equal or less than the number of time points.

spline_degree

The degree of the spline polynomial. The default is 2 which is a quadratic polynomial. A value of 1 will result in independent knots (essentially pooled across time points T). A higher value will result in wigglier time series.

spline_intercept_sd

The SD of the Normal distribution (centered on 0) used to draw the intercept for the basis spline function

spline_basis_sd

The SD of the Normal distribution (centered on 0) for the coefficients used to create the simulated ideal points from the spline function

phi

The phi (dispersion) parameter for the ordered beta distribution deviation of the outcome (i.e. the square root of the variance).

binom_trials

If model_type is 'binomial', the number of trials for each outcome: either a single number or a vector with one value per person-item observation. The simulated data has these in the column outcome_trials.

gp_rho

The rho parameter to the squared exponential kernel function for the GP model

gp_alpha

The alpha parameter to the squared exponential kernel function for the GP model

gp_nugget

The nugget of the squared-exponential kernel (equals additional variance of the GP-distributed ideal points)

Details

This function produces simulated data that matches (as closely as possible) the models used in the underlying Stan code. Currently the simulation can produce inflated and non-inflated models with binary, ordinal (GRM and rating-scale), Poisson, Normal and Log-Normal responses.

Value

The results is a idealdata object that can be used in the id_estimate function to run a model. It can also be used in the simulation plotting functions.

See Also

id_show_trues() for plotting fitted models versus true values.

Examples

# Simulate binary (non-inflated) data for 20 persons and 50 items
sim <- id_sim_gen(num_person=20, num_items=50, inflate=FALSE)
head(sim@score_matrix)

# Simulate an ordinal graded-response model with missing-data inflation
sim_ord <- id_sim_gen(model='ordinal_grm', inflate=TRUE, num_person=10, num_items=20)

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