Package: cramR 0.1.0

cramR: Cram Method for Efficient Simultaneous Learning and Evaluation

Performs the Cram method, a general and efficient approach to simultaneous learning and evaluation using a generic machine learning algorithm. In a single pass of batched data, the proposed method repeatedly trains a machine learning algorithm and tests its empirical performance. Because it utilizes the entire sample for both learning and evaluation, cramming is significantly more data-efficient than sample-splitting. Unlike cross-validation, Cram evaluates the final learned model directly, providing sharper inference aligned with real-world deployment. The method naturally applies to both policy learning and contextual bandits, where decisions are based on individual features to maximize outcomes. The package includes cram_policy() for learning and evaluating individualized binary treatment rules, cram_ml() to train and assess the population-level performance of machine learning models, and cram_bandit() for on-policy evaluation of contextual bandit algorithms. For all three functions, the package provides estimates of the average outcome that would result if the model were deployed, along with standard errors and confidence intervals for these estimates. Details of the method are described in Jia, Imai, and Li (2024) <https://www.hbs.edu/ris/Publication%20Files/2403.07031v1_a83462e0-145b-4675-99d5-9754aa65d786.pdf> and Jia et al. (2025) <doi:10.48550/arXiv.2403.07031>.

Authors:Yanis Vandecasteele [cre, aut], Michael Lingzhi Li [ctb], Kosuke Imai [ctb], Zeyang Jia [ctb], Longlin Wang [ctb]

cramR_0.1.0.tar.gz
cramR_0.1.0.zip(r-4.7-any)cramR_0.1.0.zip(r-4.6-any)cramR_0.1.0.zip(r-4.5-any)
cramR_0.1.0.tgz(r-4.6-any)cramR_0.1.0.tgz(r-4.5-any)
cramR_0.1.0.tar.gz(r-4.7-any)cramR_0.1.0.tar.gz(r-4.6-any)
cramR_0.1.0.tgz(r-4.6-emscripten)
manual.pdf |manual.html✨
DESCRIPTION |NEWS
card.svg |card.png
cramR/json (API)

# Install 'cramR' in R:
install.packages('cramR', repos = c('https://yanisvdc.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/yanisvdc/cramr/issues

Pkgdown/docs site:https://yanisvdc.github.io

On CRAN:

Conda:

5.66 score 3 stars 38 scripts 367 downloads 30 exports 130 dependencies

Last updated from:b6d7444fd9. Checks:9 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-develOK246
source / vignettesOK384
linux-releaseOK213
macos-releaseOK271
macos-oldrelOK298
windows-develOK210
windows-releaseOK247
windows-oldrelOK159
wasm-releaseOK148

Exports:BatchContextualEpsilonGreedyPolicyBatchContextualLinTSPolicyBatchLinUCBDisjointPolicyEpsilonContextualLinearBanditcram_banditcram_bandit_estcram_bandit_simcram_bandit_varcram_estimatorcram_expected_losscram_learningcram_mlcram_policycram_policy_value_estimatorcram_simulationcram_var_expected_losscram_variance_estimatorcram_variance_estimator_policy_valuefit_modelfit_model_mlget_betasLinUCBDisjointPolicyEpsilonml_learningmodel_predictmodel_predict_mlset_modeltest_baseline_policytest_batchvalidate_paramsvalidate_params_fnn

Dependencies:backportsbase64encbslibcachemcaretclasscliclockcodetoolsconfigcpp11crosstalkdata.tablediagramDiceKrigingdigestdoParalleldplyrDTe1071evaluatefarverfastmapfontawesomeforeachfsfuturefuture.applygenericsggplot2glmnetglobalsgluegowergrfgtablehardhatherehighrhtmltoolshtmlwidgetsipredisobanditeratorsitertoolsjquerylibjsonlitekerasKernSmoothknitrlabelinglaterlatticelavalazyevallifecyclelistenvlmtestlubridatemagrittrMASSMatrixmemoisemimeModelMetricsnlmennetnumDerivotelparallellypillarpkgconfigplyrpngpROCprocessxprodlimprogressrpromisesproxypspurrrR.devicesR.methodsS3R.ooR.utilsR6rappdirsRColorBrewerRcppRcppEigenRcppTOMLrecipesreshape2reticulaterjsonrlangrmarkdownrpartrprojrootrstudioapiS7sandwichsassscalesshapesparsevctrsSQUAREMstringistringrsurvivaltensorflowtfautographtfrunstibbletidyrtidyselecttimechangetimeDatetinytextzdbutf8vctrsviridisLitewhiskerwithrxfunyamlzeallotzoo

Cram Bandit Simulation
What is cram_bandit_sim()? | πŸ“‹ Inputs | Example: Cram Bandit Simulation | What Does It Return? | Example Output Preview | Notes | Recommended Use Cases | References

Last update: 2025-05-11
Started: 2025-03-27

Introduction & Cram Policy part 1
Introduction: What is the Cram Method? | The Cram Workflow | The cram_policy() Function | πŸ”‘ Key Features of cram_policy() | Example: Running Cram Policy on simulated data | Interpreting Results | Visual Summary and Notes | πŸ“ Comparing Evaluation Strategies: Sample-Splitting, Cross-Validation, and Cram | πŸ” Sample-Splitting | πŸ”„ Cross-Validation | πŸ“ˆ Cram | 🧠 Key Distinction Summary: What Is Being Evaluated? | References

Last update: 2025-05-05
Started: 2025-04-21

Cram Bandit Helpers
🌟 What is this article about? | πŸ› οΈPolicy parameters explained | ✨ Epsilon-Greedy Policy | πŸ€– Theoretical computation | πŸ“Š Code helper | πŸ”’ LinUCB Disjoint Policy with ( \varepsilon )-Greedy | πŸ€“ Thompson Sampling (LinTS) | πŸ‘¨β€πŸ’» Practical Workflow | πŸ§ͺ Estimand Calculation in cram_bandit_sim() | πŸ“‚ Useful Links | 🌟 Acknowledgments

Last update: 2025-05-05
Started: 2025-03-27

Cram Bandit
What is cram_bandit()? | Introduction: Bandits, Policies, and Cram | Understanding the inputs | Example: Use cram_bandit() on simulated data with batch size of 1 | References

Last update: 2025-04-29
Started: 2025-03-27

Cram ML
Output of Cram ML | Built-in Model | loss_name argument | Regression Losses | Classification Losses | Custom Loss Functions | caret_params argument | Case of categorical target variable | Case 1: Predicting Class Labels | Case 2: Predicting Class Probabilities | Custom Model | 1. custom_fit(data, ...) | 2. custom_predict(model, data) | 3. custom_loss(predictions, data) | 4. Use cram_ml() with Custom Functions

Last update: 2025-04-29
Started: 2025-03-27

Cram Policy part 2
Cram Policy | Built-in Model | How to set model_params? | Case of categorical target Y | Custom Model | 1. custom_fit(X, Y, D, ...) | 2. custom_predict(model, X_new, D_new) | 3. Use cram_policy() with custom_fit() and custom_predict() | References

Last update: 2025-04-29
Started: 2025-04-21

Cram Policy Simulation
🎯 What is cram_simulation()? | πŸ“¦ Inputs Overview | πŸ“˜ Example: Cram Policy Simulation | πŸ“Š Output Summary

Last update: 2025-04-29
Started: 2025-03-27

Quick Start with CRAM
Introduction | Cram User file | 1. cram_policy() β€” Binary Policy Learning & Evaluation | Generate Simulated Data | Run cram_policy() with causal forest | Case of categorical target Y | Custom Models with cram_policy() | 2. cram_ml() β€” ML Learning & Evaluation | Regression with cram_ml() | Classification with cram_ml() | Case 1: Predicting Class labels | Case 2: Predicting Class Probabilities | 3. cram_bandit() β€” Contextual Bandits for On-policy Statistical Evaluation | Summary

Last update: 2025-04-29
Started: 2025-04-02

Readme and manuals

Help Manual

Help pageTopics
Batch Contextual Epsilon-Greedy PolicyBatchContextualEpsilonGreedyPolicy
Batch Contextual Thompson Sampling PolicyBatchContextualLinTSPolicy
Batch Disjoint LinUCB Policy with Epsilon-GreedyBatchLinUCBDisjointPolicyEpsilon
Contextual Linear Bandit EnvironmentContextualLinearBandit
Cram Bandit: On-policy Statistical Evaluation in Contextual Banditscram_bandit
Cram Bandit Policy Value Estimatecram_bandit_est
Cram Bandit Simulationcram_bandit_sim
Cram Bandit Variance of the Policy Value Estimatecram_bandit_var
Cram Policy Estimator for Policy Value Difference (Delta)cram_estimator
Cram ML Expected Loss Estimatecram_expected_loss
Cram Policy Learningcram_learning
Cram ML: Simultaneous Machine Learning and Evaluationcram_ml
Cram Policy: Efficient Simultaneous Policy Learning and Evaluationcram_policy
Cram Policy: Estimator for Policy Value (Psi)cram_policy_value_estimator
Cram Policy Simulationcram_simulation
Cram ML: Variance Estimate of the crammed expected loss estimatecram_var_expected_loss
Cram Policy: Variance Estimate of the crammed Policy Value Difference (Delta)cram_variance_estimator
Cram Policy: Variance Estimate of the crammed Policy Value estimate (Psi)cram_variance_estimator_policy_value
Cram Policy: Fit Modelfit_model
Cram ML: Fit Model MLfit_model_ml
Generate Reward Parameters for Simulated Linear Banditsget_betas
LinUCB Disjoint Policy with Epsilon-Greedy ExplorationLinUCBDisjointPolicyEpsilon
Cram ML: Generalized ML Learningml_learning
Cram Policy: Predict with the Specified Modelmodel_predict
Cram ML: Predict with the Specified Modelmodel_predict_ml
Cram Policy: Set Modelset_model
Validate or Set the Baseline Policytest_baseline_policy
Validate or Generate Batch Assignmentstest_batch
Cram Policy: Validate User-Provided Parameters for a Modelvalidate_params
Cram Policy: Validate Parameters for Feedforward Neural Networks (FNNs)validate_params_fnn