Skip to content

Commit

Permalink
formula interface
Browse files Browse the repository at this point in the history
  • Loading branch information
bdilday committed Feb 1, 2018
1 parent 505adef commit 80ddedf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(mnre_dim_and_class_to_index)
export(mnre_expand_matrix)
export(mnre_fit)
export(mnre_fit_sparse)
export(mnre_make_covar)
export(mnre_simulate_ev_data)
Expand Down
17 changes: 11 additions & 6 deletions R/main.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ nd_min_fun <- function(ev) {
data=ev$fr, family='binomial')
fe <- fixed_effects <- (glf$X)
re <- random_effects <- Matrix::t(glf$reTrms$Zt)
y <- matrix(ev$y, ncol=1)

y <- matrix(ev$fr[,all.vars(ev$frm)[[1]]], ncol=1)
k_class <- max(y)
k <- max(y)
Lind = ev$Lind
Lind = glf$reTrms$Lind

s = 'mval '
for (v in mval) {
Expand All @@ -227,13 +228,17 @@ nd_min_fun <- function(ev) {

fe2 <- Matrix::Matrix(fe, sparse = TRUE)

if (! "beta_re" %in% names(ev)) {
ev$beta_re <- matrix(rnorm(ncol(re) * k_class, 0, 0.2), ncol=k_class)
}

if (! "beta_fe" %in% names(ev)) {
ev$beta_fe <- matrix(rnorm(ncol(fe) * k_class, 0, 0.2), ncol=k_class)
}

beta_re <- ev$beta_re
beta_fe <- ev$beta_fe

# beta_re <- matrix(rep(0, ncol(re) * k_class), ncol=k_class)
# beta_fe <- matrix(rep(0, ncol(fe) * k_class), ncol=k_class)
#

if (ev$verbose > 0) {
message("starting beta ", beta_fe[[1]], " ", beta_re[[1]])
}
Expand Down
16 changes: 16 additions & 0 deletions R/mnre_fit.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

#' @export
mnre_fit <- function(frm, data, verbose=0, off_diagonal=0.0) {
ev <- list()
ev$frm <- frm
ev$fr <- data
ev$verbose <- verbose

nlev <- length(all.vars(ev$frm))
mval <- rep(1, (nlev-1) * max(ev$fr$y))

nf <- nd_min_fun(ev)

ans = optim(mval, nf, method = "L-BFGS", lower=1e-8)

}

0 comments on commit 80ddedf

Please sign in to comment.