Learn R Programming

bgms (version 0.1.6.3)

simulate.bgmCompare: Simulate Data from a Fitted bgmCompare Model

Description

Generates new observations from the Markov Random Field model for a specified group using the estimated parameters from a fitted bgmCompare object.

Usage

# S3 method for bgmCompare
simulate(
  object,
  nsim = 500,
  seed = NULL,
  group,
  method = c("posterior-mean"),
  iter = 1000,
  ...
)

Value

A matrix with nsim rows and p columns containing simulated observations for the specified group.

Arguments

object

An object of class bgmCompare.

nsim

Number of observations to simulate. Default: 500.

seed

Optional random seed for reproducibility.

group

Integer specifying which group to simulate from (1 to number of groups). Required argument.

method

Character string specifying which parameter estimates to use:

"posterior-mean"

Use posterior mean parameters (faster, single simulation).

iter

Number of Gibbs iterations for equilibration before collecting samples. Default: 1000.

...

Additional arguments (currently ignored).

Details

Group-specific parameters are obtained by applying the projection matrix to convert baseline parameters and differences into group-level estimates: group_param = baseline + projection[group, ] %*% differences.

The function then uses these group-specific interaction and threshold parameters to generate new data via Gibbs sampling.

See Also

simulate.bgms for simulating from single-group models, predict.bgmCompare for computing conditional probabilities.

Examples

Run this code
# \donttest{
# Fit a comparison model
x <- Boredom[Boredom$language == "fr", 2:6]
y <- Boredom[Boredom$language != "fr", 2:6]
fit <- bgmCompare(x, y, chains = 2)

# Simulate 100 observations from group 1
new_data_g1 <- simulate(fit, nsim = 100, group = 1)

# Simulate 100 observations from group 2
new_data_g2 <- simulate(fit, nsim = 100, group = 2)
# }

Run the code above in your browser using DataLab