Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshyam-k committed May 23, 2024
1 parent cdce259 commit 07c33eb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
24 changes: 12 additions & 12 deletions R/saeczi.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ saeczi <- function(samp_dat,
stop("Invalid estimand, must be either 'means' or 'totals'")
}

Y <- deparse(lin_formula[[2]])
Y <- toString(lin_formula[[2]])

lin_X <- unlist(str_extract_all_base(deparse(lin_formula[[3]]), "\\w+"))
log_X <- unlist(str_extract_all_base(deparse(log_formula[[3]]), "\\w+"))
Expand Down Expand Up @@ -132,17 +132,17 @@ saeczi <- function(samp_dat,
} else {

res <-
purrr::map(.x = boot_samp_ls,
.f = \(.x) {
boot_rep(boot_samp = .x,
domain_level,
boot_lin_formula,
boot_log_formula)
},
.progress = list(
type = "iterator",
clear = TRUE
))
map(.x = boot_samp_ls,
.f = \(.x) {
boot_rep(boot_samp = .x,
domain_level,
boot_lin_formula,
boot_log_formula)
},
.progress = list(
type = "iterator",
clear = TRUE
))

beta_lm_mat <- res |>
map_dfr(.f = ~ .x$beta_lm) |>
Expand Down
8 changes: 3 additions & 5 deletions src/helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// [[Rcpp::depends(RcppEigen)]]
#include <vector>
#include <Rcpp.h>
#include <RcppEigen.h>
#include "helpers.h"

double sigmoid(double x) {
return 1.0 / (1.0 + std::exp(-x));
Expand All @@ -19,8 +17,8 @@ void preds_calc(Eigen::MatrixXd& result,
std::string estimand) {

// these are N_j x B
Eigen::MatrixXd pred_lm_j = (dmat_lm * beta_lm.transpose());
Eigen::MatrixXd pred_glm_j = (dmat_glm * beta_glm.transpose());
Eigen::MatrixXd pred_lm_j = dmat_lm * beta_lm.transpose();
Eigen::MatrixXd pred_glm_j = dmat_glm * beta_glm.transpose();

pred_lm_j.rowwise() += u_lm.col(j).transpose();
pred_glm_j.rowwise() += u_glm.col(j).transpose();
Expand Down
28 changes: 28 additions & 0 deletions src/helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef helpers_H
#define helpers_H

#include <Rcpp.h>
#include <RcppEigen.h>

double sigmoid(double x);

void preds_calc(Eigen::MatrixXd& result,
const Eigen::MatrixXd& beta_lm,
const Eigen::MatrixXd& beta_glm,
const Eigen::MatrixXd& dmat_lm,
const Eigen::MatrixXd& dmat_glm,
const Eigen::MatrixXd& u_lm,
const Eigen::MatrixXd& u_glm,
int j,
int B,
std::string estimand);

SEXP generate_preds(const Eigen::MatrixXd& beta_lm,
const Eigen::MatrixXd& beta_glm,
const Eigen::MatrixXd& u_lm,
const Eigen::MatrixXd& u_glm,
const Rcpp::List& design_mats,
int J,
std::string estimand);

#endif // helpers_H

0 comments on commit 07c33eb

Please sign in to comment.