20 enum Data {Y, A, X1, X2, X3, W};
24 using cx_dbl = target::cx_dbl;
25 using cx_func = target::cx_func;
28 RiskReg(
const arma::vec &y,
const arma::vec &a,
29 const arma::mat &x1,
const arma::mat &x2,
const arma::mat &x3,
30 const arma::vec &weights, std::string model) {
32 setData(y, a, x1, x2, x3, weights);
36 void setData(
const arma::vec &y,
const arma::vec &a,
37 const arma::mat &x1,
const arma::mat &x2,
const arma::mat &x3,
38 const arma::vec &weights) {
39 theta = arma::zeros(x1.n_cols + x2.n_cols + x3.n_cols);
40 if (this->type.compare(
"rr") == 0) {
51 void weights(
const arma::vec &weights) {
52 model->weights(weights);
55 void update(arma::vec &par) {
56 for (
unsigned i=0; i < par.n_elem; i++)
57 this->theta(i) = par(i);
58 model->update_par(par);
59 model->calculate(
true,
true,
true);
62 return model->loglik(
false)[0];
64 arma::mat dlogl(
bool indiv =
false) {
65 return model->score(indiv);
71 arma::cx_mat score(arma::cx_vec theta) {
72 model_c->update_par(theta);
73 model_c->calculate(
true,
true,
false);
74 return model_c->score(
false);
77 arma::mat esteq(arma::vec &alpha, arma::vec &pr) {
78 arma::mat res = model->est(alpha, pr);
83 arma::cx_vec Yc = arma::conv_to<arma::cx_vec>::from(model->Y());
84 arma::cx_vec Ac = arma::conv_to<arma::cx_vec>::from(model->A());
85 arma::cx_mat X1c = arma::conv_to<arma::cx_mat>::from(model->X1());
86 arma::cx_mat X2c = arma::conv_to<arma::cx_mat>::from(model->X2());
87 arma::cx_mat X3c = arma::conv_to<arma::cx_mat>::from(model->X3());
88 arma::cx_vec thetac = arma::conv_to<arma::cx_vec>::from(theta);
89 arma::cx_vec Wc = arma::conv_to<arma::cx_vec>::from(model->weights());
90 if (this->type.compare(
"rr") == 0) {
95 arma::mat res = target::deriv(std::bind(&RiskReg::score,
97 std::placeholders::_1), theta);
101 arma::mat operator()(Data index)
const {
116 return model->weights();
120 std::unique_ptr< target::TargetBinary<double> > model;
121 std::unique_ptr< target::TargetBinary<cx_dbl> > model_c;
Classes for targeted inference models.
Utility functions for Generalized Linear Models.
Various utility functions and constants.