Skip to content

Commit

Permalink
Add basic class for nesmr/esmr
Browse files Browse the repository at this point in the history
  • Loading branch information
stefaneng committed Dec 16, 2024
1 parent 6d9ee8e commit ecdd3b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 8 additions & 2 deletions R/esmr.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,19 @@ esmr <- function(beta_hat_X, se_X,

dat <- set_data(beta_hat_Y, se_Y, beta_hat_X, se_X, R, ld_scores, RE, tau_init)

class(dat) <- c(c("esmr"), class(dat))
dat$is_nesmr <- ! is.null(direct_effect_template)
if (dat$is_nesmr) {
class(dat) <- c(c("nesmr"), class(dat))
}

if(is.null(G)){
if(dat$p == 2){
G <- diag(dat$p)
}else if(!missing(direct_effect_template) & !is.null(direct_effect_template)){
} else if (dat$is_nesmr) {
warning("Cannot estimate G for network problem yet.\n")
G <- diag(dat$p)
}else{
} else{
G <- estimate_G(beta_hat_X = dat$Y[,-1,drop =F],
se_X = dat$S[,-1, drop = F],
R = R[-1, -1, drop = FALSE],
Expand Down
6 changes: 3 additions & 3 deletions R/grad_log_py.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## likelihood function, very slow
log_py <- function(fit, g_hat, fbar, max_prob = 1, nmax = Inf){
if(missing(g_hat)){
log_py <- function(fit, g_hat = NULL, fbar = NULL, max_prob = 1, nmax = Inf){
if(is.null(g_hat)){
g_hat <- fit$l$g_hat
}
if(missing(fbar)){
if(is.null(fbar)){
fbar <- fit$f$fbar
}
fgbar <- fbar %*% fit$G
Expand Down
4 changes: 2 additions & 2 deletions R/likelihood_funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ calc_ell2 <- function(Y, abar, a2bar, fgbar, omega, omega_logdet, s_equal){


#'@export
logLik.esmr <- function(x) {
log_py(x)
logLik.esmr <- function(x, ...) {
log_py(x, ...)
}


Expand Down

0 comments on commit ecdd3b3

Please sign in to comment.