Skip to content

Commit

Permalink
refactored nd_min_fun
Browse files Browse the repository at this point in the history
moved the formula gneration and conversion of fixed effects to sparse out of the
likelihood function. There's no need to redfine them between function calls and
thsi gives a slight speed up.
  • Loading branch information
bdilday committed Apr 8, 2018
1 parent bfb963f commit 02549f7
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions R/main.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,19 @@ nd_min_fun <- function(ev) {

# make sure the data is a data frame, not a tibble
ev$fr <- as.data.frame(ev$fr)

glf <- lme4::glFormula(ev$frm,
data=ev$fr, family='binomial')
fe <- fixed_effects <- (glf$X)
re <- random_effects <- Matrix::t(glf$reTrms$Zt)

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

function(mval) {
glf <- lme4::glFormula(ev$frm,
data=ev$fr, family='binomial')
fe <- fixed_effects <- (glf$X)
re <- random_effects <- Matrix::t(glf$reTrms$Zt)

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

s = 'mval '
for (v in mval) {
Expand All @@ -229,8 +231,6 @@ nd_min_fun <- function(ev) {

theta_mat <- matrix(mval, ncol=k_class)

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)
}
Expand Down

0 comments on commit 02549f7

Please sign in to comment.