Class that wraps the "persistent" aspects of a C++ random effects model.
Source:R/random_effects.R
RandomEffectSamples.RdCoordinates various C++ random effects classes and persists those needed for prediction / serialization
Details
Class that wraps the "persistent" aspects of a C++ random effects model, including draws of the parameters and a map from the original label indices to the 0-indexed label numbers used to place group samples in memory (i.e. the first label is stored in column 0 of the sample matrix, the second label is store in column 1 of the sample matrix, etc...)
Public fields
rfx_container_ptrExternal pointer to a C++ StochTree::RandomEffectsContainer class
label_mapper_ptrExternal pointer to a C++ StochTree::LabelMapper class
training_group_idsUnique vector of group IDs that were in the training dataset
Methods
Method load_in_session()
Construct RandomEffectSamples object from other "in-session" R objects
Method load_from_json()
Construct RandomEffectSamples object from a json object
Usage
RandomEffectSamples$load_from_json(
json_object,
json_rfx_container_label,
json_rfx_mapper_label,
json_rfx_groupids_label
)Arguments
json_objectObject of class
CppJsonjson_rfx_container_labelLabel referring to a particular rfx sample container (i.e. "random_effect_container_0") in the overall json hierarchy
json_rfx_mapper_labelLabel referring to a particular rfx label mapper (i.e. "random_effect_label_mapper_0") in the overall json hierarchy
json_rfx_groupids_labelLabel referring to a particular set of rfx group IDs (i.e. "random_effect_groupids_0") in the overall json hierarchy
Method append_from_json()
Append random effect draws to RandomEffectSamples object from a json object
Usage
RandomEffectSamples$append_from_json(
json_object,
json_rfx_container_label,
json_rfx_mapper_label,
json_rfx_groupids_label
)Arguments
json_objectObject of class
CppJsonjson_rfx_container_labelLabel referring to a particular rfx sample container (i.e. "random_effect_container_0") in the overall json hierarchy
json_rfx_mapper_labelLabel referring to a particular rfx label mapper (i.e. "random_effect_label_mapper_0") in the overall json hierarchy
json_rfx_groupids_labelLabel referring to a particular set of rfx group IDs (i.e. "random_effect_groupids_0") in the overall json hierarchy
Method load_from_json_string()
Construct RandomEffectSamples object from a json object
Usage
RandomEffectSamples$load_from_json_string(
json_string,
json_rfx_container_label,
json_rfx_mapper_label,
json_rfx_groupids_label
)Arguments
json_stringJSON string which parses into object of class
CppJsonjson_rfx_container_labelLabel referring to a particular rfx sample container (i.e. "random_effect_container_0") in the overall json hierarchy
json_rfx_mapper_labelLabel referring to a particular rfx label mapper (i.e. "random_effect_label_mapper_0") in the overall json hierarchy
json_rfx_groupids_labelLabel referring to a particular set of rfx group IDs (i.e. "random_effect_groupids_0") in the overall json hierarchy
Method append_from_json_string()
Append random effect draws to RandomEffectSamples object from a json object
Usage
RandomEffectSamples$append_from_json_string(
json_string,
json_rfx_container_label,
json_rfx_mapper_label,
json_rfx_groupids_label
)Arguments
json_stringJSON string which parses into object of class
CppJsonjson_rfx_container_labelLabel referring to a particular rfx sample container (i.e. "random_effect_container_0") in the overall json hierarchy
json_rfx_mapper_labelLabel referring to a particular rfx label mapper (i.e. "random_effect_label_mapper_0") in the overall json hierarchy
json_rfx_groupids_labelLabel referring to a particular set of rfx group IDs (i.e. "random_effect_groupids_0") in the overall json hierarchy
Method predict()
Predict random effects for each observation implied by rfx_group_ids and rfx_basis.
If a random effects model is "intercept-only" the rfx_basis will be a vector of ones of size length(rfx_group_ids).
Method extract_parameter_samples()
Extract the random effects parameters sampled. With the "redundant parameterization" of Gelman et al (2008), this includes four parameters: alpha (the "working parameter" shared across every group), xi (the "group parameter" sampled separately for each group), beta (the product of alpha and xi, which corresponds to the overall group-level random effects), and sigma (group-independent prior variance for each component of xi).
Returns
List of arrays. The alpha array has dimension (num_components, num_samples) and is simply a vector if num_components = 1.
The xi and beta arrays have dimension (num_components, num_groups, num_samples) and are simply matrices if num_components = 1.
The sigma array has dimension (num_components, num_samples) and is simply a vector if num_components = 1.
Method delete_sample()
Modify the RandomEffectsSamples object by removing the parameter samples index by sample_num.