Skip to contents

Overview

The initialize_model() function includes checks to ensure that all data is set up in a way that the model can use. If the checks notice something incompatible with the model, an error will be displayed in the console. Here, we list each possible error for the MSTCAR model, including its reasoning and ways to check and fix your inputs.

Generic errors and warnings

All checks that are run on the data check for general information, such as extraneous list objects which cannot be used by the model. In these cases, RSTr will not use these parts of the dataset. It is recommended to remove these datasets from the model to prevent unnecessary clutter.

Errors and warnings with list data

  • One or more objects missing from list 'data': The data object requires a list with two objects: an array Y for mortality counts and an array n for population counts. These are needed to perform parameter updates inside of the MSTCAR model. Check names(data) to see a vector of names that exists inside of your array and fix names accordingly.

  • Data not same dimensions. Ensure dim(Y) == dim(n): This error occurs when the arrays fed into the data list are not of the same size. Use the dim() function to check that the dimensions of your two arrays do line up. You can use the aperm() function to rearrange arrays if they have the same set of dimensions on different margins.

  • Invalid Y/n values. Check that all Y's/n's are at least 0 and finite: While NA and NULL are accepted values in Y, both Y and n must be comprised of positive finite values. Check your data with summary() for a quick look at your minimum values.

Errors and warnings with list spatial_data

  • Adjacency different length than data. Ensure length(adjacency) == dim(Y)[1]: Adjacency information must be present for all regions. Look at the length of your adjacency information: it should line up with the number of rows in your Y and n arrays.

  • Some regions have no neighbors. Ensure all regions have at least one neighbor: If a region does not have a neighbor, the model will not run. If working with list adjacency information, you can first check which regions have no neighbors by running which(lapply(adjacency, \(x) all(x == 0))) and then fixing the regions accordingly. For assistance with fixing the adjacency information, read vignette("RSTr-adj").

Errors and warnings with list priors

Ag_scale

Ag_scale is a positive-definite covariance matrix with size num_group x num_group. This means that Ag_scale:

  • Must have positive values along its diagonal. Check for zero or negative values along the diagonal with summary(diag(Ag_scale)).

  • Must be symmetric. Check that Ag_scale is symmetric using isSymmetric(Ag_scale), and if not, you can force symmetry by defining Ag_scale as (Ag_scale + t(Ag_scale)) / 2.

  • Must not contain infinite values. Check using which(!is.finite(Ag_scale)).

  • Must have size num_group x num_group, where num_group is the number of groups in the model according to the third margin of Y and n. If nrow(Ag_scale) is different than dim(Y)[2], then force Ag_scale into the appropriate size using either the matrix() or array() functions.

G_df, Ag_df

G_df and Ag_df are positive integers that must be greater than or equal to num_group, where num_group is the number of groups in the model according to dim(Y)[2].

theta_sd

theta_sd is an array of variances used in the theta parameter update. Therefore, the dimension of theta_sd must match that of data and all values must be positive and finite.

rho_sd

rho_sd is a vector of variances used in the rho update. Therefore, the length of rho_sd must match num_group, where num_group is the number of groups in the model according to dim(Y)[2]. As with theta_sd, all values must be postive and finite.

Errors and warnings with list inits

theta and z

theta and z are arrays with sizes identical to dim(Y), with all finite values. Check for potential infinite values in either of these by using the which() and !is.finite() functions. Note that theta may be comprised of log or logit-transformed values, depending on your model choice.

beta

beta is an array of size num_island x num_group x num_time, where num_island is the number of contiguous regions known as “islands” in the model, num_group is the number of groups in the model according to dim(Y)[2], and num_time is the number of time periods in the model according to dim(Y)[3]. All values must be finite, which can be checked using the which() and !is.finite() functions. Note that beta must be comprised of log or logit-transformed values, depending on your model choice.

G

G is a covariance matrix array of size num_group x num_group x num_time, where num_group is the number of groups in the model according to dim(Y)[2] and num_time is the number of time periods in the model according to dim(Y)[3]. Every matrix slice of G must be positive definite, following the same rules as the Ag_scale prior.

tau2

tau2 is a postive vector of variances of length num_group, where num_group is the number of groups in the model according to dim(Y)[2]. Check for negative or infinite values by using which(tau2 <= 0) and which(is.finite(tau2)).

rho

rho is a vector of correlations with support [0,1] of length num_group, where num_group is the number of groups in the model according to dim(Y)[2]. Check for values outside of this range by using which(rho < 0) and which(rho > 1).

Ag

Ag is a covariance matrix of size num_group x num_group, where num_group is the number of groups in the model according to dim(Y)[2]. Ag is positive definite, and must follow the same rules as the Ag_scale prior.

.ignore_checks

If you have input data that you are certain is correct, yet are receiving error messages anyway, set the .ignore_checks argument to TRUE when setting up your model to skip data checks. This is not recommended as it is easy to break RSTr when data isn’t properly checked, and should only be used as a last resort when using RSTr.