| RandomEffectSamples | R Documentation |
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...)
This class is intended for advanced use cases in which users require detailed control of sampling algorithms and data structures. Minimal input validation and error checks are performed – users are responsible for providing the correct inputs. For tutorials on the "proper" usage of the stochtree's advanced workflow, we provide several vignettes at https://stochtree.ai/
Coordinates various C++ random effects classes and persists those needed for prediction / serialization
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
new()Create a new RandomEffectSamples object.
RandomEffectSamples$new()
A new RandomEffectSamples object.
load_in_session()Construct RandomEffectSamples object from other "in-session" R objects
RandomEffectSamples$load_in_session( num_components, num_groups, random_effects_tracker )
num_componentsNumber of "components" or bases defining the random effects regression
num_groupsNumber of random effects groups
random_effects_trackerObject of type RandomEffectsTracker
None
load_from_json()Construct RandomEffectSamples object from a json object
RandomEffectSamples$load_from_json( json_object, json_rfx_container_label, json_rfx_mapper_label, json_rfx_groupids_label )
json_objectObject of class CppJson
json_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
A new RandomEffectSamples object.
append_from_json()Append random effect draws to RandomEffectSamples object from a json object
RandomEffectSamples$append_from_json( json_object, json_rfx_container_label, json_rfx_mapper_label, json_rfx_groupids_label )
json_objectObject of class CppJson
json_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
None
load_from_json_string()Construct RandomEffectSamples object from a json object
RandomEffectSamples$load_from_json_string( json_string, json_rfx_container_label, json_rfx_mapper_label, json_rfx_groupids_label )
json_stringJSON string which parses into object of class CppJson
json_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
A new RandomEffectSamples object.
append_from_json_string()Append random effect draws to RandomEffectSamples object from a json object
RandomEffectSamples$append_from_json_string( json_string, json_rfx_container_label, json_rfx_mapper_label, json_rfx_groupids_label )
json_stringJSON string which parses into object of class CppJson
json_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
None
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).
RandomEffectSamples$predict(rfx_group_ids, rfx_basis = NULL)
rfx_group_idsIndices of random effects groups in a prediction set
rfx_basis(Optional) Basis used for random effects prediction
Matrix with as many rows as observations provided and as many columns as samples drawn of the model.
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).
RandomEffectSamples$extract_parameter_samples()
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.
delete_sample()Modify the RandomEffectsSamples object by removing the parameter samples index by sample_num.
RandomEffectSamples$delete_sample(sample_num)
sample_numIndex of the RFX sample to be removed
extract_label_mapping()Convert the mapping of group IDs to random effect components indices from C++ to R native format
RandomEffectSamples$extract_label_mapping()
List mapping group ID to random effect components.
num_samples()Query the number of samples in the RandomEffectsSamples object.
RandomEffectSamples$num_samples()
Integer number of samples
num_components()Query the number of components in the RandomEffectsSamples object.
RandomEffectSamples$num_components()
Integer number of components
num_groups()Query the number of groups in the RandomEffectsSamples object.
RandomEffectSamples$num_groups()
Integer number of groups
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.