Skip to contents

A MRPModel object is an R6 object created by the $create_model() method of a MRPWorkflow object. Each MRPModel object represents a multilevel regression model with methods for sampling, diagnostics, and post-stratification.

Format

An R6 generator object.

Methods


Method new()

Creates a new instance of the MRPModel class with specified effects, data, and metadata for Bayesian model fitting.

Usage

MRPModel$new(effects, mrp, metadata, linkdata, plotdata)

Arguments

effects

List containing model effects specification including intercept, fixed effects, varying effects, and interactions

mrp

List containing the MRP data structure with input sample data and new post-stratification data

metadata

List containing metadata about the analysis including family, time variables, and special cases

linkdata

List containing information about data linking including geography and ACS year

plotdata

List containing data prepared for visualization including dates and geojson objects

Returns

A new MRPModel object initialized with the provided effects, MRP data, metadata, link data, and plot data.


Method effects()

Retrieves the effects specification used in the model, including intercept, fixed effects, varying effects, and interactions.

Usage

MRPModel$effects()


Method formula()

Retrieves the model formula constructed from the effects specification.

Usage

MRPModel$formula()


Method mrp()

Retrieves the MRP data structure containing input sample data and post-stratification data.

Usage

MRPModel$mrp()


Method metadata()

Retrieves the metadata associated with the model, including information about family, time variables, and fitting parameters.

Usage

MRPModel$metadata()


Method plotdata()

Retrieves the data prepared for visualization, including dates and geojson objects.

Usage

MRPModel$plotdata()


Method linkdata()

Retrieves the data linking information including geography and ACS year.

Usage

MRPModel$linkdata()


Method stan_data()

Retrieves the Stan data structure used for MCMC sampling

Usage

MRPModel$stan_data()


Method stan_code()

Retrieves Stan code.

Usage

MRPModel$stan_code()


Method fit()

Fits the MRP model using Stan for Bayesian estimation with MCMC sampling.

Usage

MRPModel$fit(n_iter = 2000, n_chains = 4, seed = NULL, extra = NULL)

Arguments

n_iter

Number of MCMC iterations per chain

n_chains

Number of MCMC chains to run

seed

Random seed for reproducibility

extra

Additional parameters for model fitting


Method check_fit_exists()

Checks whether the model has been fitted and results are available.

Usage

MRPModel$check_fit_exists()


Method code()

Retrieves the Stan model code used for MCMC fitting.

Usage

MRPModel$code()


Method summary()

Retrieves a summary of the fitted model parameters including posterior means, credible intervals, and diagnostics.

Usage

MRPModel$summary()


Method diagnostics()

Retrieves MCMC diagnostics including convergence statistics and sampling efficiency measures.

Usage

MRPModel$diagnostics()


Method ppc()

Runs posterior predictive checks to assess model fit by generating replicated data from the posterior predictive distribution.

Usage

MRPModel$ppc()


Method loo()

Runs leave-one-out cross-validation to assess model predictive performance and enable model comparison.

Usage

MRPModel$loo()


Method poststratify()

Runs post-stratification using the fitted model to generate population-level estimates across different subgroups and geographies.

Usage

MRPModel$poststratify(interval = 0.95)

Arguments

interval

Confidence interval or standard deviation for the estimates (default is 0.95)


Method save()

Saves a fitted MRPModel object to a file for later use.

Usage

MRPModel$save(file)

Arguments

file

File path where the model should be saved

model

Fitted MRPModel object to save


Method clone()

The objects of this class are cloneable with this method.

Usage

MRPModel$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.